Message ID | Y2K2MD7+WBu4QouU@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 l7csp68294wru; Wed, 2 Nov 2022 11:28:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6KAfUsCAlZOaPgCv6TfkiVWFlf6eA/YG7SOqYO7LiDt01ZHeut5i/eesEBmZPU80PPNhvE X-Received: by 2002:a62:4c6:0:b0:55f:c739:51e0 with SMTP id 189-20020a6204c6000000b0055fc73951e0mr25987438pfe.49.1667413737766; Wed, 02 Nov 2022 11:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667413737; cv=none; d=google.com; s=arc-20160816; b=pwaboJJ/0bMSMloRgu86q4dZBeIe0AZOcye3ic3gWQGPRImt/kz1VT1btXDQLsynPh aUCPoeKVDXGJEeUjyueYQAlEJGVZMu/keb56jDBD7D0Jvj+ocpO2t+iLcCOzpevMNY88 td2vtvlgrPtJZkYfcQ84OiwIi3/Oq5DCPqdQJOxu2AY7vmXPhzkRSvfJnBzqpwSQ5k4a WLkvtDcbDNZqeYE5mtZNNKcksNRa+jUldo99eB2FhsX4BIvnMEQxX30+JOVfI+VZZnwG Xo5Z8MhGhOmJCSpFdIrdh1a3tEMPmRBP96ubqo0TWETZPJDWjuGYVT/yDeUErFPkRiZe NagA== 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=RKteODWc7nJHlNwKsu6YNy2k134L6hBOhFHLILam23s=; b=0cYHzrks7tvDhO197Y+1ixp0xcXk9O8MY6TabYBbYP4DVeHnX4+GFqlWvZRd8cD49y GWrXBwl+ua6IAbfjijEMfvMCZK1ZjQz2IAZnieyF/aesGOwxHDXci3RG9Rps78QTXe66 Z3wOg//pdFoR8hzR5UL+HLJNsvLUyC1FJ2wngzthSZPBL7T/TieVeqbUuhNMBROKtxkB jveIksCykVlUuthaGKC1b1Ehy94tNFljbS9wAnUmjcDJyVPXr8DvIeAeTL99C3QKJxPM DLcnXNDnPDStAqScgwqM2yk+se3fahIPBJ6t7ZrxkPeUdymfHUPSIanS0j4p9BVCpVxi 7k7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=VHo226tc; 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 u133-20020a62798b000000b0056c882d7065si15004578pfc.179.2022.11.02.11.28.44; Wed, 02 Nov 2022 11:28:57 -0700 (PDT) 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=VHo226tc; 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 S230341AbiKBS0S (ORCPT <rfc822;yves.mi.zy@gmail.com> + 99 others); Wed, 2 Nov 2022 14:26:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231205AbiKBS0K (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 2 Nov 2022 14:26:10 -0400 Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDFE521820 for <linux-kernel@vger.kernel.org>; Wed, 2 Nov 2022 11:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1667413556; bh=3rsRCttLKAT5Ls6ZOU7vfsBpZ4yDty9OCgC/PPt1JXE=; h=X-EA-Auth:Date:From:To:Subject:Message-ID:MIME-Version: Content-Type; b=VHo226tcGq6UkmmWik3FzNW7FW9WJbOzLQlCk+VAlngP8Tp64JJ/2aRF5H2+92d0c 3NfJCVoiHE1iinESUU0q9/f3HcypAD0ZcinH7TFqLvgbiC3XK+VNySHBO8uCPCWXzv gReUxirIfkWPIkSNGWmXHEAhksERW8UqilzYzVGk= Received: by b-6.in.mailobj.net [192.168.90.16] with ESMTP via [213.182.55.206] Wed, 2 Nov 2022 19:25:56 +0100 (CET) X-EA-Auth: 7Y3vbvCxeKCXYF2dtoftR5y3E0Kq3g1f7d/kmFDKtPxssrWWzjpYDtCX9eq9wTBkViFvAUaJC4feBDOKJPlqNt2PoPHZRaRK Date: Wed, 2 Nov 2022 23:55: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] staging: fieldbus: convert snprintf to scnprintf Message-ID: <Y2K2MD7+WBu4QouU@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?1748410027243542746?= X-GMAIL-MSGID: =?utf-8?q?1748410027243542746?= |
Series |
staging: fieldbus: convert snprintf to scnprintf
|
|
Commit Message
Deepak R Varma
Nov. 2, 2022, 6:25 p.m. UTC
It is recommended to use scnprintf instead of snprintf to accurately
return the size of the encoded data. Following article [1] has details
on the reason for this kernel level migration. This issue was identified
using coccicheck.
[1] https://lwn.net/Articles/69419/
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
drivers/staging/fieldbus/dev_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.34.1
Comments
On Wed, Nov 02, 2022 at 11:55:52PM +0530, Deepak R Varma wrote: > It is recommended to use scnprintf instead of snprintf to accurately > return the size of the encoded data. Following article [1] has details > on the reason for this kernel level migration. This issue was identified > using coccicheck. > > [1] https://lwn.net/Articles/69419/ > > Signed-off-by: Deepak R Varma <drv@mailo.com> > --- > drivers/staging/fieldbus/dev_core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/staging/fieldbus/dev_core.c b/drivers/staging/fieldbus/dev_core.c > index 5aab734606ea..d51f2b02d5e6 100644 > --- a/drivers/staging/fieldbus/dev_core.c > +++ b/drivers/staging/fieldbus/dev_core.c > @@ -70,7 +70,7 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr, > * card_name was provided by child driver, could potentially be long. > * protect against buffer overrun. > */ > - return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name); > + return scnprintf(buf, PAGE_SIZE, "%s\n", fb->card_name); No, neither of these are correct. Please use sysfs_emit() for sysfs show callbacks. thanks, greg k-h
On Tue, Nov 08, 2022 at 04:13:12PM +0100, Greg Kroah-Hartman wrote: > On Wed, Nov 02, 2022 at 11:55:52PM +0530, Deepak R Varma wrote: > > It is recommended to use scnprintf instead of snprintf to accurately > > return the size of the encoded data. Following article [1] has details > > on the reason for this kernel level migration. This issue was identified > > using coccicheck. > > > > [1] https://lwn.net/Articles/69419/ > > > > Signed-off-by: Deepak R Varma <drv@mailo.com> > > --- > > drivers/staging/fieldbus/dev_core.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/staging/fieldbus/dev_core.c b/drivers/staging/fieldbus/dev_core.c > > index 5aab734606ea..d51f2b02d5e6 100644 > > --- a/drivers/staging/fieldbus/dev_core.c > > +++ b/drivers/staging/fieldbus/dev_core.c > > @@ -70,7 +70,7 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr, > > * card_name was provided by child driver, could potentially be long. > > * protect against buffer overrun. > > */ > > - return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name); > > + return scnprintf(buf, PAGE_SIZE, "%s\n", fb->card_name); > > No, neither of these are correct. > > Please use sysfs_emit() for sysfs show callbacks. Hello Greg, Thank you. I corrected and resubmitted the patch as suggested. Hi Julia, The device_attr_show.cocci file should have made the recommendation to use the sysfs_emit(), however, in this case it instead suggested to use scnprintf. Is it because the method name was not "show" but "xxx_show"? 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..d51f2b02d5e6 100644 --- a/drivers/staging/fieldbus/dev_core.c +++ b/drivers/staging/fieldbus/dev_core.c @@ -70,7 +70,7 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr, * card_name was provided by child driver, could potentially be long. * protect against buffer overrun. */ - return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name); + return scnprintf(buf, PAGE_SIZE, "%s\n", fb->card_name); } static DEVICE_ATTR_RO(card_name);