Skip to contentSkip to conversation

uacce: use sysfs_emit instead of sprintf

PATCH Superseded Kai Ye 2 participants 4 messages May 17, 2021

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kai Ye

author
#0 lore raw

PATCH 1/1 uacce: use sysfs_emit instead of sprintf

Use the sysfs_emit to replace sprintf.

---
 drivers/misc/uacce/uacce.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/misc/uacce/uacce.c +6 -6
index d07af4e..c8db16c 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.8.1
maintainer
#1 lore raw
Quoted 1 line · Kai Ye

Use the sysfs_emit to replace sprintf.

That says _what_ you did, not _why_ you are doing this. What problem are you solving with this change?

thanks,

greg k-h

author
#2 lore raw
Quoted 11 lines · Greg KH
Quoted 1 line · Kai Ye

Use the sysfs_emit to replace sprintf.

That says _what_ you did, not _why_ you are doing this. What problem are you solving with this change?

thanks,

greg k-h
.

sprintf is not safe, and it not recommended to use.
sprintf does not know the PAGE_SIZE maximum of the temporary buffer
used for outputting sysfs content and it's possible to overrun the
PAGE_SIZE buffer length. so used sysfs_emit that knows that the size
of the call situations that also ensures that no overrun is done. so use sysfs_emit to replace sprintf maybe better.

thanks,
Kai Ye

maintainer
#3 lore raw
Quoted 9 lines · yekai(A)
Quoted 6 lines · Greg KH
Quoted 1 line · Kai Ye

Use the sysfs_emit to replace sprintf.

That says _what_ you did, not _why_ you are doing this. What problem are you solving with this change?

Quoted 6 lines
Quoted 5 lines

thanks,

greg k-h
.

sprintf is not safe, and it not recommended to use.

Why not? What is "unsafe" with it in this function?

Quoted 5 lines

sprintf does not know the PAGE_SIZE maximum of the temporary buffer used for outputting sysfs content and it's possible to overrun the PAGE_SIZE buffer length. so used sysfs_emit that knows that the size of the call situations that also ensures that no overrun is done. so use sysfs_emit to replace sprintf maybe better.

But that's not a problem at all for these calls, right? If so, please show me how that could ever happen.

thanks,

greg k-h