lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 30 Jun 2015 10:35:46 -0700
From:	Joe Perches <joe@...ches.com>
To:	LKML <linux-kernel@...r.kernel.org>
Cc:	Dan Carpenter <dan.carpenter@...cle.com>,
	Julia Lawall <julia.lawall@...6.fr>,
	Andrew Morton <akpm@...ux-foundation.org>
Subject: RFC: kernel coding style: prefer array to &array[0] ?

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


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ