Skip to contentSkip to conversation

staging: fieldbus: Use sysfs_emit for show(device *...) functions

PATCH In review Deepak R Varma 2 participants 3 messages Oct 18, 2020 – Nov 2, 2020 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: fieldbus: Use sysfs_emit for show(device *...) functions

Convert snprintf calls in device show functions to sysfs_emit for PAGE_SIZE buffer safety.
Warning generated by: scripts/coccinelle/api/device_attr_show.cocci

---
 drivers/staging/fieldbus/dev_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/fieldbus/dev_core.c +1 -1
index 1ba0234cc60d..698d7b479270 100644
@@ -70,7 +70,7 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr,
 	 * card_name was provided by child driver, could potentially be long.
 	 * protect against buffer overrun.
 	 */
-	return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name);
+	return sysfs_emit(buf, "%s\n", fb->card_name);
 }
 static DEVICE_ATTR_RO(card_name);
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Deepak, thank you for the patch.

There are many other sysfs show functions in this driver that can be converted to use sysfs_emit().

But, the perfect musn't be the enemy of the good:

Quoted 26 lines · Deepak R Varma

Convert snprintf calls in device show functions to sysfs_emit for PAGE_SIZE buffer safety.
Warning generated by: scripts/coccinelle/api/device_attr_show.cocci

---
 drivers/staging/fieldbus/dev_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/fieldbus/dev_core.c +1 -2
index 1ba0234cc60d..698d7b479270 100644
@@ -70,7 +70,7 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr,
         * card_name was provided by child driver, could potentially be long.
         * protect against buffer overrun.
         */
-       return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name);
+       return sysfs_emit(buf, "%s\n", fb->card_name);
 }
 static DEVICE_ATTR_RO(card_name);
 
--

2.25.1

#2 lore raw
Quoted 4 lines · Sven Van Asbroeck

Hi Deepak, thank you for the patch.

There are many other sysfs show functions in this driver that can be converted to use sysfs_emit().

Hello Sven & Greg,
Is it okay for me to now change other show functions as suggested for this driver and send another patch?
Just want to confirm since I will be sending the patches from the linux next tree and for the staging driver.

Thank you.
./drv

Quoted 32 lines

But, the perfect musn't be the enemy of the good:

Quoted 26 lines · Deepak R Varma

Convert snprintf calls in device show functions to sysfs_emit for PAGE_SIZE buffer safety.
Warning generated by: scripts/coccinelle/api/device_attr_show.cocci

---
 drivers/staging/fieldbus/dev_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/fieldbus/dev_core.c +1 -2
index 1ba0234cc60d..698d7b479270 100644
@@ -70,7 +70,7 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr,
         * card_name was provided by child driver, could potentially be long.
         * protect against buffer overrun.
         */
-       return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name);
+       return sysfs_emit(buf, "%s\n", fb->card_name);
 }
 static DEVICE_ATTR_RO(card_name);
 
--

2.25.1