Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752398AbdICT7o (ORCPT ); Sun, 3 Sep 2017 15:59:44 -0400 Received: from www17.your-server.de ([213.133.104.17]:40288 "EHLO www17.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751454AbdICT7n (ORCPT ); Sun, 3 Sep 2017 15:59:43 -0400 Date: Sun, 3 Sep 2017 21:59:37 +0200 From: Thomas Meyer To: Joe Perches Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7 Message-ID: <20170903194605.qh6k3fthcc6qevpn@olymp> References: <1504439110050-939061377-0-diffsplit-thomas@m3y3r.de> <1504452962.18971.1.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1504452962.18971.1.camel@perches.com> User-Agent: NeoMutt/20170113 (1.7.2) X-Authenticated-Sender: thomas@m3y3r.de Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1620 Lines: 45 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? > > It seems none of those styles exist though. >