Message ID | Y2tBJFSsyUzdb+eO@qemulion |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp167283wru; Tue, 8 Nov 2022 22:07:46 -0800 (PST) X-Google-Smtp-Source: AMsMyM4WlFJ8XMD3qYmfOaZm2BNT2AzrEPf7/3EFG5MhqYpmOQql4fphQNKDye2a6FFifFW3IBRS X-Received: by 2002:a17:902:d3cc:b0:186:9720:b19b with SMTP id w12-20020a170902d3cc00b001869720b19bmr59107528plb.3.1667974065817; Tue, 08 Nov 2022 22:07:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667974065; cv=none; d=google.com; s=arc-20160816; b=PUxaQp+TPZH4HNAUuPzOMnpy/5LMQ4+VT4AjWgdj8qYQCpTskXqOlmY5invk1l3EDI +Ufl0zSxQNtJmXwdp5cMORFWDlbjYy60lbF0wb0CWG2vh9pHM+F0F0sIukU3XN3UhDSO rn0gjERJfCNGG5dIxXuUZfQEWKjmduV/uIIMKuI1vDFGKLvANSyxYllanHv7LSr1ptvB jTVuyQZOc7kELwJ+dQBMR17ITgYshSha8qNvAso0b2MocXAgIcptnVffYuf7mbzYsHdI DTjjcnquJMVFRaeCvUZx5PzoHbIES0hiREGRQeF/SJh/T1JE+9Zt7U/RE2nM7o2auAGl 6miw== 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:to:from:date:dkim-signature; bh=pG1dtm0GLoTYlAzc7Pf+CpGFxCWvNx/IZcjAJ6mP5gI=; b=d4hHEaBbq/Eu0AjKqqAydNLjIkQcMuIulI+LQyzAxWyOjdp8rpG0wnJb1yvIqmMVPs yU9amaNx7/lJaHQG8MxSq6sRmlZV4I6bfpnyAWN2acZddjj8sBVJGpb2YUFAhK/1yL6/ j9ggDxxNwJalLnUTDMBpuNpb/IS/Pj4imDSG6Be6Z1cP2/Uh99+A9b78K6rLVP/j0cdD A7wtsuzRyh4MZi6utEnX+OLnCBJc3uBNHLiFAtQn3I48dTgSmRyYAUm2oxCTjFDr5R1Y 8B621yq0iaR4I/cW7PV+Ot9STO7WUQEtiMEoRdxdCxyn6FN85o2QbDCiIxnoeBaAao56 sggA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=aZX328bE; 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 n27-20020a634d5b000000b00463e9f26c48si16265696pgl.177.2022.11.08.22.07.28; Tue, 08 Nov 2022 22:07:45 -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=aZX328bE; 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 S229447AbiKIF5L (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Wed, 9 Nov 2022 00:57:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbiKIF5J (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 9 Nov 2022 00:57:09 -0500 Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3015E1EEFE for <linux-kernel@vger.kernel.org>; Tue, 8 Nov 2022 21:57:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1667973417; bh=q5LxJ2lKJ6N/n72Brdpysb7xQ8lsJn/yyuOCTpd/wjI=; h=X-EA-Auth:Date:From:To:Subject:Message-ID:MIME-Version: Content-Type; b=aZX328bEJ7+VoD3Qbz3zEa4BvMAeWz4Xa8c/Rxf0FMWW9fOi4nrTPMWV+J2Fg7iRN BpEHKBjCHuBulj02AQxHFLla41eE0xqx6rM9+4G5kYmFzNVvzEhv8DOssetRavkKFQ l0NBsbU6hXFUsjRM1JOTpkpVBjEWU+XSr+6gbPYU= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via ip-206.mailobj.net [213.182.55.206] Wed, 9 Nov 2022 06:56:57 +0100 (CET) X-EA-Auth: YV79CcZLIeAn9jjsZtRh2oSpwDk5kRO9LG7IYES5/OgiMa4wOBUW99yiN6t5mz0/kjEs5sY2H4luHN189iul5p2wYX63Iouf Date: Wed, 9 Nov 2022 11:26:52 +0530 From: Deepak R Varma <drv@mailo.com> To: outreachy@lists.linux.dev, Sven Van Asbroeck <TheSven73@gmail.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2] staging: fieldbus: replace snprintf in show functions with sysfs_emit Message-ID: <Y2tBJFSsyUzdb+eO@qemulion> 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?1748997574367717313?= X-GMAIL-MSGID: =?utf-8?q?1748997574367717313?= |
Series |
[v2] staging: fieldbus: replace snprintf in show functions with sysfs_emit
|
|
Commit Message
Deepak R Varma
Nov. 9, 2022, 5:56 a.m. UTC
The show() methods should only use sysfs_emit() when formatting values
to be returned to the user space.
Ref: Documentation/filesystems/sysfs.rst
Issue identified by coccicheck.
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
Changes in v2:
1. Switch to using sysfs_emit instead of scnprintf
2. Update patch subject and log accordingly
Feedback from gregkh@linuxfoundation.org
drivers/staging/fieldbus/dev_core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
--
2.34.1
Comments
On Wed, Nov 09, 2022 at 11:26:52AM +0530, Deepak R Varma wrote: > The show() methods should only use sysfs_emit() when formatting values > to be returned to the user space. > Ref: Documentation/filesystems/sysfs.rst > Issue identified by coccicheck. > > Signed-off-by: Deepak R Varma <drv@mailo.com> > --- > > Changes in v2: > 1. Switch to using sysfs_emit instead of scnprintf > 2. Update patch subject and log accordingly > Feedback from gregkh@linuxfoundation.org > > > drivers/staging/fieldbus/dev_core.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/staging/fieldbus/dev_core.c b/drivers/staging/fieldbus/dev_core.c > index 5aab734606ea..d32599f4eb44 100644 > --- a/drivers/staging/fieldbus/dev_core.c > +++ b/drivers/staging/fieldbus/dev_core.c > @@ -67,10 +67,10 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr, > struct fieldbus_dev *fb = dev_get_drvdata(dev); > > /* > - * card_name was provided by child driver, could potentially be long. > - * protect against buffer overrun. > + * sysfs provides PAGE_SIZE long buffer to take care of potentially No need to ever mention PAGE_SIZE at all, this comment should just be: /* card_name was provided by child driver */ But the larger question is, why did you only convert one of the sysfs show functions in this file? Why not do them all? thanks, greg k-h
On Wed, Nov 09, 2022 at 08:30:26AM +0100, Greg Kroah-Hartman wrote: > On Wed, Nov 09, 2022 at 11:26:52AM +0530, Deepak R Varma wrote: > > The show() methods should only use sysfs_emit() when formatting values > > to be returned to the user space. > > Ref: Documentation/filesystems/sysfs.rst > > Issue identified by coccicheck. > > > > Signed-off-by: Deepak R Varma <drv@mailo.com> > > /* > > - * card_name was provided by child driver, could potentially be long. > > - * protect against buffer overrun. > > + * sysfs provides PAGE_SIZE long buffer to take care of potentially > > No need to ever mention PAGE_SIZE at all, this comment should just be: > /* card_name was provided by child driver */ Sure. I will update the comment in the revision. > > But the larger question is, why did you only convert one of the sysfs > show functions in this file? Why not do them all? I was limiting it to what is reported by coccicheck. I will review other such show functions and send a consolidated patch. Thank you, ./drv > > thanks, > > greg k-h >
diff --git a/drivers/staging/fieldbus/dev_core.c b/drivers/staging/fieldbus/dev_core.c index 5aab734606ea..d32599f4eb44 100644 --- a/drivers/staging/fieldbus/dev_core.c +++ b/drivers/staging/fieldbus/dev_core.c @@ -67,10 +67,10 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr, struct fieldbus_dev *fb = dev_get_drvdata(dev); /* - * card_name was provided by child driver, could potentially be long. - * protect against buffer overrun. + * sysfs provides PAGE_SIZE long buffer to take care of potentially + * long card_name provided by child driver. */ - return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name); + return sysfs_emit(buf, "%s\n", fb->card_name); } static DEVICE_ATTR_RO(card_name);