ALSA: hda/senary: Fix potential resource leak in set_beep_amp
Subsystems (2)
PATCH 1/1 ALSA: hda/senary: Fix potential resource leak in set_beep_amp
From: wangdicheng <[email protected]>
Add proper error handling in set_beep_amp function to avoid potential resource leaks when snd_hda_gen_add_kctl fails.
Signed-off-by wangdicheng <[email protected]>
--- sound/hda/codecs/senarytech.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
sound/hda/codecs/senarytech.c +14 -3
@@ -47,17 +47,28 @@ static int set_beep_amp(struct senary_spec *spec, hda_nid_t nid, {struct snd_kcontrol_new *knew;unsigned int beep_amp =HDA_COMPOSE_AMP_VAL (nid,1 , idx, dir); -int i; +int i, err; spec->gen.beep_nid = nid;for (i =0 ; i <ARRAY_SIZE (senary_beep_mixer); i++) { knew =snd_hda_gen_add_kctl (&spec->gen,NULL , &senary_beep_mixer[i]); -if (!knew) -return -ENOMEM ; +if (!knew) { + err = -ENOMEM ; + goto error; + } knew->private_value = beep_amp; }return 0 ; + +error: +/* Clean up any successfully added controls */ +while (i-- >0 ) { +/* The gen spec will be cleaned up in senary_remove, +* so we don't need individual cleanup here +*/ + } +return err; }static int senary_auto_parse_beep (struct hda_codec *codec)
Signature · 1 line
2.25.1
Quoted 7 lines · On Thu, 06 Nov 2025 07:35:46 +0100, [email protected] wrote:
From: wangdicheng <[email protected]>
Add proper error handling in
set_beep_ampfunction to avoid potential resource leaks whensnd_hda_gen_add_kctlfails.Signed-off-by wangdicheng <[email protected]>
Please align both From and Signed-off-by addresses. And in this patch...
Quoted 28 lines
--- sound/hda/codecs/senarytech.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)sound/hda/codecs/senarytech.c +5
-3@@ -47,17 +47,28 @@ static int set_beep_amp(struct senary_spec *spec, hda_nid_t nid, {struct snd_kcontrol_new *knew;unsigned int beep_amp =HDA_COMPOSE_AMP_VAL (nid,1 , idx, dir); -int i; +int i, err; spec->gen.beep_nid = nid;for (i =0 ; i <ARRAY_SIZE (senary_beep_mixer); i++) { knew =snd_hda_gen_add_kctl (&spec->gen,NULL , &senary_beep_mixer[i]); -if (!knew) -return -ENOMEM ; +if (!knew) { + err = -ENOMEM ; + goto error; + } knew->private_value = beep_amp; }return 0 ;
sound/hda/codecs/senarytech.c static int set_beep_amp(struct senary_spec *spec, hda_nid_t nid, · line 72
Quoted 10 lines
sound/hda/codecs/senarytech.c +9
-0+ +error: +/* Clean up any successfully added controls */ +while (i-- >0 ) { +/* The gen spec will be cleaned up in senary_remove, +* so we don't need individual cleanup here +*/ + } +return err; }
So the "error handling" you added is just an empty loop. What really does this patch "fix"?
As of this, it looks like just adding some garbage.
thanks,
Takashi