scsi: snic: Use sysfs_emit in show function callback
Subsystems (2)
PATCH 1/1 scsi: snic: Use sysfs_emit in show function callback
According to Documentation/filesystems/sysfs.rst, the show() callback function of kobject attributes should strictly use sysfs_emit() instead of sprintf() family functions.
Issue identified using the device_attr_show.cocci Coccinelle script.
--- drivers/scsi/snic/snic_attrs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/scsi/snic/snic_attrs.c +4 -6
@@ -13,7 +13,7 @@ snic_show_sym_name(struct device *dev, {struct snic *snic =shost_priv (class_to_shost (dev)); -return snprintf (buf,PAGE_SIZE ,"%s\n" , snic->name); +return sysfs_emit (buf,"%s\n" , snic->name); } static ssize_t
@@ -23,8 +23,7 @@ snic_show_state(struct device *dev, {struct snic *snic =shost_priv (class_to_shost (dev)); -return snprintf (buf,PAGE_SIZE ,"%s\n" , - snic_state_str[snic_get_state (snic)]); +return sysfs_emit (buf,"%s\n" , snic_state_str[snic_get_state (snic)]); } static ssize_t
@@ -32,7 +31,7 @@ snic_show_drv_version(struct device *dev,struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION); + return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION); } static ssize_t
@@ -45,8 +44,7 @@ snic_show_link_state(struct device *dev,if (snic->config.xpt_type ==SNIC_DAS ) snic->link_status =svnic_dev_link_status (snic->vdev); -return snprintf (buf,PAGE_SIZE ,"%s\n" , - (snic->link_status) ?"Link Up" :"Link Down" ); +return sysfs_emit (buf,"%s\n" , (snic->link_status) ?"Link Up" :"Link Down" ); } static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);
Signature · 1 line
2.34.1
code changes look good.
commit message can be more simpler like "show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space."
and in place of kobject attributes , device attribute is more relevant here.
Thanks,
Alok
Quoted 52 lines · Deepak R Varma
According to
Documentation/filesystems/sysfs.rst, theshow()callback function of kobject attributes should strictly usesysfs_emit()instead ofsprintf()family functions.
Issue identified using thedevice_attr_show.cocciCoccinelle script.Signed-off-by Deepak R Varma <[email protected]>--- drivers/scsi/snic/snic_attrs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/scsi/snic/snic_attrs.c +4
-6@@ -13,7 +13,7 @@ snic_show_sym_name(struct device *dev, {struct snic *snic =shost_priv (class_to_shost (dev)); -return snprintf (buf,PAGE_SIZE ,"%s\n" , snic->name); +return sysfs_emit (buf,"%s\n" , snic->name); } static ssize_t@@ -23,8 +23,7 @@ snic_show_state(struct device *dev, {struct snic *snic =shost_priv (class_to_shost (dev)); -return snprintf (buf,PAGE_SIZE ,"%s\n" , - snic_state_str[snic_get_state (snic)]); +return sysfs_emit (buf,"%s\n" , snic_state_str[snic_get_state (snic)]); } static ssize_t@@ -32,7 +31,7 @@ snic_show_drv_version(struct device *dev,struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION); + return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION); } static ssize_t@@ -45,8 +44,7 @@ snic_show_link_state(struct device *dev,if (snic->config.xpt_type ==SNIC_DAS ) snic->link_status =svnic_dev_link_status (snic->vdev); -return snprintf (buf,PAGE_SIZE ,"%s\n" , - (snic->link_status) ?"Link Up" :"Link Down" ); +return sysfs_emit (buf,"%s\n" , (snic->link_status) ?"Link Up" :"Link Down" ); } static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);
Quoted 7 lines · ALOK TIWARI
code changes look good.
commit message can be more simpler like "
show()should only usesysfs_emit()orsysfs_emit_at()when formatting the value to be returned to user space."and in place of kobject attributes , device attribute is more relevant here.
Hi Alok,
Thank you for the feedback. Your commends make perfect sense. Shall I resend a v2 with the simplified language?
Regards,
Deepak.
Quoted 50 lines
Thanks,
AlokQuoted 45 lines · Deepak R Varma
According to
Documentation/filesystems/sysfs.rst, theshow()callback function of kobject attributes should strictly usesysfs_emit()instead ofsprintf()family functions.
Issue identified using thedevice_attr_show.cocciCoccinelle script.Signed-off-by Deepak R Varma <[email protected]>--- drivers/scsi/snic/snic_attrs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/scsi/snic/snic_attrs.c +4
-6@@ -13,7 +13,7 @@ snic_show_sym_name(struct device *dev, {struct snic *snic =shost_priv (class_to_shost (dev)); -return snprintf (buf,PAGE_SIZE ,"%s\n" , snic->name); +return sysfs_emit (buf,"%s\n" , snic->name); } static ssize_t@@ -23,8 +23,7 @@ snic_show_state(struct device *dev, {struct snic *snic =shost_priv (class_to_shost (dev)); -return snprintf (buf,PAGE_SIZE ,"%s\n" , - snic_state_str[snic_get_state (snic)]); +return sysfs_emit (buf,"%s\n" , snic_state_str[snic_get_state (snic)]); } static ssize_t@@ -32,7 +31,7 @@ snic_show_drv_version(struct device *dev,struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION); + return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION); } static ssize_t@@ -45,8 +44,7 @@ snic_show_link_state(struct device *dev,if (snic->config.xpt_type ==SNIC_DAS ) snic->link_status =svnic_dev_link_status (snic->vdev); -return snprintf (buf,PAGE_SIZE ,"%s\n" , - (snic->link_status) ?"Link Up" :"Link Down" ); +return sysfs_emit (buf,"%s\n" , (snic->link_status) ?"Link Up" :"Link Down" ); } static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);
RE: [External] : Re: [PATCH] scsi: snic: Use sysfs_emit in show function callback
Yes, please.
Thanks,
Alok
-----Original Message-----
From: Deepak R Varma <[email protected]>
Sent: Tuesday, January 31, 2023 1:06 AM
To: ALOK TIWARI <[email protected]>
Cc: Karan Tilak Kumar <[email protected]>; Sesidhar Baddela <[email protected]>; James E.J. Bottomley <[email protected]>; Martin Petersen <[email protected]>; [email protected]; [email protected]; Saurabh Singh Sengar <[email protected]>; Praveen Kumar <[email protected]>; Deepak R Varma <[email protected]>
Subject: [External] : Re: [PATCH] scsi: snic: Use sysfs_emit in show function callback
Quoted 7 lines · ALOK TIWARI
code changes look good.
commit message can be more simpler like "
show()should only usesysfs_emit()orsysfs_emit_at()when formatting the value to be returned to user space."and in place of kobject attributes , device attribute is more relevant here.
Hi Alok,
Thank you for the feedback. Your commends make perfect sense. Shall I resend a v2 with the simplified language?
Regards,
Deepak.
Quoted 54 lines
Thanks,
AlokQuoted 49 lines · Deepak R Varma
According to
Documentation/filesystems/sysfs.rst, theshow()callback function of kobject attributes should strictly usesysfs_emit()instead ofsprintf()family functions.
Issue identified using thedevice_attr_show.cocciCoccinelle script.Signed-off-by Deepak R Varma <[email protected]>--- drivers/scsi/snic/snic_attrs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)(quoted diff) +0
-0
b/drivers/scsi/snic/snic_attrs.cindex3ddbdbc3ded1..56c46ea06e60100644drivers/scsi/snic/snic_attrs.c +6
-6@@ -13,7 +13,7 @@ snic_show_sym_name(struct device *dev, {struct snic *snic =shost_priv (class_to_shost (dev)); -return snprintf (buf,PAGE_SIZE ,"%s\n" , snic->name); +return sysfs_emit (buf,"%s\n" , snic->name); } static ssize_t@@ -23,8 +23,7 @@ snic_show_state(struct device *dev, {struct snic *snic =shost_priv (class_to_shost (dev)); -return snprintf (buf,PAGE_SIZE ,"%s\n" , - snic_state_str[snic_get_state (snic)]); +return sysfs_emit (buf,"%s\n" , +snic_state_str[snic_get_state (snic)]); } static ssize_t@@ -32,7 +31,7 @@ snic_show_drv_version(struct device *dev,struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION); + return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION); } static ssize_t@@ -45,8 +44,7 @@ snic_show_link_state(struct device *dev,if (snic->config.xpt_type ==SNIC_DAS ) snic->link_status =svnic_dev_link_status (snic->vdev); -return snprintf (buf,PAGE_SIZE ,"%s\n" , - (snic->link_status) ?"Link Up" :"Link Down" ); +return sysfs_emit (buf,"%s\n" , (snic->link_status) ?"Link Up" : +"Link Down" ); } static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);