Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp739889pxa; Thu, 27 Aug 2020 14:37:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUK3uNFV+Klpo58e6sKFeNpp8zQIE9VWYgwxzSuz8i27FxSu/DHdlP0s0mlqCaaMgNcqW0 X-Received: by 2002:a50:da44:: with SMTP id a4mr22386065edk.36.1598564260781; Thu, 27 Aug 2020 14:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598564260; cv=none; d=google.com; s=arc-20160816; b=AP5hXMdCuHQG+Hakus7YhIEjDNFaFQGgYL6MF8wDouQ/JRQ16BkPVtuyqPPTdJaDV5 JYpHcSRt6oNHAKcpuUoLQHpBLgJAOYFWq4I5aVZMt4cJuFc36gsW7HfVTA5cLySHHUjT 0Tbnq9vtPzbsD+o7wAOoyw1lQhAyCRrZxT+WYRePVb2AKm7lLWnWmTLh91+LfxKbme8y 88q3+wVhieyRdhDDhr5njnPLugIILbIYAZhaax6c3COSuFPeTssxirxoxZcv7Vh3NDIO BCnRdJ/1VZkwUcqpK1eCBKtPJ5I1ldse08ruX2M0TyNvDlsbgBh7nA4tOmsNf2Seke5r x14Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=9mzdsOBx1iXU1qBeDnu0LRYCM1or7i8klna1zzEUPGE=; b=XrVfyyyTEm3Dpsm8SoNP7zsoBT0FVMA+bpkm6kxWwidpOLq7G0gdl4dSvIkk1KIqjA hoKVIj1pw+FPJepezvbaZezbtZ7dycAW22DZqLAfibRDi4h4+Cxk+5cAPdHy7jsQpVq5 jOnQrflsjc6IPCRZWuCeuUo95CV2wWt9h/BCXjoi14u7zCRlVspmE//4DQJSyFNcx1wr THrG3fTdEtvKNyfI5i6x0hbSJGuqiEoDegqWVCzIBeti1Rbh/XBBepPdfHMLrOKpT9Lu KiSbqgFDldO+fvjIuLxFmltD7Sc/9GxN9sdBkYw8m/E0WUvD722tCYd1svobucC0R5iu W3uw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r11si2288217edo.607.2020.08.27.14.37.17; Thu, 27 Aug 2020 14:37:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726289AbgH0Vge (ORCPT + 99 others); Thu, 27 Aug 2020 17:36:34 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:50702 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726073AbgH0Vgd (ORCPT ); Thu, 27 Aug 2020 17:36:33 -0400 X-IronPort-AV: E=Sophos;i="5.76,359,1592863200"; d="scan'208";a="357458750" Received: from abo-173-121-68.mrs.modulonet.fr (HELO hadrien) ([85.68.121.173]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2020 23:36:29 +0200 Date: Thu, 27 Aug 2020 23:36:28 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Denis Efremov cc: Julia Lawall , Joe Perches , "Gustavo A. R. Silva" , Kees Cook , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org, cocci , accessrunner-general@lists.sourceforge.net, Alex Dewar Subject: Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs In-Reply-To: <5853c58e-7d26-2cf9-6cbf-698ecd93cbf9@linux.com> Message-ID: References: <20200824222322.22962-1-alex.dewar90@gmail.com> <48f2dc90-7852-eaf1-55d7-2c85cf954688@rasmusvillemoes.dk> <20200827071537.GA168593@kroah.com> <20200827131819.7rcl2f5js3hkoqj2@lenovo-laptop> <20200827144846.yauuttjaqtxaldxg@lenovo-laptop> <5d1dfb9b031130d4d20763ec621233a19d6a88a2.camel@perches.com> <5853c58e-7d26-2cf9-6cbf-698ecd93cbf9@linux.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 28 Aug 2020, Denis Efremov wrote: > Hi all, > > On 8/27/20 10:42 PM, Julia Lawall wrote: > > > > > > On Thu, 27 Aug 2020, Joe Perches wrote: > > > >> On Thu, 2020-08-27 at 15:48 +0100, Alex Dewar wrote: > >>> On Thu, Aug 27, 2020 at 03:41:06PM +0200, Rasmus Villemoes wrote: > >>>> On 27/08/2020 15.18, Alex Dewar wrote: > >>>>> On Thu, Aug 27, 2020 at 09:15:37AM +0200, Greg Kroah-Hartman wrote: > >>>>>> On Thu, Aug 27, 2020 at 08:42:06AM +0200, Rasmus Villemoes wrote: > >>>>>>> On 25/08/2020 00.23, Alex Dewar wrote: > >>>>>>>> kernel/cpu.c: don't use snprintf() for sysfs attrs > >>>>>>>> > >>>>>>>> As per the documentation (Documentation/filesystems/sysfs.rst), > >>>>>>>> snprintf() should not be used for formatting values returned by sysfs. > > Just FYI, I've send an addition to the device_attr_show.cocci script[1] to turn > simple cases of snprintf (e.g. "%i") to sprintf. Looks like many developers would > like it more than changing snprintf to scnprintf. As for me, I don't like the idea > of automated altering of the original logic from bounded snprint to unbouded one > with sprintf. > > [1] https://lkml.org/lkml/2020/8/13/786 > > Regarding current device_attr_show.cocci implementation, it detects the functions > by declaration: > ssize_t any_name(struct device *dev, struct device_attribute *attr, char *buf) > > and I limited the check to: > "return snprintf" > pattern because there are already too many warnings. > > Actually, it looks more correct to check for: > ssize_t show(struct device *dev, struct device_attribute *attr, char *buf) > { > <... > * snprintf@p(...); > ...> > } > > This pattern should also highlight the snprintf calls there we save returned > value in a var, e.g.: > > ret += snprintf(...); > ... > ret += snprintf(...); > ... > ret += snprintf(...); > > return ret; > > > > > Something like > > > > identifier f; > > fresh identifier = "sysfs" ## f; > > > > may be useful. Let me know if further help is needed. > > Initially, I wrote the rule to search for DEVICE_ATTR(..., ..., func_name, ...) This is what I would have expected. > functions. However, it looks like matching function prototype is enough. At least, > I failed to find false positives. I rejected the initial DEVICE_ATTR() searching > because I thought that it's impossible to handle DEVICE_ATTR_RO()/DEVICE_ATTR_RW() > macroses with coccinelle as they "generate" function names internally with > "##". "fresh identifier" should really help here, but now I doubt it's required in > device_attr_show.cocci, function prototype is enough. It's true that it is probably unique enough. julia