linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: atm: don't use snprintf() for sysfs attrs
@ 2020-08-24 22:23 Alex Dewar
  2020-08-25  8:12 ` David Laight
  2020-08-27  6:42 ` Rasmus Villemoes
  0 siblings, 2 replies; 33+ messages in thread
From: Alex Dewar @ 2020-08-24 22:23 UTC (permalink / raw)
  Cc: Alex Dewar, Greg Kroah-Hartman, Gustavo A. R. Silva,
	accessrunner-general, linux-usb, linux-kernel

kernel/cpu.c: don't use snprintf() for sysfs attrs

As per the documentation (Documentation/filesystems/sysfs.rst),
snprintf() should not be used for formatting values returned by sysfs.

In all of these cases, sprintf() suffices as we know that the formatted
strings will be less than PAGE_SIZE in length.

Issue identified by Coccinelle.

Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
---
 drivers/usb/atm/cxacru.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index ea66f8f385bae..e62a770a5d3bf 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -230,12 +230,12 @@ CXACRU__ATTR_INIT(_name)
 
 static ssize_t cxacru_sysfs_showattr_u32(u32 value, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%u\n", value);
+	return sprintf(buf, "%u\n", value);
 }
 
 static ssize_t cxacru_sysfs_showattr_s8(s8 value, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%d\n", value);
+	return sprintf(buf, "%d\n", value);
 }
 
 static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf)
@@ -255,8 +255,8 @@ static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf)
 	static char *str[] = { "no", "yes" };
 
 	if (unlikely(value >= ARRAY_SIZE(str)))
-		return snprintf(buf, PAGE_SIZE, "%u\n", value);
-	return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
+		return sprintf(buf, "%u\n", value);
+	return sprintf(buf, "%s\n", str[value]);
 }
 
 static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
@@ -264,8 +264,8 @@ static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
 	static char *str[] = { NULL, "not connected", "connected", "lost" };
 
 	if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
-		return snprintf(buf, PAGE_SIZE, "%u\n", value);
-	return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
+		return sprintf(buf, "%u\n", value);
+	return sprintf(buf, "%s\n", str[value]);
 }
 
 static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
@@ -275,8 +275,8 @@ static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
 		"waiting", "initialising"
 	};
 	if (unlikely(value >= ARRAY_SIZE(str)))
-		return snprintf(buf, PAGE_SIZE, "%u\n", value);
-	return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
+		return sprintf(buf, "%u\n", value);
+	return sprintf(buf, "%s\n", str[value]);
 }
 
 static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
@@ -288,8 +288,8 @@ static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
 			"ITU-T G.992.2 (G.LITE)"
 	};
 	if (unlikely(value >= ARRAY_SIZE(str)))
-		return snprintf(buf, PAGE_SIZE, "%u\n", value);
-	return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
+		return sprintf(buf, "%u\n", value);
+	return sprintf(buf, "%s\n", str[value]);
 }
 
 /*
@@ -309,8 +309,7 @@ static ssize_t mac_address_show(struct device *dev,
 	if (instance == NULL || instance->usbatm->atm_dev == NULL)
 		return -ENODEV;
 
-	return snprintf(buf, PAGE_SIZE, "%pM\n",
-		instance->usbatm->atm_dev->esi);
+	return sprintf(buf, "%pM\n", instance->usbatm->atm_dev->esi);
 }
 
 static ssize_t adsl_state_show(struct device *dev,
@@ -326,8 +325,8 @@ static ssize_t adsl_state_show(struct device *dev,
 
 	value = instance->card_info[CXINF_LINE_STARTABLE];
 	if (unlikely(value >= ARRAY_SIZE(str)))
-		return snprintf(buf, PAGE_SIZE, "%u\n", value);
-	return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
+		return sprintf(buf, "%u\n", value);
+	return sprintf(buf, "%s\n", str[value]);
 }
 
 static ssize_t adsl_state_store(struct device *dev,
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2020-08-28  8:22 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-24 22:23 [PATCH] usb: atm: don't use snprintf() for sysfs attrs Alex Dewar
2020-08-25  8:12 ` David Laight
2020-08-25  8:17   ` Alex Dewar
2020-08-25  9:07     ` David Laight
2020-08-25  8:24   ` Greg Kroah-Hartman
2020-08-27 16:49     ` Kees Cook
2020-08-27 17:45       ` Greg Kroah-Hartman
2020-08-27  6:42 ` Rasmus Villemoes
2020-08-27  7:15   ` Greg Kroah-Hartman
2020-08-27 13:18     ` Alex Dewar
2020-08-27 13:41       ` Rasmus Villemoes
2020-08-27 14:48         ` Alex Dewar
2020-08-27 16:58           ` Joe Perches
2020-08-27 19:42             ` [Cocci] " Julia Lawall
2020-08-27 20:29               ` Joe Perches
2020-08-27 21:00                 ` Joe Perches
2020-08-27 21:29                 ` Julia Lawall
2020-08-27 22:03                 ` David Laight
2020-08-27 22:11                   ` Joe Perches
2020-08-27 22:16                     ` Kees Cook
2020-08-27 21:01               ` Denis Efremov
2020-08-27 21:36                 ` Julia Lawall
2020-08-27 21:44                   ` Joe Perches
2020-08-27 22:38                     ` Denis Efremov
2020-08-27 22:48                       ` Joe Perches
2020-08-27 22:20                 ` Kees Cook
2020-08-27 22:45                   ` Joe Perches
2020-08-28  4:12                     ` Joe Perches
2020-08-28  7:58                       ` Kees Cook
2020-08-28  8:10                         ` Joe Perches
2020-08-28  8:22                           ` Joe Perches
2020-08-28  7:39                   ` David Laight
2020-08-27 21:54             ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).