Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

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>

authored by

Kai Ye and committed by
Greg Kroah-Hartman
2d2802fb 909c648e

+6 -6
+6 -6
drivers/misc/uacce/uacce.c
··· 289 289 { 290 290 struct uacce_device *uacce = to_uacce_device(dev); 291 291 292 - return sprintf(buf, "%s\n", uacce->api_ver); 292 + return sysfs_emit(buf, "%s\n", uacce->api_ver); 293 293 } 294 294 295 295 static ssize_t flags_show(struct device *dev, ··· 297 297 { 298 298 struct uacce_device *uacce = to_uacce_device(dev); 299 299 300 - return sprintf(buf, "%u\n", uacce->flags); 300 + return sysfs_emit(buf, "%u\n", uacce->flags); 301 301 } 302 302 303 303 static ssize_t available_instances_show(struct device *dev, ··· 309 309 if (!uacce->ops->get_available_instances) 310 310 return -ENODEV; 311 311 312 - return sprintf(buf, "%d\n", 312 + return sysfs_emit(buf, "%d\n", 313 313 uacce->ops->get_available_instances(uacce)); 314 314 } 315 315 ··· 318 318 { 319 319 struct uacce_device *uacce = to_uacce_device(dev); 320 320 321 - return sprintf(buf, "%s\n", uacce->algs); 321 + return sysfs_emit(buf, "%s\n", uacce->algs); 322 322 } 323 323 324 324 static ssize_t region_mmio_size_show(struct device *dev, ··· 326 326 { 327 327 struct uacce_device *uacce = to_uacce_device(dev); 328 328 329 - return sprintf(buf, "%lu\n", 329 + return sysfs_emit(buf, "%lu\n", 330 330 uacce->qf_pg_num[UACCE_QFRT_MMIO] << PAGE_SHIFT); 331 331 } 332 332 ··· 335 335 { 336 336 struct uacce_device *uacce = to_uacce_device(dev); 337 337 338 - return sprintf(buf, "%lu\n", 338 + return sysfs_emit(buf, "%lu\n", 339 339 uacce->qf_pg_num[UACCE_QFRT_DUS] << PAGE_SHIFT); 340 340 } 341 341