Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp758245pxa; Thu, 27 Aug 2020 15:13:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPzrAENzVBq/Gl5PcjJ7SOY4CrskamcNUvsvCyqSYiBKaoXHb2V+YkwNXQXq6p2BRLd/Ey X-Received: by 2002:a17:907:40bf:: with SMTP id nu23mr20693481ejb.47.1598566408392; Thu, 27 Aug 2020 15:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598566408; cv=none; d=google.com; s=arc-20160816; b=D5bfnwSd0vQyNePg8gPeSO4urX4rED3r+10UytMmeA7mU1Mz2ernRO0wS42UKv8SzQ EFrnkHU52gcbPo2TuGhJYm2/RCPxqaEeue/elr+3ml0S0N0e5rJpwWx02p4iqCwfi5fA Lon9gKVbfIcm+PRwA2arJReoOCq015o52MaHlqnLAlqI8mYlm2OeyVVjyTpigXrZzWKG mzSll0j5uGAN/UmhIOcKpsX3VO/jAAVqO/UWWvZpd5LHZWzAiENqPxyjznSj7lvqTUAc lLPA5OvCRpm/XM2BpLOd70XjDkYf6Q6kdRSS/Uhoh4ajsm6sCodaHv8WIFUMy0ztPyk3 BRyQ== 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:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=UGgK6AErJUGzeqhN+PgRRqhldZRjv9vEgBGPOwkCAOY=; b=suwDfASX1hf1yFcr8gsvnsX5Fqmib2HvMWgZoCCQoBRWz1J89YrXXaY/ygXnoH2q95 6iK2SLobthVKndcHRwxrZAcGfBO0HuSzh4OUNW5s852XVawMd16aOCpWa4rawiQBwv+E qiiZpcBC94uxwt14lveg+EFkijYgxPJ+KdwBDL5h1IaHx+RdlstzFgzlqGhZ3eSobkcW RwN9kKj2tFBZQlK/JH71fh8kxrczZnHrcgBqgotB+27cl6X1I4ug4KVWGBWx4O8QApmu KvtI5x0if35th3/LbqCNvsgl2mlOmaxBQKNAupElPsPDIPXHc/tPbyy3zmVt41sO30R0 V3lQ== 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 p25si2530596edw.562.2020.08.27.15.13.05; Thu, 27 Aug 2020 15:13:28 -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 S1727846AbgH0WMC (ORCPT + 99 others); Thu, 27 Aug 2020 18:12:02 -0400 Received: from smtprelay0213.hostedemail.com ([216.40.44.213]:35818 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726256AbgH0WMC (ORCPT ); Thu, 27 Aug 2020 18:12:02 -0400 Received: from smtprelay.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by smtpgrave06.hostedemail.com (Postfix) with ESMTP id 854B78123E2F; Thu, 27 Aug 2020 22:12:01 +0000 (UTC) Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay08.hostedemail.com (Postfix) with ESMTP id 74415182CED34; Thu, 27 Aug 2020 22:12:00 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:355:379:599:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:1801:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3352:3622:3865:3866:3867:3868:3871:3874:4321:4605:5007:7576:8531:10004:10400:10848:11026:11232:11473:11658:11914:12043:12296:12297:12740:12760:12895:13069:13311:13357:13439:14096:14097:14659:14721:21080:21324:21627:21990:30029:30054:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: fly24_1910e5127070 X-Filterd-Recvd-Size: 2747 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf16.hostedemail.com (Postfix) with ESMTPA; Thu, 27 Aug 2020 22:11:58 +0000 (UTC) Message-ID: Subject: Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs From: Joe Perches To: David Laight , Julia Lawall Cc: Alex Dewar , Rasmus Villemoes , cocci , Kees Cook , Greg Kroah-Hartman , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Gustavo A. R. Silva" , "accessrunner-general@lists.sourceforge.net" Date: Thu, 27 Aug 2020 15:11:57 -0700 In-Reply-To: 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> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.36.4-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2020-08-27 at 22:03 +0000, David Laight wrote: > From: Joe Perches > > Sent: 27 August 2020 21:30 > ... > > Perhaps what's necessary is to find any > > appropriate .show function and change > > any use of strcpy/sprintf within those > > function to some other name. > > > > For instance: > > > > drivers/isdn/mISDN/core.c-static ssize_t name_show(struct device *dev, > > drivers/isdn/mISDN/core.c- struct device_attribute *attr, char *buf) > > drivers/isdn/mISDN/core.c-{ > > drivers/isdn/mISDN/core.c: strcpy(buf, dev_name(dev)); > > drivers/isdn/mISDN/core.c- return strlen(buf); > > drivers/isdn/mISDN/core.c-} > > drivers/isdn/mISDN/core.c-static DEVICE_ATTR_RO(name); > > That form ends up calculating the string length twice. > Better would be: > len = strlen(msg); > memcpy(buf, msg, len); > return len; or given clang's requirement for stpcpy return stpcpy(buf, dev_name(dev)) - buf; (I do not advocate for this ;)