public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RFC: kernel coding style: prefer array to &array[0] ?
@ 2015-06-30 17:35 Joe Perches
  2015-07-01  6:10 ` Julia Lawall
  2015-07-01 11:54 ` Clemens Ladisch
  0 siblings, 2 replies; 9+ messages in thread
From: Joe Perches @ 2015-06-30 17:35 UTC (permalink / raw)
  To: LKML; +Cc: Dan Carpenter, Julia Lawall, Andrew Morton

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",



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-07-05 21:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-30 17:35 RFC: kernel coding style: prefer array to &array[0] ? Joe Perches
2015-07-01  6:10 ` Julia Lawall
2015-07-01 11:54 ` Clemens Ladisch
2015-07-01 12:15   ` Dan Carpenter
2015-07-01 12:26     ` Julia Lawall
2015-07-01 14:53       ` Joe Perches
2015-07-01 22:33         ` Dmitry Torokhov
2015-07-01 23:04           ` Joe Perches
2015-07-05 21:28         ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox