From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752374AbbF3Rf5 (ORCPT ); Tue, 30 Jun 2015 13:35:57 -0400 Received: from smtprelay0148.hostedemail.com ([216.40.44.148]:40496 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751643AbbF3Rfv (ORCPT ); Tue, 30 Jun 2015 13:35:51 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:355:379:541:973:982:988:989:1260:1277:1311:1313:1314:1345:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3871:3872:4321:5007:6261:8957:10004:10400:10848:11658:11914:12043:12517:12519:12555:13069:13311:13357:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: hour63_6cd285b5e6028 X-Filterd-Recvd-Size: 1793 Message-ID: <1435685746.12101.18.camel@perches.com> Subject: RFC: kernel coding style: prefer array to &array[0] ? From: Joe Perches To: LKML Cc: Dan Carpenter , Julia Lawall , Andrew Morton Date: Tue, 30 Jun 2015 10:35:46 -0700 Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.11-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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",