Skip to contentSkip to conversation

mei: bus: use scnprintf in *_show

char-misc-next Tomas Winkler 2 participants 2 messages Mar 24, 2016 – Mar 31, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

From: Rasmus Villemoes <[email protected]>

There's no reason to duplicate the logic provided by scnprintf().

---
 drivers/misc/mei/bus.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)
drivers/misc/mei/bus.c +4 -15
index 5d5996e39a67..04dc05150898 100644
@@ -634,11 +634,8 @@ static ssize_t name_show(struct device *dev, struct device_attribute *a,
 			     char *buf)
 {
 	struct mei_cl_device *cldev = to_mei_cl_device(dev);
-	size_t len;
 
-	len = snprintf(buf, PAGE_SIZE, "%s", cldev->name);
-
-	return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
+	return scnprintf(buf, PAGE_SIZE, "%s", cldev->name);
 }
 static DEVICE_ATTR_RO(name);
 
@@ -647,11 +644,8 @@ static ssize_t uuid_show(struct device *dev, struct device_attribute *a,
 {
 	struct mei_cl_device *cldev = to_mei_cl_device(dev);
 	const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl);
-	size_t len;
-
-	len = snprintf(buf, PAGE_SIZE, "%pUl", uuid);
 
-	return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
+	return scnprintf(buf, PAGE_SIZE, "%pUl", uuid);
 }
 static DEVICE_ATTR_RO(uuid);
 
@@ -660,11 +654,8 @@ static ssize_t version_show(struct device *dev, struct device_attribute *a,
 {
 	struct mei_cl_device *cldev = to_mei_cl_device(dev);
 	u8 version = mei_me_cl_ver(cldev->me_cl);
-	size_t len;
-
-	len = snprintf(buf, PAGE_SIZE, "%02X", version);
 
-	return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
+	return scnprintf(buf, PAGE_SIZE, "%02X", version);
 }
 static DEVICE_ATTR_RO(version);
 
@@ -673,10 +664,8 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
 {
 	struct mei_cl_device *cldev = to_mei_cl_device(dev);
 	const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl);
-	size_t len;
 
-	len = snprintf(buf, PAGE_SIZE, "mei:%s:%pUl:", cldev->name, uuid);
-	return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
+	return scnprintf(buf, PAGE_SIZE, "mei:%s:%pUl:", cldev->name, uuid);
 }
 static DEVICE_ATTR_RO(modalias);
 
Signature · 1 line
2.4.3
#1 lore raw
Quoted 3 lines · Tomas Winkler

From: Rasmus Villemoes <[email protected]>

There's no reason to duplicate the logic provided by scnprintf().

And really, there's no need for any of this, just use sprintf() for sysfs attributes that are the size of an integer.

But I'll take this for now, just to keep people happy because "everyone knows sprintf() should never be used"...

bah.

greg k-h