[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <9fc56cf0-1a8c-fa9b-60ce-74b7c7104902@opensource.wdc.com>
Date: Wed, 9 Feb 2022 11:44:53 +0900
From: Damien Le Moal <damien.lemoal@...nsource.wdc.com>
To: davidcomponentone@...il.com, jejb@...ux.ibm.com
Cc: martin.petersen@...cle.com, yang.guang5@....com.cn,
bvanassche@....org, linux-scsi@...r.kernel.org,
linux-kernel@...r.kernel.org, Zeal Robot <zealci@....com.cn>
Subject: Re: [PATCH] scsi: arcmsr: replace snprintf with sysfs_emit
On 2/9/22 09:47, davidcomponentone@...il.com wrote:
> From: Yang Guang <yang.guang5@....com.cn>
>
> coccinelle report:
> ./drivers/scsi/arcmsr/arcmsr_attr.c:297:8-16:
> WARNING: use scnprintf or sprintf
> ./drivers/scsi/arcmsr/arcmsr_attr.c:273:8-16:
> WARNING: use scnprintf or sprintf
> ./drivers/scsi/arcmsr/arcmsr_attr.c:285:8-16:
> WARNING: use scnprintf or sprintf
> ./drivers/scsi/arcmsr/arcmsr_attr.c:261:8-16:
> WARNING: use scnprintf or sprintf
> ./drivers/scsi/arcmsr/arcmsr_attr.c:374:8-16:
> WARNING: use scnprintf or sprintf
> ./drivers/scsi/arcmsr/arcmsr_attr.c:309:8-16:
> WARNING: use scnprintf or sprintf
> ./drivers/scsi/arcmsr/arcmsr_attr.c:348:8-16:
> WARNING: use scnprintf or sprintf
> ./drivers/scsi/arcmsr/arcmsr_attr.c:335:8-16:
> WARNING: use scnprintf or sprintf
> ./drivers/scsi/arcmsr/arcmsr_attr.c:361:8-16:
> WARNING: use scnprintf or sprintf
> ./drivers/scsi/arcmsr/arcmsr_attr.c:322:8-16:
> WARNING: use scnprintf or sprintf
>
> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
>
> Reported-by: Zeal Robot <zealci@....com.cn>
> Signed-off-by: Yang Guang <yang.guang5@....com.cn>
> Signed-off-by: David Yang <davidcomponentone@...il.com>
> ---
> drivers/scsi/arcmsr/arcmsr_attr.c | 30 ++++++++++--------------------
> 1 file changed, 10 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/scsi/arcmsr/arcmsr_attr.c b/drivers/scsi/arcmsr/arcmsr_attr.c
> index baeb5e795690..e66d761926e9 100644
> --- a/drivers/scsi/arcmsr/arcmsr_attr.c
> +++ b/drivers/scsi/arcmsr/arcmsr_attr.c
> @@ -258,8 +258,7 @@ static ssize_t
> arcmsr_attr_host_driver_version(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> - return snprintf(buf, PAGE_SIZE,
> - "%s\n",
> + return sysfs_emit(buf, "%s\n",
> ARCMSR_DRIVER_VERSION);
No need for the line break.
> }
>
> @@ -270,8 +269,7 @@ arcmsr_attr_host_driver_posted_cmd(struct device *dev,
> struct Scsi_Host *host = class_to_shost(dev);
> struct AdapterControlBlock *acb =
> (struct AdapterControlBlock *) host->hostdata;
> - return snprintf(buf, PAGE_SIZE,
> - "%4d\n",
> + return sysfs_emit(buf, "%4d\n",
> atomic_read(&acb->ccboutstandingcount));
> }
>
> @@ -282,8 +280,7 @@ arcmsr_attr_host_driver_reset(struct device *dev,
> struct Scsi_Host *host = class_to_shost(dev);
> struct AdapterControlBlock *acb =
> (struct AdapterControlBlock *) host->hostdata;
> - return snprintf(buf, PAGE_SIZE,
> - "%4d\n",
> + return sysfs_emit(buf, "%4d\n",
> acb->num_resets);
Please add a blank line after the declarations and there is no need for
the line break. The format should be %4u (unsigned value).
> }
>
> @@ -294,8 +291,7 @@ arcmsr_attr_host_driver_abort(struct device *dev,
> struct Scsi_Host *host = class_to_shost(dev);
> struct AdapterControlBlock *acb =
> (struct AdapterControlBlock *) host->hostdata;
> - return snprintf(buf, PAGE_SIZE,
> - "%4d\n",
> + return sysfs_emit(buf, "%4d\n",
> acb->num_aborts);
Same comments (all of them).
> }
>
> @@ -306,8 +302,7 @@ arcmsr_attr_host_fw_model(struct device *dev, struct device_attribute *attr,
> struct Scsi_Host *host = class_to_shost(dev);
> struct AdapterControlBlock *acb =
> (struct AdapterControlBlock *) host->hostdata;
> - return snprintf(buf, PAGE_SIZE,
> - "%s\n",
> + return sysfs_emit(buf, "%s\n",
> acb->firm_model);
blank line and line break comments apply.
> }
>
> @@ -319,8 +314,7 @@ arcmsr_attr_host_fw_version(struct device *dev,
> struct AdapterControlBlock *acb =
> (struct AdapterControlBlock *) host->hostdata;
>
> - return snprintf(buf, PAGE_SIZE,
> - "%s\n",
> + return sysfs_emit(buf, "%s\n",
> acb->firm_version);
line break not needed.
> }
>
> @@ -332,8 +326,7 @@ arcmsr_attr_host_fw_request_len(struct device *dev,
> struct AdapterControlBlock *acb =
> (struct AdapterControlBlock *) host->hostdata;
>
> - return snprintf(buf, PAGE_SIZE,
> - "%4d\n",
> + return sysfs_emit(buf, "%4d\n",
> acb->firm_request_len);
line break not needed and %u format.
> }
>
> @@ -345,8 +338,7 @@ arcmsr_attr_host_fw_numbers_queue(struct device *dev,
> struct AdapterControlBlock *acb =
> (struct AdapterControlBlock *) host->hostdata;
>
> - return snprintf(buf, PAGE_SIZE,
> - "%4d\n",
> + return sysfs_emit(buf, "%4d\n",
> acb->firm_numbers_queue);
Same.
> }
>
> @@ -358,8 +350,7 @@ arcmsr_attr_host_fw_sdram_size(struct device *dev,
> struct AdapterControlBlock *acb =
> (struct AdapterControlBlock *) host->hostdata;
>
> - return snprintf(buf, PAGE_SIZE,
> - "%4d\n",
> + return sysfs_emit(buf, "%4d\n",
> acb->firm_sdram_size);
Again same.
> }
>
> @@ -371,8 +362,7 @@ arcmsr_attr_host_fw_hd_channels(struct device *dev,
> struct AdapterControlBlock *acb =
> (struct AdapterControlBlock *) host->hostdata;
>
> - return snprintf(buf, PAGE_SIZE,
> - "%4d\n",
> + return sysfs_emit(buf, "%4d\n",
> acb->firm_hd_channels);
> }
And here too.
--
Damien Le Moal
Western Digital Research
Powered by blists - more mailing lists