Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752412AbbGAGKY (ORCPT ); Wed, 1 Jul 2015 02:10:24 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:30349 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751276AbbGAGKW (ORCPT ); Wed, 1 Jul 2015 02:10:22 -0400 X-IronPort-AV: E=Sophos;i="5.15,383,1432591200"; d="scan'208";a="168214259" Date: Wed, 1 Jul 2015 08:10:19 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@localhost6.localdomain6 To: Joe Perches cc: LKML , Dan Carpenter , Andrew Morton Subject: Re: RFC: kernel coding style: prefer array to &array[0] ? In-Reply-To: <1435685746.12101.18.camel@perches.com> Message-ID: References: <1435685746.12101.18.camel@perches.com> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1432 Lines: 48 On Tue, 30 Jun 2015, Joe Perches wrote: > It seems most in-kernel uses are 'array' rather than '&array[0]' > > Most of the time, using array is simpler to read than &array[0]. > > Exceptions exists when addresses for consecutive members are > used like func(&array[0], &array[1]); > > Should this preference be put into checkpatch and/or CodingStyle? &array[0] looks complicated to me. julia > Here's a possible checkpatch --strict addition > --- > scripts/checkpatch.pl | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 90e1edc..362a9d8 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -5492,6 +5492,12 @@ sub process { > } > } > > +# check for address of array[0] (not '&& array[0]' or &array[0].member) > + if ($sline =~ /[^\&]&\s*($Ident\s*(?:(?:\-\>|\.)\s*$Ident\s*)*)\s*\[\s*0\s*\]\s*(?!\[|\.|\-\>)/) { > + CHK("ADDRESSOF_ARRAY", > + "Using addressof array '$1' index [0] may be simpler as '$1'\n" . $herecurr); > + } > + > # check for semaphores initialized locked > if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) { > WARN("CONSIDER_COMPLETION", > > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/