Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752575AbdICUUo (ORCPT ); Sun, 3 Sep 2017 16:20:44 -0400 Received: from smtprelay0234.hostedemail.com ([216.40.44.234]:36214 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751649AbdICUUm (ORCPT ); Sun, 3 Sep 2017 16:20:42 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::,RULES_HIT:41:355:379:541:599:960:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2828:3138:3139:3140:3141:3142:3354:3622:3653:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:5007:6119:6691:7875:7904:8527:10004:10400:10848:11026:11232:11657:11658:11783:11914:12043:12295:12296:12438:12555:12740:12895:12986:13132:13231:13439:13894:14180:14659:14721:21060:21080:21324:21627:30029:30054:30069: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: cover32_60579b883950 X-Filterd-Recvd-Size: 3054 Message-ID: <1504470040.18971.9.camel@perches.com> Subject: Re: [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7 From: Joe Perches To: Thomas Meyer Cc: linux-kernel@vger.kernel.org Date: Sun, 03 Sep 2017 13:20:40 -0700 In-Reply-To: <20170903194605.qh6k3fthcc6qevpn@olymp> References: <1504439110050-939061377-0-diffsplit-thomas@m3y3r.de> <1504452962.18971.1.camel@perches.com> <20170903194605.qh6k3fthcc6qevpn@olymp> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2194 Lines: 71 On Sun, 2017-09-03 at 21:59 +0200, Thomas Meyer wrote: > On Sun, Sep 03, 2017 at 08:36:02AM -0700, Joe Perches wrote: > > On Sun, 2017-09-03 at 14:19 +0200, Thomas Meyer wrote: > > > Use ARRAY_SIZE macro, rather than explicitly coding some variant of it > > > yourself. > > > > > > Found with: find -type f -name "*.c" -o -name "*.h" | xargs perl -p -i -e > > > 's/\bsizeof\s*\(\s*(\w+)\s*\)\s*\ /\s*sizeof\s*\(\s*\1\s*\[\s*0\s*\]\s*\) > > > /ARRAY_SIZE(\1)/g' and manual check/verification. > > > > Hey Thomas. > > Hi Joe, > > > > There are some instances that span multiple lines that > > the regex above misses. > > > > For instance: > > > > diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c > > index 3d701c7a4c91..26a825bd7581 100644 > > --- a/drivers/infiniband/hw/mlx5/odp.c > > +++ b/drivers/infiniband/hw/mlx5/odp.c > > @@ -929,8 +929,7 @@ static int mlx5_ib_mr_initiator_pfault_handler( > > ????????????????return -EFAULT; > > ????????} > > ? > > -???????if (unlikely(opcode >= sizeof(mlx5_ib_odp_opcode_cap) / > > -???????????sizeof(mlx5_ib_odp_opcode_cap[0]) || > > +???????if (unlikely(opcode >= ARRAY_SIZE(mlx5_ib_odp_opcode_cap) || > > > > Here is another perl command regex that fixes a few more: > > > > $ perl -i -e 'local $/; while (<>) { s/\bsizeof\s*\(\s*(\w+)\s*\)\s*\/\s*sizeof\s*\(\s*\1\s*\[\s*0\s*\]\s*\)/ARRAY_SIZE(\1)/g; print; }' $file > > > > This regex could still miss variants that > > have a comment or that don't use parentheses > > around the sizeof. > > Okay, fine, but I think this patch series is okay to go in anyway. I will > re-run with above regex after the next rcX tag. Would that be fine for you? > What do you think? I think whatever you want to do is fine with me. If you want, you could use the simple cocci script below which is _much_ better than the perl regex as it can find all the appropriate cases not just sizeof(var)/sizeof(var[0]) $ cat array_size.cocci @@ type T; T[] E; @@ ( - sizeof(E) /sizeof(*E) + ARRAY_SIZE(E) | - sizeof(E) /sizeof(E[...]) + ARRAY_SIZE(E) | - sizeof(E) /sizeof(T) + ARRAY_SIZE(E) ) $ and maybe this $ spatch --in-place --all-includes --sp-file array_size.cocci .