[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <uzfke2ry3rhdirqpdb2bdjkoemj4rgtfwsio7yf5la7p3p2ait@6umacnfdeto2>
Date: Fri, 22 Aug 2025 01:57:05 +0300
From: "Nikola Z. Ivanov" <zlatistiv@...il.com>
To: Mark Brown <broonie@...nel.org>
Cc: perex@...ex.cz, tiwai@...e.com, shuah@...nel.org,
linux-sound@...r.kernel.org, linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kernel-mentees@...ts.linuxfoundation.org
Subject: Re: [PATCH] selftests/alsa: remove 0/NULL global variable assignment
On Thu, Aug 21, 2025 at 10:30:50PM +0100, Mark Brown wrote:
> On Fri, Aug 22, 2025 at 12:17:14AM +0300, Nikola Ivanov wrote:
> > On Thu, Aug 21, 2025 at 09:49:29PM +0100, Mark Brown wrote:
>
> > > > -int num_cards = 0;
> > > > -int num_controls = 0;
> > > > -struct card_data *card_list = NULL;
> > > > -struct ctl_data *ctl_list = NULL;
> > > > +int num_cards;
> > > > +int num_controls;
> > > > +struct card_data *card_list;
> > > > +struct ctl_data *ctl_list;
>
> > > Nothing now sets initial values for these variables so they all have
> > > undefined values which is buggy. The code is relying on the default
> > > values.
>
> > Checkpatch reports it as an error, it looks to be part of the C
> > standard that all compilers must initialize globals to 0.
> > Though I suppose it helps with readability to see
> > the num_ counters assigned 0.
>
> Do you have a reference there, note that these are just plain non-static
> variables? I wouldn't trust checkpatch for anything that isn't kernel
> code (and even there it's got issues).
This is what it says in the C99/C11/C18/C23 drafts I found:
> If an object that has automatic storage duration is not initialized explicitly, its value is
> indeterminate. If an object that has static or thread storage duration is not initialized
> explicitly, then:
> — if it has pointer type, it is initialized to a null pointer;
> — if it has arithmetic type, it is initialized to (positive or unsigned) zero;
"static or thread storage" referring to variables declared at global scope
(regardless of static keyword) as well as those inside function scope defined
with static keyword.
Since as you said checkpatch.pl is mostly intended for kernel code
(which I was not aware of) this patch is probably not desired.
In case it still is I can add quote to the draft and link it in the patch.
Powered by blists - more mailing lists