linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: isci: convert sysfs sprintf/snprintf family to sysfs_emit
@ 2021-02-03  8:43 Jiapeng Chong
  2021-02-03 16:15 ` James Bottomley
  0 siblings, 1 reply; 2+ messages in thread
From: Jiapeng Chong @ 2021-02-03  8:43 UTC (permalink / raw)
  To: intel-linux-scu
  Cc: artur.paszkiewicz, jejb, martin.petersen, linux-scsi,
	linux-kernel, Jiapeng Chong

Fix the following coccicheck warning:

 ./drivers/scsi/isci/init.c:140:8-16: WARNING: use scnprintf or sprintf.

Reported-by: Abaci Robot<abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
 drivers/scsi/isci/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c
index c452849..741a98e 100644
--- a/drivers/scsi/isci/init.c
+++ b/drivers/scsi/isci/init.c
@@ -137,7 +137,7 @@ static ssize_t isci_show_id(struct device *dev, struct device_attribute *attr, c
 	struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
 	struct isci_host *ihost = container_of(sas_ha, typeof(*ihost), sas_ha);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", ihost->id);
+	return sysfs_emit(buf, "%d\n", ihost->id);
 }
 
 static DEVICE_ATTR(isci_id, S_IRUGO, isci_show_id, NULL);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] scsi: isci: convert sysfs sprintf/snprintf family to sysfs_emit
  2021-02-03  8:43 [PATCH] scsi: isci: convert sysfs sprintf/snprintf family to sysfs_emit Jiapeng Chong
@ 2021-02-03 16:15 ` James Bottomley
  0 siblings, 0 replies; 2+ messages in thread
From: James Bottomley @ 2021-02-03 16:15 UTC (permalink / raw)
  To: Jiapeng Chong, intel-linux-scu
  Cc: artur.paszkiewicz, martin.petersen, linux-scsi, linux-kernel

On Wed, 2021-02-03 at 16:43 +0800, Jiapeng Chong wrote:
> Fix the following coccicheck warning:
> 
>  ./drivers/scsi/isci/init.c:140:8-16: WARNING: use scnprintf or
> sprintf.
> 
> Reported-by: Abaci Robot<abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
>  drivers/scsi/isci/init.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c
> index c452849..741a98e 100644
> --- a/drivers/scsi/isci/init.c
> +++ b/drivers/scsi/isci/init.c
> @@ -137,7 +137,7 @@ static ssize_t isci_show_id(struct device *dev,
> struct device_attribute *attr, c
>  	struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
>  	struct isci_host *ihost = container_of(sas_ha, typeof(*ihost),
> sas_ha);
>  
> -	return snprintf(buf, PAGE_SIZE, "%d\n", ihost->id);
> +	return sysfs_emit(buf, "%d\n", ihost->id);

What's the point of doing this change?  We'd have to have 13,600 bit
integer types before this could ever possibly overflow and the
difference between snprintf and scnprintf actually matter from a
practical point of view.  Perhaps the coccinelle check should be
updated to account for these common impossible to overflow situations.

James



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-03 16:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03  8:43 [PATCH] scsi: isci: convert sysfs sprintf/snprintf family to sysfs_emit Jiapeng Chong
2021-02-03 16:15 ` James Bottomley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).