mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: snic: Use sysfs_emit in show function callback
@ 2023-01-30 16:26 Deepak R Varma
  2023-01-30 19:21 ` ALOK TIWARI
  0 siblings, 1 reply; 4+ messages in thread
From: Deepak R Varma @ 2023-01-30 16:26 UTC (permalink / raw)
  To: Karan Tilak Kumar, Sesidhar Baddela, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi, linux-kernel
  Cc: Saurabh Singh Sengar, Praveen Kumar, Deepak R Varma

According to Documentation/filesystems/sysfs.rst, the show() callback
function of kobject attributes should strictly use sysfs_emit() instead
of sprintf() family functions.
Issue identified using the device_attr_show.cocci Coccinelle script.

Signed-off-by: Deepak R Varma <drv@mailo.com>
---
 drivers/scsi/snic/snic_attrs.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/snic/snic_attrs.c b/drivers/scsi/snic/snic_attrs.c
index 3ddbdbc3ded1..56c46ea06e60 100644
--- a/drivers/scsi/snic/snic_attrs.c
+++ b/drivers/scsi/snic/snic_attrs.c
@@ -13,7 +13,7 @@ snic_show_sym_name(struct device *dev,
 {
 	struct snic *snic = shost_priv(class_to_shost(dev));
 
-	return snprintf(buf, PAGE_SIZE, "%s\n", snic->name);
+	return sysfs_emit(buf, "%s\n", snic->name);
 }
 
 static ssize_t
@@ -23,8 +23,7 @@ snic_show_state(struct device *dev,
 {
 	struct snic *snic = shost_priv(class_to_shost(dev));
 
-	return snprintf(buf, PAGE_SIZE, "%s\n",
-			snic_state_str[snic_get_state(snic)]);
+	return sysfs_emit(buf, "%s\n", snic_state_str[snic_get_state(snic)]);
 }
 
 static ssize_t
@@ -32,7 +31,7 @@ snic_show_drv_version(struct device *dev,
 		      struct device_attribute *attr,
 		      char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION);
+	return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION);
 }
 
 static ssize_t
@@ -45,8 +44,7 @@ snic_show_link_state(struct device *dev,
 	if (snic->config.xpt_type == SNIC_DAS)
 		snic->link_status = svnic_dev_link_status(snic->vdev);
 
-	return snprintf(buf, PAGE_SIZE, "%s\n",
-			(snic->link_status) ? "Link Up" : "Link Down");
+	return sysfs_emit(buf, "%s\n", (snic->link_status) ? "Link Up" : "Link Down");
 }
 
 static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);
-- 
2.34.1




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

* Re: [PATCH] scsi: snic: Use sysfs_emit in show function callback
  2023-01-30 16:26 [PATCH] scsi: snic: Use sysfs_emit in show function callback Deepak R Varma
@ 2023-01-30 19:21 ` ALOK TIWARI
  2023-01-30 19:35   ` Deepak R Varma
  0 siblings, 1 reply; 4+ messages in thread
From: ALOK TIWARI @ 2023-01-30 19:21 UTC (permalink / raw)
  To: Deepak R Varma, Karan Tilak Kumar, Sesidhar Baddela,
	James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	linux-kernel
  Cc: Saurabh Singh Sengar, Praveen Kumar

code changes look good.

commit message can be more simpler like  "show() should only use 
sysfs_emit() or sysfs_emit_at() when formatting the
value to be returned to user space."

and in place of kobject attributes , device attribute is more relevant here.

Thanks,
Alok

On 1/30/2023 9:56 PM, Deepak R Varma wrote:
> According to Documentation/filesystems/sysfs.rst, the show() callback
> function of kobject attributes should strictly use sysfs_emit() instead
> of sprintf() family functions.
> Issue identified using the device_attr_show.cocci Coccinelle script.
>
> Signed-off-by: Deepak R Varma <drv@mailo.com>
> ---
>   drivers/scsi/snic/snic_attrs.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/scsi/snic/snic_attrs.c b/drivers/scsi/snic/snic_attrs.c
> index 3ddbdbc3ded1..56c46ea06e60 100644
> --- a/drivers/scsi/snic/snic_attrs.c
> +++ b/drivers/scsi/snic/snic_attrs.c
> @@ -13,7 +13,7 @@ snic_show_sym_name(struct device *dev,
>   {
>   	struct snic *snic = shost_priv(class_to_shost(dev));
>   
> -	return snprintf(buf, PAGE_SIZE, "%s\n", snic->name);
> +	return sysfs_emit(buf, "%s\n", snic->name);
>   }
>   
>   static ssize_t
> @@ -23,8 +23,7 @@ snic_show_state(struct device *dev,
>   {
>   	struct snic *snic = shost_priv(class_to_shost(dev));
>   
> -	return snprintf(buf, PAGE_SIZE, "%s\n",
> -			snic_state_str[snic_get_state(snic)]);
> +	return sysfs_emit(buf, "%s\n", snic_state_str[snic_get_state(snic)]);
>   }
>   
>   static ssize_t
> @@ -32,7 +31,7 @@ snic_show_drv_version(struct device *dev,
>   		      struct device_attribute *attr,
>   		      char *buf)
>   {
> -	return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION);
> +	return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION);
>   }
>   
>   static ssize_t
> @@ -45,8 +44,7 @@ snic_show_link_state(struct device *dev,
>   	if (snic->config.xpt_type == SNIC_DAS)
>   		snic->link_status = svnic_dev_link_status(snic->vdev);
>   
> -	return snprintf(buf, PAGE_SIZE, "%s\n",
> -			(snic->link_status) ? "Link Up" : "Link Down");
> +	return sysfs_emit(buf, "%s\n", (snic->link_status) ? "Link Up" : "Link Down");
>   }
>   
>   static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);

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

* Re: [PATCH] scsi: snic: Use sysfs_emit in show function callback
  2023-01-30 19:21 ` ALOK TIWARI
@ 2023-01-30 19:35   ` Deepak R Varma
  2023-01-30 23:31     ` [External] : " ALOK TIWARI
  0 siblings, 1 reply; 4+ messages in thread
From: Deepak R Varma @ 2023-01-30 19:35 UTC (permalink / raw)
  To: ALOK TIWARI
  Cc: Karan Tilak Kumar, Sesidhar Baddela, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi, linux-kernel,
	Saurabh Singh Sengar, Praveen Kumar, Deepak R Varma

On Tue, Jan 31, 2023 at 12:51:40AM +0530, ALOK TIWARI wrote:
> code changes look good.
> 
> commit message can be more simpler like  "show() should only use
> sysfs_emit() or sysfs_emit_at() when formatting the
> value to be returned to user space."
> 
> and in place of kobject attributes , device attribute is more relevant here.

Hi Alok,
Thank you for the feedback. Your commends make perfect sense. Shall I resend a
v2 with the simplified language?

Regards,
Deepak.

> 
> Thanks,
> Alok
> 
> On 1/30/2023 9:56 PM, Deepak R Varma wrote:
> > According to Documentation/filesystems/sysfs.rst, the show() callback
> > function of kobject attributes should strictly use sysfs_emit() instead
> > of sprintf() family functions.
> > Issue identified using the device_attr_show.cocci Coccinelle script.
> > 
> > Signed-off-by: Deepak R Varma <drv@mailo.com>
> > ---
> >   drivers/scsi/snic/snic_attrs.c | 10 ++++------
> >   1 file changed, 4 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/scsi/snic/snic_attrs.c b/drivers/scsi/snic/snic_attrs.c
> > index 3ddbdbc3ded1..56c46ea06e60 100644
> > --- a/drivers/scsi/snic/snic_attrs.c
> > +++ b/drivers/scsi/snic/snic_attrs.c
> > @@ -13,7 +13,7 @@ snic_show_sym_name(struct device *dev,
> >   {
> >   	struct snic *snic = shost_priv(class_to_shost(dev));
> > -	return snprintf(buf, PAGE_SIZE, "%s\n", snic->name);
> > +	return sysfs_emit(buf, "%s\n", snic->name);
> >   }
> >   static ssize_t
> > @@ -23,8 +23,7 @@ snic_show_state(struct device *dev,
> >   {
> >   	struct snic *snic = shost_priv(class_to_shost(dev));
> > -	return snprintf(buf, PAGE_SIZE, "%s\n",
> > -			snic_state_str[snic_get_state(snic)]);
> > +	return sysfs_emit(buf, "%s\n", snic_state_str[snic_get_state(snic)]);
> >   }
> >   static ssize_t
> > @@ -32,7 +31,7 @@ snic_show_drv_version(struct device *dev,
> >   		      struct device_attribute *attr,
> >   		      char *buf)
> >   {
> > -	return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION);
> > +	return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION);
> >   }
> >   static ssize_t
> > @@ -45,8 +44,7 @@ snic_show_link_state(struct device *dev,
> >   	if (snic->config.xpt_type == SNIC_DAS)
> >   		snic->link_status = svnic_dev_link_status(snic->vdev);
> > -	return snprintf(buf, PAGE_SIZE, "%s\n",
> > -			(snic->link_status) ? "Link Up" : "Link Down");
> > +	return sysfs_emit(buf, "%s\n", (snic->link_status) ? "Link Up" : "Link Down");
> >   }
> >   static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);



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

* RE: [External] : Re: [PATCH] scsi: snic: Use sysfs_emit in show function callback
  2023-01-30 19:35   ` Deepak R Varma
@ 2023-01-30 23:31     ` ALOK TIWARI
  0 siblings, 0 replies; 4+ messages in thread
From: ALOK TIWARI @ 2023-01-30 23:31 UTC (permalink / raw)
  To: Deepak R Varma
  Cc: Karan Tilak Kumar, Sesidhar Baddela, James E.J. Bottomley,
	Martin Petersen, linux-scsi, linux-kernel, Saurabh Singh Sengar,
	Praveen Kumar

Yes, please.

Thanks,
Alok

-----Original Message-----
From: Deepak R Varma <drv@mailo.com> 
Sent: Tuesday, January 31, 2023 1:06 AM
To: ALOK TIWARI <alok.a.tiwari@oracle.com>
Cc: Karan Tilak Kumar <kartilak@cisco.com>; Sesidhar Baddela <sebaddel@cisco.com>; James E.J. Bottomley <jejb@linux.ibm.com>; Martin Petersen <martin.petersen@oracle.com>; linux-scsi@vger.kernel.org; linux-kernel@vger.kernel.org; Saurabh Singh Sengar <ssengar@microsoft.com>; Praveen Kumar <kumarpraveen@linux.microsoft.com>; Deepak R Varma <drv@mailo.com>
Subject: [External] : Re: [PATCH] scsi: snic: Use sysfs_emit in show function callback

On Tue, Jan 31, 2023 at 12:51:40AM +0530, ALOK TIWARI wrote:
> code changes look good.
> 
> commit message can be more simpler like  "show() should only use
> sysfs_emit() or sysfs_emit_at() when formatting the value to be 
> returned to user space."
> 
> and in place of kobject attributes , device attribute is more relevant here.

Hi Alok,
Thank you for the feedback. Your commends make perfect sense. Shall I resend a
v2 with the simplified language?

Regards,
Deepak.

> 
> Thanks,
> Alok
> 
> On 1/30/2023 9:56 PM, Deepak R Varma wrote:
> > According to Documentation/filesystems/sysfs.rst, the show() 
> > callback function of kobject attributes should strictly use 
> > sysfs_emit() instead of sprintf() family functions.
> > Issue identified using the device_attr_show.cocci Coccinelle script.
> > 
> > Signed-off-by: Deepak R Varma <drv@mailo.com>
> > ---
> >   drivers/scsi/snic/snic_attrs.c | 10 ++++------
> >   1 file changed, 4 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/scsi/snic/snic_attrs.c 
> > b/drivers/scsi/snic/snic_attrs.c index 3ddbdbc3ded1..56c46ea06e60 
> > 100644
> > --- a/drivers/scsi/snic/snic_attrs.c
> > +++ b/drivers/scsi/snic/snic_attrs.c
> > @@ -13,7 +13,7 @@ snic_show_sym_name(struct device *dev,
> >   {
> >   	struct snic *snic = shost_priv(class_to_shost(dev));
> > -	return snprintf(buf, PAGE_SIZE, "%s\n", snic->name);
> > +	return sysfs_emit(buf, "%s\n", snic->name);
> >   }
> >   static ssize_t
> > @@ -23,8 +23,7 @@ snic_show_state(struct device *dev,
> >   {
> >   	struct snic *snic = shost_priv(class_to_shost(dev));
> > -	return snprintf(buf, PAGE_SIZE, "%s\n",
> > -			snic_state_str[snic_get_state(snic)]);
> > +	return sysfs_emit(buf, "%s\n", 
> > +snic_state_str[snic_get_state(snic)]);
> >   }
> >   static ssize_t
> > @@ -32,7 +31,7 @@ snic_show_drv_version(struct device *dev,
> >   		      struct device_attribute *attr,
> >   		      char *buf)
> >   {
> > -	return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION);
> > +	return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION);
> >   }
> >   static ssize_t
> > @@ -45,8 +44,7 @@ snic_show_link_state(struct device *dev,
> >   	if (snic->config.xpt_type == SNIC_DAS)
> >   		snic->link_status = svnic_dev_link_status(snic->vdev);
> > -	return snprintf(buf, PAGE_SIZE, "%s\n",
> > -			(snic->link_status) ? "Link Up" : "Link Down");
> > +	return sysfs_emit(buf, "%s\n", (snic->link_status) ? "Link Up" : 
> > +"Link Down");
> >   }
> >   static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, 
> > NULL);



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

end of thread, other threads:[~2023-01-30 23:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-30 16:26 [PATCH] scsi: snic: Use sysfs_emit in show function callback Deepak R Varma
2023-01-30 19:21 ` ALOK TIWARI
2023-01-30 19:35   ` Deepak R Varma
2023-01-30 23:31     ` [External] : " ALOK TIWARI

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®