* [PATCH] selftests/alsa: remove 0/NULL global variable assignment
@ 2025-08-21 20:01 Nikola Z. Ivanov
2025-08-21 20:49 ` Mark Brown
2025-08-22 6:21 ` Takashi Iwai
0 siblings, 2 replies; 7+ messages in thread
From: Nikola Z. Ivanov @ 2025-08-21 20:01 UTC (permalink / raw)
To: broonie, perex, tiwai, shuah, linux-sound, linux-kselftest
Cc: linux-kernel, linux-kernel-mentees, Nikola Z. Ivanov
Remove 0/NULL global variable assignment in mixer-test.c and pcm-test.c
Signed-off-by: Nikola Z. Ivanov <zlatistiv@gmail.com>
---
tools/testing/selftests/alsa/mixer-test.c | 8 ++++----
tools/testing/selftests/alsa/pcm-test.c | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/alsa/mixer-test.c b/tools/testing/selftests/alsa/mixer-test.c
index 2a4b2662035e..e113dafa5c24 100644
--- a/tools/testing/selftests/alsa/mixer-test.c
+++ b/tools/testing/selftests/alsa/mixer-test.c
@@ -53,10 +53,10 @@ struct ctl_data {
struct ctl_data *next;
};
-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;
static void find_controls(void)
{
diff --git a/tools/testing/selftests/alsa/pcm-test.c b/tools/testing/selftests/alsa/pcm-test.c
index dbd7c222ce93..ce92548670c8 100644
--- a/tools/testing/selftests/alsa/pcm-test.c
+++ b/tools/testing/selftests/alsa/pcm-test.c
@@ -30,7 +30,7 @@ struct card_data {
struct card_data *next;
};
-struct card_data *card_list = NULL;
+struct card_data *card_list;
struct pcm_data {
snd_pcm_t *handle;
@@ -43,10 +43,10 @@ struct pcm_data {
struct pcm_data *next;
};
-struct pcm_data *pcm_list = NULL;
+struct pcm_data *pcm_list;
-int num_missing = 0;
-struct pcm_data *pcm_missing = NULL;
+int num_missing;
+struct pcm_data *pcm_missing;
snd_config_t *default_pcm_config;
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/alsa: remove 0/NULL global variable assignment
2025-08-21 20:01 [PATCH] selftests/alsa: remove 0/NULL global variable assignment Nikola Z. Ivanov
@ 2025-08-21 20:49 ` Mark Brown
2025-08-21 21:17 ` Nikola Ivanov
2025-08-22 6:21 ` Takashi Iwai
1 sibling, 1 reply; 7+ messages in thread
From: Mark Brown @ 2025-08-21 20:49 UTC (permalink / raw)
To: Nikola Z. Ivanov
Cc: perex, tiwai, shuah, linux-sound, linux-kselftest, linux-kernel,
linux-kernel-mentees
[-- Attachment #1: Type: text/plain, Size: 718 bytes --]
On Thu, Aug 21, 2025 at 11:01:32PM +0300, Nikola Z. Ivanov wrote:
> Remove 0/NULL global variable assignment in mixer-test.c and pcm-test.c
Why?
> --- a/tools/testing/selftests/alsa/mixer-test.c
> +++ b/tools/testing/selftests/alsa/mixer-test.c
> @@ -53,10 +53,10 @@ struct ctl_data {
> struct ctl_data *next;
> };
>
> -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.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/alsa: remove 0/NULL global variable assignment
2025-08-21 20:49 ` Mark Brown
@ 2025-08-21 21:17 ` Nikola Ivanov
2025-08-21 21:30 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: Nikola Ivanov @ 2025-08-21 21:17 UTC (permalink / raw)
To: Mark Brown
Cc: perex, tiwai, shuah, linux-sound, linux-kselftest, linux-kernel,
linux-kernel-mentees
On Thu, Aug 21, 2025 at 09:49:29PM +0100, Mark Brown wrote:
> On Thu, Aug 21, 2025 at 11:01:32PM +0300, Nikola Z. Ivanov wrote:
> > Remove 0/NULL global variable assignment in mixer-test.c and pcm-test.c
>
> Why?
>
> > --- a/tools/testing/selftests/alsa/mixer-test.c
> > +++ b/tools/testing/selftests/alsa/mixer-test.c
> > @@ -53,10 +53,10 @@ struct ctl_data {
> > struct ctl_data *next;
> > };
> >
> > -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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/alsa: remove 0/NULL global variable assignment
2025-08-21 21:17 ` Nikola Ivanov
@ 2025-08-21 21:30 ` Mark Brown
2025-08-21 22:57 ` Nikola Z. Ivanov
0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2025-08-21 21:30 UTC (permalink / raw)
To: Nikola Ivanov
Cc: perex, tiwai, shuah, linux-sound, linux-kselftest, linux-kernel,
linux-kernel-mentees
[-- Attachment #1: Type: text/plain, Size: 936 bytes --]
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).
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/alsa: remove 0/NULL global variable assignment
2025-08-21 21:30 ` Mark Brown
@ 2025-08-21 22:57 ` Nikola Z. Ivanov
2025-08-21 23:14 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: Nikola Z. Ivanov @ 2025-08-21 22:57 UTC (permalink / raw)
To: Mark Brown
Cc: perex, tiwai, shuah, linux-sound, linux-kselftest, linux-kernel,
linux-kernel-mentees
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/alsa: remove 0/NULL global variable assignment
2025-08-21 22:57 ` Nikola Z. Ivanov
@ 2025-08-21 23:14 ` Mark Brown
0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2025-08-21 23:14 UTC (permalink / raw)
To: Nikola Z. Ivanov
Cc: perex, tiwai, shuah, linux-sound, linux-kselftest, linux-kernel,
linux-kernel-mentees
[-- Attachment #1: Type: text/plain, Size: 777 bytes --]
On Fri, Aug 22, 2025 at 01:57:05AM +0300, Nikola Z. Ivanov wrote:
> On Thu, Aug 21, 2025 at 10:30:50PM +0100, Mark Brown wrote:
> > 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:
...
> 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.
No, it's fine - thanks for checking the reference. I suspected this
might be something specific to how the kernel is linked:
Reviewed-by: Mark Brown <broonie@kernel.org>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/alsa: remove 0/NULL global variable assignment
2025-08-21 20:01 [PATCH] selftests/alsa: remove 0/NULL global variable assignment Nikola Z. Ivanov
2025-08-21 20:49 ` Mark Brown
@ 2025-08-22 6:21 ` Takashi Iwai
1 sibling, 0 replies; 7+ messages in thread
From: Takashi Iwai @ 2025-08-22 6:21 UTC (permalink / raw)
To: Nikola Z. Ivanov
Cc: broonie, perex, tiwai, shuah, linux-sound, linux-kselftest,
linux-kernel, linux-kernel-mentees
On Thu, 21 Aug 2025 22:01:32 +0200,
Nikola Z. Ivanov wrote:
>
> Remove 0/NULL global variable assignment in mixer-test.c and pcm-test.c
>
> Signed-off-by: Nikola Z. Ivanov <zlatistiv@gmail.com>
Applied now. Thanks.
Takashi
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-08-22 6:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 20:01 [PATCH] selftests/alsa: remove 0/NULL global variable assignment Nikola Z. Ivanov
2025-08-21 20:49 ` Mark Brown
2025-08-21 21:17 ` Nikola Ivanov
2025-08-21 21:30 ` Mark Brown
2025-08-21 22:57 ` Nikola Z. Ivanov
2025-08-21 23:14 ` Mark Brown
2025-08-22 6:21 ` Takashi Iwai
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.