From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753460AbbGAXEV (ORCPT ); Wed, 1 Jul 2015 19:04:21 -0400 Received: from smtprelay0222.hostedemail.com ([216.40.44.222]:35149 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753349AbbGAXER (ORCPT ); Wed, 1 Jul 2015 19:04:17 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::,RULES_HIT:41:355:379:541:599:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:1801:2110:2393:2553:2559:2562:2693:2828:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:4250:4321:4605:5007:6261:8957:10004:10400:10848:11026:11232:11473:11658:11914:12043:12438:12517:12519:12740:13161:13229:13618: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: glass46_7c6014a348b38 X-Filterd-Recvd-Size: 3234 Message-ID: <1435791853.12101.131.camel@perches.com> Subject: Re: RFC: kernel coding style: prefer array to &array[0] ? From: Joe Perches To: Dmitry Torokhov Cc: Julia Lawall , Dan Carpenter , Clemens Ladisch , LKML , Andrew Morton , Liam Girdwood , Mark Brown Date: Wed, 01 Jul 2015 16:04:13 -0700 In-Reply-To: <20150701223311.GE36579@dtor-ws> References: <1435685746.12101.18.camel@perches.com> <5593D4F5.1090106@ladisch.de> <20150701121524.GA30834@mwanda> <1435762424.12101.95.camel@perches.com> <20150701223311.GE36579@dtor-ws> 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 On Wed, 2015-07-01 at 15:33 -0700, Dmitry Torokhov wrote: > On Wed, Jul 01, 2015 at 07:53:44AM -0700, Joe Perches wrote: > > On Wed, 2015-07-01 at 14:26 +0200, Julia Lawall wrote: > > > On Wed, 1 Jul 2015, Dan Carpenter wrote: > > > > On Wed, Jul 01, 2015 at 01:54:29PM +0200, Clemens Ladisch wrote: > > > > > 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]); > > > > > > > > > > I use '&array[0]' when I want to get a pointer to a single object that > > > > > happens to be the first one in an array. > > > > > > > > Yeah. Of course, you're right. Otherwise it ends up confusing static > > > > checkers if you want the first element or the whole array. > > > > Right. > > > > > > > > Should this preference be put into checkpatch and/or CodingStyle? > > > > And checkpatch will have no idea what the prototype > > for any function is, so this transform is better left > > for smarter tools like coccinelle. > > > > The proper answer here is no. [] > CHECK: Using addressof array 'mtouch->data' index [0] may be simpler as > 'mtouch->data' > #97: FILE: drivers/input/touchscreen/mtouch.c:97: > + if (MTOUCH_FORMAT_TABLET_STATUS_BIT & mtouch->data[0]) The joys of perl parsing. > CHECK: Using addressof array 'msg' index [0] may be simpler as 'msg' > #38: FILE: drivers/input/touchscreen/ipaq-micro-ts.c:38: > + be16_to_cpup((__be16 *) &msg[0])); That's using the first member in an array. > I'd be OK with changing cases like: > > CHECK: Using addressof array 'buf' index [0] may be simpler as 'buf' > #232: FILE: drivers/input/touchscreen/zforce_ts.c:232: > + return zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf)); I think cases like those are sensible to change. cheers, Joe