alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Jaroslav Kysela <perex@perex.cz>
To: Takashi Iwai <tiwai@suse.de>
Cc: Nathan Chancellor <nathan@kernel.org>,
	ALSA development <alsa-devel@alsa-project.org>
Subject: Re: [PATCH] ALSA: control_led - fix the stack usage (control element ops)
Date: Wed, 14 Apr 2021 12:09:07 +0200	[thread overview]
Message-ID: <7624e19b-d618-0dcd-8798-989a1375614f@perex.cz> (raw)
In-Reply-To: <s5h35vtw681.wl-tiwai@suse.de>

Dne 14. 04. 21 v 11:44 Takashi Iwai napsal(a):
> On Wed, 14 Apr 2021 11:30:31 +0200,
> Jaroslav Kysela wrote:
>>
>> It's a bad idea to allocate big structures on the stack. Allocate
>> the required structures on demand and cache them in the led
>> structure.
>>
>> Fixes: 22d8de62f11b ("ALSA: control - add generic LED trigger module as the new control layer")
>> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
>> Cc: Nathan Chancellor <nathan@kernel.org>
>> Cc: Takashi Sakamoto <o-takashi@sakamocchi.jp>
> 
> Thanks for the patch.
> 
> But, wouldn't it be simpler if we just add snd_ctl_elem_info and
> _value in snd_ctl_led object itself?
> 
> -- 8< --
> --- a/sound/core/control_led.c
> +++ b/sound/core/control_led.c
> @@ -38,6 +38,8 @@ struct snd_ctl_led {
>  	enum led_audio trigger_type;
>  	enum snd_ctl_led_mode mode;
>  	struct snd_ctl_led_card *cards[SNDRV_CARDS];
> +	struct snd_ctl_elem_info elem_info;
> +	struct snd_ctl_elem_value elem_value;
>  };
>  
>  struct snd_ctl_led_ctl {
> 
> -- 8< --
> 
> Then we need no extra kmalloc.  I guess snd_ctl_led_get() shall be
> called almost always, so we won't save much even if we allocate
> dynamically.

The idea was to allocate this structure purely on demand. We can have the case
where some LED group is inactive (no speaker LED for example) or the LED
functionality is not used at all even if the module is loaded. And it's true
that those structures requires some more bytes.

Another option is just to make the structures in snd_ctl_led_get() static -
two line patch. The calls are protected with snd_ctl_led_mutex . But it may be
problematic if we do a finer mutex locking per LED group in the future.

						Jaroslav

-- 
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

  reply	other threads:[~2021-04-14 10:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14  9:30 [PATCH] ALSA: control_led - fix the stack usage (control element ops) Jaroslav Kysela
2021-04-14  9:44 ` Takashi Iwai
2021-04-14 10:09   ` Jaroslav Kysela [this message]
2021-04-14 10:52     ` Takashi Iwai
2021-04-14 10:59       ` Jaroslav Kysela
2021-04-14 10:58 Jaroslav Kysela
2021-04-14 12:23 ` Takashi Iwai
2021-04-14 13:53   ` Jaroslav Kysela

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=7624e19b-d618-0dcd-8798-989a1375614f@perex.cz \
    --to=perex@perex.cz \
    --cc=alsa-devel@alsa-project.org \
    --cc=nathan@kernel.org \
    --cc=tiwai@suse.de \
    /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).