[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <a56a858531e86a456c3a6c213c9f562add517d83.camel@gmail.com>
Date: Thu, 23 Oct 2025 20:44:23 +0530
From: ally heev <allyheev@...il.com>
To: Joe Perches <joe@...ches.com>, Dwaipayan Ray <dwaipayanray1@...il.com>,
Lukas Bulwahn <lukas.bulwahn@...il.com>, Jonathan Corbet <corbet@....net>,
Andy Whitcroft <apw@...onical.com>
Cc: workflows@...r.kernel.org, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, Dan Carpenter <dan.carpenter@...aro.org>,
David Hunter <david.hunter.linux@...il.com>, Shuah Khan
<skhan@...uxfoundation.org>, Viresh Kumar <vireshk@...nel.org>, Nishanth
Menon <nm@...com>, Stephen Boyd <sboyd@...nel.org>, linux-pm
<linux-pm@...r.kernel.org>, dan.j.williams@...el.com
Subject: Re: [PATCH] checkpatch: add uninitialized pointer with __free
attribute check
On Tue, 2025-10-21 at 10:06 -0700, Joe Perches wrote:
> On Tue, 2025-10-21 at 17:00 +0530, Ally Heev wrote:
> > uninitialized pointers with __free attribute can cause undefined
> > behaviour as the memory allocated to the pointer is freed
> > automatically when the pointer goes out of scope.
> > add check in checkpatch to detect such issues
>
> Seems sensible. Couple minor points below:
>
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
> > @@ -7721,6 +7721,12 @@ sub process {
> > ERROR("MISSING_SENTINEL", "missing sentinel in ID array\n" . "$here\n$stat\n");
> > }
> > }
> > +
> > +# check for uninitialized pointers with __free attribute
> > + if ($line =~ /\s*$Type\s*($Ident)\s+__free\s*\(\s*$Ident\s*\)\s*;/) {
>
> The leading \s* isn't useful, but \b should be used.
Sure
>
> Perhaps verify that $Type is a pointer as well
>
> if ($line =~ /\b($Type)\s*($Ident)\s*__free\s*\(\s*$Ident\s*\)\s*;/ &&
> $1 =~ /\*\s*$/) {
>
> to avoid things like:
>
> drivers/net/ethernet/microsoft/mana/gdma_main.c: cpumask_var_t cpus __free(free_cpumask_var);
>
>
> > + WARN("UNINITIALIZED_PTR_WITH_FREE",
> > + "pointer '$1' with __free attribute should be initialized\n" . $herecurr);
>
> pointer '$2' etc
>
Nice find. Thanks!
> And this would not find uses like the below where another definition
> is done before a definition with __free on the same line:
>
> crypto/testmgr.c: u8 *ptr, *key __free(kfree);
I will add the check for each pointer defined on the same line
Powered by blists - more mailing lists