Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scsi: snic: Convert sprintf() family to sysfs_emit() family

Per filesystems/sysfs.rst, show() should only use sysfs_emit() or
sysfs_emit_at() when formatting the value to be returned to user space.

coccinelle complains that there are still a couple of functions that use
snprintf(). Convert them to sysfs_emit().

sprintf() and scnprintf() will be converted as well if they have.

Generally, this patch is generated by
make coccicheck M=<path/to/file> MODE=patch \
COCCI=scripts/coccinelle/api/device_attr_show.cocci

No functional change intended

CC: Karan Tilak Kumar <kartilak@cisco.com>
CC: Sesidhar Baddela <sebaddel@cisco.com>
CC: James E.J. Bottomley <jejb@linux.ibm.com>
CC: Martin K. Petersen <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
Link: https://lore.kernel.org/r/20240319063132.1588443-12-lizhijian@fujitsu.com
Reviewed-by: Karan Tilak Kumar <kartilak@cisco.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Li Zhijian and committed by
Martin K. Petersen
eab302e8 9bd8e413

+5 -6
+5 -6
drivers/scsi/snic/snic_attrs.c
··· 13 13 { 14 14 struct snic *snic = shost_priv(class_to_shost(dev)); 15 15 16 - return snprintf(buf, PAGE_SIZE, "%s\n", snic->name); 16 + return sysfs_emit(buf, "%s\n", snic->name); 17 17 } 18 18 19 19 static ssize_t ··· 23 23 { 24 24 struct snic *snic = shost_priv(class_to_shost(dev)); 25 25 26 - return snprintf(buf, PAGE_SIZE, "%s\n", 27 - snic_state_str[snic_get_state(snic)]); 26 + return sysfs_emit(buf, "%s\n", snic_state_str[snic_get_state(snic)]); 28 27 } 29 28 30 29 static ssize_t ··· 31 32 struct device_attribute *attr, 32 33 char *buf) 33 34 { 34 - return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION); 35 + return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION); 35 36 } 36 37 37 38 static ssize_t ··· 44 45 if (snic->config.xpt_type == SNIC_DAS) 45 46 snic->link_status = svnic_dev_link_status(snic->vdev); 46 47 47 - return snprintf(buf, PAGE_SIZE, "%s\n", 48 - (snic->link_status) ? "Link Up" : "Link Down"); 48 + return sysfs_emit(buf, "%s\n", 49 + (snic->link_status) ? "Link Up" : "Link Down"); 49 50 } 50 51 51 52 static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);