Skip to contentSkip to conversation

coccinelle: api: fix device_attr_show.cocci warnings

PATCH Rong Chen 1 participant 1 message Dec 30, 2020 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Rong Chen

author
#1 lore raw

Hi Denis,

Thanks for your reminding, we have ignored this warning.

Best Regards,
Rong Chen

Quoted 101 lines · Denis Efremov

Hi,

Could you please disable automatic emails based on this rule? The rule requires an update after sysfs_emit patchset by Joe Perches was merged.
https://lore.kernel.org/linux-pm/5d606519698ce4c8f1203a2b35797d8254c6050a.1600285923.git.joe(a)perches.com/T/

I'll prepare an update for the rule.

Thanks,
Denis

Quoted 87 lines · kernel test robot

CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: Denis Efremov <[email protected]>
CC: Julia Lawall <[email protected]>
CC: "Rafael J. Wysocki" <[email protected]>
CC: Len Brown <[email protected]>
CC: linux-acpi(a)vger.kernel.org
CC: linux-kernel(a)vger.kernel.org

From: kernel test robot <[email protected]>

drivers/acpi/bgrt.c:28:8-16: WARNING: use scnprintf or sprintf drivers/acpi/bgrt.c:35:8-16: WARNING: use scnprintf or sprintf drivers/acpi/bgrt.c:21:8-16: WARNING: use scnprintf or sprintf drivers/acpi/bgrt.c:42:8-16: WARNING: use scnprintf or sprintf drivers/acpi/bgrt.c:49:8-16: WARNING: use scnprintf or sprintf

From Documentation/filesystems/sysfs.txt:
show() must not use snprintf() when formatting the value to be returned to user space. If you can guarantee that an overflow will never happen you can use sprintf() otherwise you must use scnprintf().

Generated by: scripts/coccinelle/api/device_attr_show.cocci

Fixes abfc19ff202d ("coccinelle: api: add device_attr_show script")
CC Denis Efremov <[email protected]>

---

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   dea8dcf2a9fa8cc540136a6cd885c3beece16ec3
commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script

:::::: branch date: 7 hours ago
:::::: commit date: 5 months ago

Please take the patch only if it's a positive warning. Thanks!

  bgrt.c |   10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
drivers/acpi/bgrt.c +5 -5
@@ -18,35 +18,35 @@ static struct kobject *bgrt_kobj;
  static ssize_t show_version(struct device *dev,
  			    struct device_attribute *attr, char *buf)
  {
-	return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.version);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.version);
  }
  static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
 
  static ssize_t show_status(struct device *dev,
  			   struct device_attribute *attr, char *buf)
  {
-	return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.status);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.status);
  }
  static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
 
  static ssize_t show_type(struct device *dev,
  			 struct device_attribute *attr, char *buf)
  {
-	return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_type);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_type);
  }
  static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
 
  static ssize_t show_xoffset(struct device *dev,
  			    struct device_attribute *attr, char *buf)
  {
-	return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_x);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_x);
  }
  static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL);
 
  static ssize_t show_yoffset(struct device *dev,
  			    struct device_attribute *attr, char *buf)
  {
-	return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_y);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_y);
  }
  static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);