Re: [PATCH] fsi: master: replace snprintf in show functions with sysfs_emit

From: Joe Perches
Date: Fri Oct 22 2021 - 00:49:40 EST


On Fri, 2021-10-22 at 02:50 +0000, cgel.zte@xxxxxxxxx wrote:
> From: Ye Guojin <ye.guojin@xxxxxxxxxx>
>
> coccicheck complains about the use of snprintf() in sysfs show
> functions:
> WARNING use scnprintf or sprintf
[]
> diff --git a/drivers/fsi/fsi-master-ast-cf.c b/drivers/fsi/fsi-master-ast-cf.c
[]
> @@ -1083,8 +1083,7 @@ static ssize_t external_mode_show(struct device *dev,
> {
> struct fsi_master_acf *master = dev_get_drvdata(dev);
>
> - return snprintf(buf, PAGE_SIZE - 1, "%u\n",
> - master->external_mode ? 1 : 0);
> + return sysfs_emit(buf, "%u\n", master->external_mode ? 1 : 0);

external_mode is already bool so this ?: isn't necessary.

> diff --git a/drivers/fsi/fsi-master-gpio.c b/drivers/fsi/fsi-master-gpio.c
[]
> @@ -718,8 +718,7 @@ static ssize_t external_mode_show(struct device *dev,
> {
> struct fsi_master_gpio *master = dev_get_drvdata(dev);
>
> - return snprintf(buf, PAGE_SIZE - 1, "%u\n",
> - master->external_mode ? 1 : 0);
> + return sysfs_emit(buf, "%u\n", master->external_mode ? 1 : 0);

here too