* [PATCH] sound/core/seq: Initialize structure pointer to NULL to prevent undefined behavior
@ 2025-10-02 17:43 hariconscious
2025-10-03 7:21 ` Takashi Iwai
2025-10-06 3:55 ` David Hunter
0 siblings, 2 replies; 3+ messages in thread
From: hariconscious @ 2025-10-02 17:43 UTC (permalink / raw)
To: perex, tiwai
Cc: khalid, shuah, david.hunter.linux, linux-sound, linux-kernel,
HariKrishna Sagala
From: HariKrishna Sagala <hariconscious@gmail.com>
This change ensures the structure pointer is explicitly initialized to
NULL,preventing potential access to uninitialized memory. It improves
code safety and avoids undefined behavior during pointer dereferencing.
Signed-off-by: HariKrishna Sagala <hariconscious@gmail.com>
---
Note:
Turned on the settings needed for sequencer MIDI and built a kernel
image with those settings. The system booted up fine with no errors.
However, couldn’t get the sequencer emulation to start.
sound/core/seq/seq_midi_emul.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/core/seq/seq_midi_emul.c b/sound/core/seq/seq_midi_emul.c
index 81d2ef5e5811..f24c5a475c41 100644
--- a/sound/core/seq/seq_midi_emul.c
+++ b/sound/core/seq/seq_midi_emul.c
@@ -647,7 +647,7 @@ static void snd_midi_channel_init(struct snd_midi_channel *p, int n)
*/
static struct snd_midi_channel *snd_midi_channel_init_set(int n)
{
- struct snd_midi_channel *chan;
+ struct snd_midi_channel *chan = NULL;
int i;
chan = kmalloc_array(n, sizeof(struct snd_midi_channel), GFP_KERNEL);
@@ -686,7 +686,7 @@ reset_all_channels(struct snd_midi_channel_set *chset)
*/
struct snd_midi_channel_set *snd_midi_channel_alloc_set(int n)
{
- struct snd_midi_channel_set *chset;
+ struct snd_midi_channel_set *chset = NULL;
chset = kmalloc(sizeof(*chset), GFP_KERNEL);
if (chset) {
base-commit: 50c19e20ed2ef359cf155a39c8462b0a6351b9fa
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] sound/core/seq: Initialize structure pointer to NULL to prevent undefined behavior
2025-10-02 17:43 [PATCH] sound/core/seq: Initialize structure pointer to NULL to prevent undefined behavior hariconscious
@ 2025-10-03 7:21 ` Takashi Iwai
2025-10-06 3:55 ` David Hunter
1 sibling, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2025-10-03 7:21 UTC (permalink / raw)
To: hariconscious
Cc: perex, tiwai, khalid, shuah, david.hunter.linux, linux-sound,
linux-kernel
On Thu, 02 Oct 2025 19:43:00 +0200,
hariconscious@gmail.com wrote:
>
> From: HariKrishna Sagala <hariconscious@gmail.com>
>
> This change ensures the structure pointer is explicitly initialized to
> NULL,preventing potential access to uninitialized memory. It improves
> code safety and avoids undefined behavior during pointer dereferencing.
>
> Signed-off-by: HariKrishna Sagala <hariconscious@gmail.com>
> ---
>
> Note:
> Turned on the settings needed for sequencer MIDI and built a kernel
> image with those settings. The system booted up fine with no errors.
> However, couldn’t get the sequencer emulation to start.
Something really wrong in your test, I'm afraid.
See your patch below more closely:
>
> sound/core/seq/seq_midi_emul.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sound/core/seq/seq_midi_emul.c b/sound/core/seq/seq_midi_emul.c
> index 81d2ef5e5811..f24c5a475c41 100644
> --- a/sound/core/seq/seq_midi_emul.c
> +++ b/sound/core/seq/seq_midi_emul.c
> @@ -647,7 +647,7 @@ static void snd_midi_channel_init(struct snd_midi_channel *p, int n)
> */
> static struct snd_midi_channel *snd_midi_channel_init_set(int n)
> {
> - struct snd_midi_channel *chan;
> + struct snd_midi_channel *chan = NULL;
> int i;
>
> chan = kmalloc_array(n, sizeof(struct snd_midi_channel), GFP_KERNEL);
The variable chan is initialized at the very beginning.
NULL initialization is utterly nonsense.
> @@ -686,7 +686,7 @@ reset_all_channels(struct snd_midi_channel_set *chset)
> */
> struct snd_midi_channel_set *snd_midi_channel_alloc_set(int n)
> {
> - struct snd_midi_channel_set *chset;
> + struct snd_midi_channel_set *chset = NULL;
>
> chset = kmalloc(sizeof(*chset), GFP_KERNEL);
Here, too.
So all changes make really no sense.
thanks,
Takashi
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] sound/core/seq: Initialize structure pointer to NULL to prevent undefined behavior
2025-10-02 17:43 [PATCH] sound/core/seq: Initialize structure pointer to NULL to prevent undefined behavior hariconscious
2025-10-03 7:21 ` Takashi Iwai
@ 2025-10-06 3:55 ` David Hunter
1 sibling, 0 replies; 3+ messages in thread
From: David Hunter @ 2025-10-06 3:55 UTC (permalink / raw)
To: hariconscious, perex, tiwai; +Cc: khalid, shuah, linux-sound, linux-kernel
On 10/2/25 13:43, hariconscious@gmail.com wrote:
> From: HariKrishna Sagala <hariconscious@gmail.com>
>
> This change ensures the structure pointer is explicitly initialized to
> NULL,preventing potential access to uninitialized memory. It improves
> code safety and avoids undefined behavior during pointer dereferencing.
>
> Signed-off-by: HariKrishna Sagala <hariconscious@gmail.com>
Hi Harikrishna,
Thank you for detailing your attempt at testing. Unfortunately, your
patch makes no substantive change. The variable you are setting to NULL
is assigned before use, so there is no risk of undefined behavior.
I know this can seem discouraging to hear, but I do want you to
encourage you to keep looking for ways you can make contributions.
Thanks,
David
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-06 3:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-02 17:43 [PATCH] sound/core/seq: Initialize structure pointer to NULL to prevent undefined behavior hariconscious
2025-10-03 7:21 ` Takashi Iwai
2025-10-06 3:55 ` David Hunter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox