Skip to contentSkip to conversation

uacce: use sysfs_emit instead of sprintf

PATCH Superseded Kai Ye 3 participants 3 messages Dec 6, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kai Ye

author
#0 lore raw

PATCH v2 1/1 uacce: use sysfs_emit instead of sprintf

Use the sysfs_emit to replace sprintf. sprintf may cause output defect in sysfs content, it is better to use new added sysfs_emit function which knows the size of the temporary buffer.

changes v1->v2:
modfiy the comments.

---
 drivers/misc/uacce/uacce.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/misc/uacce/uacce.c +6 -6
index 488eeb2811ae..281c54003edc 100644
@@ -289,7 +289,7 @@ static ssize_t api_show(struct device *dev,
 {
 	struct uacce_device *uacce = to_uacce_device(dev);
 
-	return sprintf(buf, "%s\n", uacce->api_ver);
+	return sysfs_emit(buf, "%s\n", uacce->api_ver);
 }
 
 static ssize_t flags_show(struct device *dev,
@@ -297,7 +297,7 @@ static ssize_t flags_show(struct device *dev,
 {
 	struct uacce_device *uacce = to_uacce_device(dev);
 
-	return sprintf(buf, "%u\n", uacce->flags);
+	return sysfs_emit(buf, "%u\n", uacce->flags);
 }
 
 static ssize_t available_instances_show(struct device *dev,
@@ -309,7 +309,7 @@ static ssize_t available_instances_show(struct device *dev,
 	if (!uacce->ops->get_available_instances)
 		return -ENODEV;
 
-	return sprintf(buf, "%d\n",
+	return sysfs_emit(buf, "%d\n",
 		       uacce->ops->get_available_instances(uacce));
 }
 
@@ -318,7 +318,7 @@ static ssize_t algorithms_show(struct device *dev,
 {
 	struct uacce_device *uacce = to_uacce_device(dev);
 
-	return sprintf(buf, "%s\n", uacce->algs);
+	return sysfs_emit(buf, "%s\n", uacce->algs);
 }
 
 static ssize_t region_mmio_size_show(struct device *dev,
@@ -326,7 +326,7 @@ static ssize_t region_mmio_size_show(struct device *dev,
 {
 	struct uacce_device *uacce = to_uacce_device(dev);
 
-	return sprintf(buf, "%lu\n",
+	return sysfs_emit(buf, "%lu\n",
 		       uacce->qf_pg_num[UACCE_QFRT_MMIO] << PAGE_SHIFT);
 }
 
@@ -335,7 +335,7 @@ static ssize_t region_dus_size_show(struct device *dev,
 {
 	struct uacce_device *uacce = to_uacce_device(dev);
 
-	return sprintf(buf, "%lu\n",
+	return sysfs_emit(buf, "%lu\n",
 		       uacce->qf_pg_num[UACCE_QFRT_DUS] << PAGE_SHIFT);
 }
 
Signature · 1 line
2.33.0
#1 lore raw
Quoted 4 lines · Kai Ye

Use the sysfs_emit to replace sprintf. sprintf may cause output defect in sysfs content, it is better to use new added sysfs_emit function which knows the size of the temporary buffer.

[]

drivers/misc/uacce/uacce.c

Quoted 1 line
drivers/misc/uacce/uacce.c +0 -0

[]

drivers/misc/uacce/uacce.c static ssize_t available_instances_show(struct device *dev, · line 313

Quoted 7 lines
drivers/misc/uacce/uacce.c +1 -1
@@ -309,7 +309,7 @@ static ssize_t available_instances_show(struct device *dev,
 	if (!uacce->ops->get_available_instances)
 		return -ENODEV;
 
-	return sprintf(buf, "%d\n",
+	return sysfs_emit(buf, "%d\n",
 		       uacce->ops->get_available_instances(uacce));

It's generally good form to rewrap the multiple line statements to the open parenthesis so the below would be better:

	return sysfs_emit(buf, "%d\n",
			  uacce->ops->get_available_instances(uacce));

drivers/misc/uacce/uacce.c static ssize_t region_mmio_size_show(struct device *dev, · line 330

Quoted 7 lines
drivers/misc/uacce/uacce.c +1 -1
@@ -326,7 +326,7 @@ static ssize_t region_mmio_size_show(struct device *dev,
 {
 	struct uacce_device *uacce = to_uacce_device(dev);
 
-	return sprintf(buf, "%lu\n",
+	return sysfs_emit(buf, "%lu\n",
 		       uacce->qf_pg_num[UACCE_QFRT_MMIO] << PAGE_SHIFT);

etc...

maintainer
#2 lore raw
In reply to Kai Ye
Quoted 4 lines · Kai Ye

Use the sysfs_emit to replace sprintf. sprintf may cause output defect in sysfs content, it is better to use new added sysfs_emit function which knows the size of the temporary buffer.

For these calls you have replaced, there is no real reason to change as it is obvious that the buffer is big enough. So there is no "may cause output defect" here.

Also, feel free to use the full 72 columns for your changelog text.

Quoted 6 lines

changes v1->v2:
modfiy the comments.
---

As per the documentation, the "changes..." lines go below the --- line so that git will remove them automatically.

Please fix up and resend a v3.

thanks,

greg k-h