[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f543013af300995880a3370bbbeef15a5669345d.camel@perches.com>
Date: Wed, 02 Jul 2025 02:19:45 -0700
From: Joe Perches <joe@...ches.com>
To: Brian Norris <briannorris@...omium.org>, Andy Whitcroft
<apw@...onical.com>
Cc: linux-kernel@...r.kernel.org, Dwaipayan Ray <dwaipayanray1@...il.com>,
Lukas Bulwahn <lukas.bulwahn@...il.com>
Subject: Re: [PATCH v3] checkpatch: Check for missing sentinels in ID arrays
On Tue, 2025-07-01 at 11:34 -0700, Brian Norris wrote:
> All of the ID tables based on <linux/mod_devicetable.h> (of_device_id,
> pci_device_id, ...) require their arrays to end in an empty sentinel
> value. That's usually spelled with an empty initializer entry (e.g.,
> "{}"), but also sometimes with explicit 0 entries, field initializers
> (e.g., '.id = ""'), or even a macro entry (like PCMCIA_DEVICE_NULL).
>
> Without a sentinel, device-matching code may read out of bounds.
>
> I've found a number of such bugs in driver reviews, and we even
> occasionally commit one to the tree. See commit 5751eee5c620 ("i2c:
> nomadik: Add missing sentinel to match table") for example.
>
> Teach checkpatch to find these ID tables, and complain if it looks like
> there wasn't a sentinel value.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -685,6 +685,64 @@ our $tracing_logging_tags = qr{(?xi:
> [\.\!:\s]*
> )};
>
> +# Device ID types from include/linux/mod_devicetable.h.
> +our $dev_id_types = qr{(?x:
[ a long list ...]
> +)_device_id};
This list seems unmaintainable.
Does something like '\b[a-z]\w*_device_id\b'
match too many other non-sentinal uses?
$ git grep -P -o -h '\b\w+_device_id\b' -- '*.[ch]' | sort | uniq | wc -l
288
> @@ -7678,6 +7736,30 @@ sub process {
[]
> +# Check that *_device_id tables have sentinel entries.
> + if (defined $stat && $line =~ /struct $dev_id_types .*\[\] = \{/) {
Spacing isn't guaranteed so perhaps
$line =~ /struct\s+$dev_id_types\s+\w+\s*\[\s*\]\s*=\s*\{/
Powered by blists - more mailing lists