Message ID | Y9fvsSJrflcIHm7e@ubun2204.myguest.virtualbox.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2274556wrn; Mon, 30 Jan 2023 08:30:24 -0800 (PST) X-Google-Smtp-Source: AK7set9zewq11kS8x1XrDSbI6I2xEPjRqp8FcjP/dDRbyx/6n4yfwXRozzYDByofsau8xNgRR/VA X-Received: by 2002:a17:90a:4b:b0:22c:3a1b:631f with SMTP id 11-20020a17090a004b00b0022c3a1b631fmr15680498pjb.38.1675096224290; Mon, 30 Jan 2023 08:30:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675096224; cv=none; d=google.com; s=arc-20160816; b=WrMpfCdG9YU6KIx9U9fvWAwBSTwqQKgag3/l2otNhrQ5+iUcze9d6AYCx1OiYFeL91 /ei5ipWBVAYVlDZ/WnRdZsdvcosCnbgu4CYRw8pO3tYaOqXBImOU2d0JsM45JzqbelLN ae21o3AIGN/wy0LUmeDXxEUPLL0rVr1u07uvxIrAPIr8hpM/EStGNdeekY0ObPbGXHVW eMCjC3sVrg7rDL1XHXvw5h2wznrrDgvHKKIRjuSalQBrBfoNeDAcsqRspdcVLh2aX8VN h4HtIJxDu6ZBiwJTicPJsCRQpvy1bsikHRIbZmVQudb8Gll1fl65J1pogv+J7xzJJLru apRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=UO9rDdWzVZO1R9QdigvR2ZLEyHZ+Y67iwORIp4WvoqM=; b=NSqnLH0fTHyhvG9+X8ksS9rl9IAQa2I5rlSAIhZrZIMOexNzBww4Wuks5EHA6V2Y37 8/S/dtMWAZjNsGHx0T7/fPgqdCZ7h3oqW32p7u3VbbbHLDWylTHvQ/TDF17+5fick0hS o/0/uNSqzR0F96riBHNa6MFOHaWEui+l0kvbr24E1TABjJCQAHtFYVUIpDETV+Shwt0d ofA1ELkYrv00Yoo3VdJWM6WLfOh7GLsKYcd1BCJ5h83vAz+pM3vTXTsy23dJ8fUoLpE1 sxceCG9ZWCI7wHGrA2TextOGgOEDaUaGmxWM3VZ85XFFxkhhMEkmn5RkxJ91+Szbelzg XloA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=IbGW6e4y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 32-20020a17090a0fa300b0022bf6d7260esi17557411pjz.68.2023.01.30.08.30.11; Mon, 30 Jan 2023 08:30:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=IbGW6e4y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236848AbjA3Q0s (ORCPT <rfc822;n2h9z4@gmail.com> + 99 others); Mon, 30 Jan 2023 11:26:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231538AbjA3Q0q (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 30 Jan 2023 11:26:46 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7FDD3A856; Mon, 30 Jan 2023 08:26:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1675095991; bh=WOQ4vuk34rA8b08A56gxt9geZ1TucBGZIWvT4ETxZIg=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=IbGW6e4yoU4N8jnk+gb10lFBklYd+2W/It+3J/QhfgIMobtaPdJc6y9BO2othIbxg JRDe8wYdbV3d7ohGr8KCQDZgriuZ4nx9P7TH0u/NVWaV/pYeK/bYfTmmaoaNHwojuw aRRvFB7kAclMZWKjGGhdhU1H8heZfzG4MjsBJCAc= Received: by b-6.in.mailobj.net [192.168.90.16] with ESMTP via ip-206.mailobj.net [213.182.55.206] Mon, 30 Jan 2023 17:26:31 +0100 (CET) X-EA-Auth: Iop45wzrRbdCV8RWDLbj/0flWLCA+fQ84U0oUYoywr0m1w/jsYoUdCyRQTjntI8xuq8QxZvlDC+KbaNmp/Tv59KAlvf6dJXs Date: Mon, 30 Jan 2023 21:56:25 +0530 From: Deepak R Varma <drv@mailo.com> To: Karan Tilak Kumar <kartilak@cisco.com>, Sesidhar Baddela <sebaddel@cisco.com>, "James E.J. Bottomley" <jejb@linux.ibm.com>, "Martin K. Petersen" <martin.petersen@oracle.com>, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar <ssengar@microsoft.com>, Praveen Kumar <kumarpraveen@linux.microsoft.com>, Deepak R Varma <drv@mailo.com> Subject: [PATCH] scsi: snic: Use sysfs_emit in show function callback Message-ID: <Y9fvsSJrflcIHm7e@ubun2204.myguest.virtualbox.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756465698895460635?= X-GMAIL-MSGID: =?utf-8?q?1756465698895460635?= |
Series |
scsi: snic: Use sysfs_emit in show function callback
|
|
Commit Message
Deepak R Varma
Jan. 30, 2023, 4:26 p.m. UTC
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(-)
Comments
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);
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);
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);
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);