uacce: use sysfs_emit instead of sprintf
authorKai Ye <yekai13@huawei.com>
Mon, 6 Dec 2021 10:47:24 +0000 (18:47 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 21 Dec 2021 09:13:34 +0000 (10:13 +0100)
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.

Signed-off-by: Kai Ye <yekai13@huawei.com>
Link: https://lore.kernel.org/r/20211206104724.11559-1-yekai13@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/uacce/uacce.c

index 488eeb2811aeb3d0a0df6d300c563bdfa439c535..281c54003edc4b3283d9f41b3f0f528c8cf04278 100644 (file)
@@ -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);
 }