Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp721899pxa; Thu, 27 Aug 2020 14:03:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXWanpxZ8XGm1aYvxWELU+y3bjRxwbXmB3xzvBIFgcpu3ijaYu2mwF880YWA6zVSRT0z9R X-Received: by 2002:a17:906:f957:: with SMTP id ld23mr21592824ejb.187.1598562210954; Thu, 27 Aug 2020 14:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598562210; cv=none; d=google.com; s=arc-20160816; b=BMSDZbQKiX13Yz+6of1fcFuHyWF3SN2eEkT81nqxzhNanpsz9wcYis5Oo7N6IVADYj MsvloDnpU3QxQxwFJfQv9g6xRHiznDrtg2SRRobb8tg0IUKgjvoSYnWFPRzLJivB909a P70zgNKl7jK1wyuGIaCg/w+TwYlnQgmk/B94b+Kyc17u0QXD0pixB4PzDxOE39IofoV3 G2pQg31+9RKaTnoQHnnVcCPe9b6PBy5Zilk6rbZ5ZRpiO0tmWsSyaSLJWks0/H1m10vO oUAx6qZf+D8m1sRoejAIN/Rqiyl8QSDbo/hcgaeakxBqyPrrO8vmWAPGSp2I9C2rqzKx y22w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:subject:autocrypt:from:references:cc:to; bh=KxNcRg+6YklAZRX3UfhSSAfkYXt8ik61k8vNbfFaB8M=; b=nrDaeQXAFreihX2fmJ1UJRfo4Bw6uTUzlRA7c0DCX2hfPZQsWzVf4KklpiZbXoOqOJ UBoRNke1fuVZt0J5ovUbMd13Y2xCy8eqLLjzhi3dMrAa6i8GO1SJ47rQUI96Xfy5sCy6 VVF2fegJPV9jG0kiSnxq3vaW0hg67Al8V8DUxv5R6mlC2bQKa+rP9DEtIRqSnSj4EEP+ p+EVQ7cJxFOchHYQfWTsGtK9rPiVAR1LE+XpUALn6WkO2E+Dfb5VAARApX74dDFnXFvz tRTlPAczAYxT8sYqSxN7bI3OqHiPU9yaf9qoJANF77max6NSQeqUiGm0CLmx3a0n+W51 vlDA== 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 s22si2097539ejj.630.2020.08.27.14.03.08; Thu, 27 Aug 2020 14:03:30 -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 S1727115AbgH0VBl (ORCPT + 99 others); Thu, 27 Aug 2020 17:01:41 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:41417 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbgH0VBk (ORCPT ); Thu, 27 Aug 2020 17:01:40 -0400 Received: by mail-lj1-f194.google.com with SMTP id f26so7983530ljc.8; Thu, 27 Aug 2020 14:01:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=KxNcRg+6YklAZRX3UfhSSAfkYXt8ik61k8vNbfFaB8M=; b=pJmaR9xi2RE4Q3T53prCvIH446W1JbkyAYOZ0ZHzNqGm3n5a+u5AkrODoI1xvcucls daPh/uPOwMJHFh7EbF8mIQkjNGztnjH80ySFS58qgeER8CTkRUWtOXEeOqPIudGM0a3e Q+jt8XJcInAIJT4kEJqYFVvk39pwzYqXfxsfyG4fjjnm25ngXvAuzpTddvVui0Dlln21 LUf2rgjJfy31xpLOipYi6+h4mjndOZW1ajVDMJTdcl8unAbIeZr/cxpaBcsqY3/tjPKt G1GCeWdXQN1Wl4RnugLovh2CaUxbmKP0pzF1u4bgkqQ6QYbJjY5GnHkoM1/G4ysbvny4 g4oQ== X-Gm-Message-State: AOAM531svG6AIN/EKciBSB1klteES3c6hVnojKJ2inPkG7D1jl6P+AIP KwbWZ9r8nQ09FAIO27P8GSo= X-Received: by 2002:a05:651c:513:: with SMTP id o19mr11036575ljp.379.1598562097796; Thu, 27 Aug 2020 14:01:37 -0700 (PDT) Received: from [192.168.1.8] ([213.87.147.111]) by smtp.gmail.com with ESMTPSA id x17sm717163ljm.0.2020.08.27.14.01.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Aug 2020 14:01:37 -0700 (PDT) To: Julia Lawall , Joe Perches Cc: "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 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> From: Denis Efremov Autocrypt: addr=efremov@linux.com; keydata= mQINBFsJUXwBEADDnzbOGE/X5ZdHqpK/kNmR7AY39b/rR+2Wm/VbQHV+jpGk8ZL07iOWnVe1 ZInSp3Ze+scB4ZK+y48z0YDvKUU3L85Nb31UASB2bgWIV+8tmW4kV8a2PosqIc4wp4/Qa2A/ Ip6q+bWurxOOjyJkfzt51p6Th4FTUsuoxINKRMjHrs/0y5oEc7W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dBGd9WZIid10FCoI30QXA82SHmxWe0Xy7h r4bbZobDPc7GbTHeDIYmUF24jI15NZ/Xy9ADAL0TpEg3fNVad2eslhCwiQViWfKOGOLLMe7v zod9dwxYdGXnNRlW+YOCdFNVPMvPDr08zgzXaZ2+QJjp44HSyzxgONmHAroFcqCFUlfAqUDO T30gV5bQ8BHqvfWyEhJT+CS3JJyP8BmmSgPa0Adlp6Do+pRsOO1YNNO78SYABhMi3fEa7X37 WxL31TrNCPnIauTgZtf/KCFQJpKaakC3ffEkPhyTjEl7oOE9xccNjccZraadi+2uHV0ULA1m ycHhb817A03n1I00QwLf2wOkckdqTqRbFFI/ik69hF9hemK/BmAHpShI+z1JsYT9cSs8D7wb aF/jQVy4URensgAPkgXsRiboqOj/rTz9F5mpd/gPU/IOUPFEMoo4TInt/+dEVECHioU3RRrW EahrGMfRngbdp/mKs9aBR56ECMfFFUPyI3VJsNbgpcIJjV/0N+JdJKQpJ/4uQ2zNm0wH/RU8 CRJvEwtKemX6fp/zLI36Gvz8zJIjSBIEqCb7vdgvWarksrhmi6/Jay5zRZ03+k6YwiqgX8t7 ANwvYa1h1dQ36OiTqm1cIxRCGl4wrypOVGx3OjCar7sBLD+NkwO4RaqFvdv0xuuy4x01VnOF Subject: Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs Message-ID: <5853c58e-7d26-2cf9-6cbf-698ecd93cbf9@linux.com> Date: Fri, 28 Aug 2020 00:01:34 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, ...) 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. Thanks, Denis