Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8381DC433B4 for ; Wed, 14 Apr 2021 10:53:29 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 10A2A61249 for ; Wed, 14 Apr 2021 10:53:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10A2A61249 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id CA92016AE; Wed, 14 Apr 2021 12:52:35 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz CA92016AE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1618397605; bh=r1w5RVSyAN0lZxGtWs0R/GNJatf1fFubW2rxERLZwyA=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=IcVNAZLRg2a9HBSeTAqmy2IHuXsSvqVEaiqAzES2MJtCbRyiiUuMqzGcOYcbQ6njv 0AFT4n7ZzJtFN4+LlZP5a4o5/YRP5FIyCwKbhRc4vuJ5W3YCDBC29V3pcDRlR6syqc K2/9/CK+tmeZfdPxOhYcGinEHq7dTbvrgR9MR1F0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4B74BF8025B; Wed, 14 Apr 2021 12:52:35 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1A8BEF80269; Wed, 14 Apr 2021 12:52:33 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 98583F800FF for ; Wed, 14 Apr 2021 12:52:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 98583F800FF X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6C463AEEE; Wed, 14 Apr 2021 10:52:25 +0000 (UTC) Date: Wed, 14 Apr 2021 12:52:25 +0200 Message-ID: From: Takashi Iwai To: Jaroslav Kysela Subject: Re: [PATCH] ALSA: control_led - fix the stack usage (control element ops) In-Reply-To: <7624e19b-d618-0dcd-8798-989a1375614f@perex.cz> References: <20210414093031.1934261-1-perex@perex.cz> <7624e19b-d618-0dcd-8798-989a1375614f@perex.cz> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: Nathan Chancellor , ALSA development X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Wed, 14 Apr 2021 12:09:07 +0200, Jaroslav Kysela wrote: > > 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 > >> Cc: Nathan Chancellor > >> Cc: Takashi Sakamoto > > > > 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. OK, I see your points. OTOH, I prefer simplicity at this moment over yet another kmalloc. If the static variables are enough, that sounds like the best option. Not only that it's way simpler (only two line changes), it's even more byte-saving as it allocates only once globally, not per snd_ctl_led object. Having a comment should be good enough for avoiding the pitfall in future changes (if any). thanks, Takashi