Re: [PATCH v2] uacce: use sysfs_emit instead of sprintf

From: Joe Perches
Date: Mon Dec 06 2021 - 02:19:32 EST


On Mon, 2021-12-06 at 15:09 +0800, Kai Ye wrote:
> 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.
[]
> diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
[]
> @@ -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));

> @@ -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...