linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: wangdich9700@163.com
Cc: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz,
	tiwai@suse.com, linux-kernel@vger.kernel.org,
	linux-sound@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	wangdicheng <wangdicheng@kylinos.cn>
Subject: Re: [PATCH] ALSA: hda/senary: Fix potential resource leak in set_beep_amp
Date: Thu, 06 Nov 2025 11:06:21 +0100	[thread overview]
Message-ID: <874ir7h3vm.wl-tiwai@suse.de> (raw)
In-Reply-To: <20251106063546.115197-1-wangdich9700@163.com>

On Thu, 06 Nov 2025 07:35:46 +0100,
wangdich9700@163.com wrote:
> 
> From: wangdicheng <wangdich9700@163.com>
> 
> 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 <wangdicheng@kylinos.cn>

Please align both From and Signed-off-by addresses.
And in this patch...

> ---
>  sound/hda/codecs/senarytech.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/hda/codecs/senarytech.c b/sound/hda/codecs/senarytech.c
> index 9aa1e9bcd9ec..99af8d5e51db 100644
> --- a/sound/hda/codecs/senarytech.c
> +++ b/sound/hda/codecs/senarytech.c
> @@ -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;
>  }

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


  reply	other threads:[~2025-11-06 10:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-06  6:35 [PATCH] ALSA: hda/senary: Fix potential resource leak in set_beep_amp wangdich9700
2025-11-06 10:06 ` Takashi Iwai [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-11-06  3:18 wangdich9700

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874ir7h3vm.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=wangdich9700@163.com \
    --cc=wangdicheng@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).