Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753111AbdICPgG (ORCPT ); Sun, 3 Sep 2017 11:36:06 -0400 Received: from smtprelay0227.hostedemail.com ([216.40.44.227]:44108 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753053AbdICPgF (ORCPT ); Sun, 3 Sep 2017 11:36:05 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::,RULES_HIT:41:355:379:541:599:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1381:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3352:3622:3865:3866:3868:3871:3872:3874:4321:5007:7904:8527:10004:10400:10848:11026:11232:11657:11658:11783:11914:12043:12296:12438:12555:12679:12740:12895:12986:13069:13132:13161:13229:13231:13311:13357:13439:13894:14180:14659:14721:21080:21324:21627:30029:30054:30069:30070: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:9,LUA_SUMMARY:none X-HE-Tag: sand92_8c4a6419ab761 X-Filterd-Recvd-Size: 2056 Message-ID: <1504452962.18971.1.camel@perches.com> Subject: Re: [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7 From: Joe Perches To: Thomas Meyer , linux-kernel@vger.kernel.org Date: Sun, 03 Sep 2017 08:36:02 -0700 In-Reply-To: <1504439110050-939061377-0-diffsplit-thomas@m3y3r.de> References: <1504439110050-939061377-0-diffsplit-thomas@m3y3r.de> 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: 1305 Lines: 37 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. 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. It seems none of those styles exist though.