uacce: use sysfs_emit instead of sprintf
Subsystems (2)
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
@@ -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
Greg KH
maintainerQuoted 1 line · Kai Ye
Use the
sysfs_emitto 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
Quoted 11 lines · Greg KH
Quoted 1 line · Kai Ye
Use the
sysfs_emitto 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 thePAGE_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
Greg KH
maintainerQuoted 9 lines · yekai(A)
Quoted 6 lines · Greg KH
Quoted 1 line · Kai Ye
Use the
sysfs_emitto 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_SIZEmaximum of the temporary buffer used for outputting sysfs content and it's possible to overrun thePAGE_SIZEbuffer length. so usedsysfs_emitthat knows that the size of the call situations that also ensures that no overrun is done. so usesysfs_emitto 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