From: Joe Perches <joe@perches.com>
To: Brian Norris <briannorris@chromium.org>,
Andy Whitcroft <apw@canonical.com>
Cc: linux-kernel@vger.kernel.org,
Dwaipayan Ray <dwaipayanray1@gmail.com>,
Lukas Bulwahn <lukas.bulwahn@gmail.com>
Subject: Re: [PATCH v3] checkpatch: Check for missing sentinels in ID arrays
Date: Wed, 02 Jul 2025 02:19:45 -0700 [thread overview]
Message-ID: <f543013af300995880a3370bbbeef15a5669345d.camel@perches.com> (raw)
In-Reply-To: <20250701183537.501225-1-briannorris@chromium.org>
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*\{/
next prev parent reply other threads:[~2025-07-02 9:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 18:34 Brian Norris
2025-07-02 9:19 ` Joe Perches [this message]
2025-07-02 22:12 ` Brian Norris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f543013af300995880a3370bbbeef15a5669345d.camel@perches.com \
--to=joe@perches.com \
--cc=apw@canonical.com \
--cc=briannorris@chromium.org \
--cc=dwaipayanray1@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®