From patchwork Tue Jun 13 07:38:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oswald Buddenhagen X-Patchwork-Id: 13278104 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id CADEBC77B7A for ; Tue, 13 Jun 2023 07:39:51 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 2D045822; Tue, 13 Jun 2023 09:38:59 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2D045822 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1686641989; bh=UVimVAlQaD/qBIwR7YjTiZUQ57bbmjM9i8VSrHde7r8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=aar445gx/zXTB8MSB5mG9OBREaVklO+oaMWHYRVSCbNvA3DzJgJ+87R761tVtHXd5 TFbIm7MSDVuMop0wlXCeK9Kv9UFWCO179d/6yGL4B5Im1w77z9M4S6nREWzC8YjTw1 2dE8d/u80cc4eNfofKIJO62BtNQSgS/+3K/sch0M= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 39555F80549; Tue, 13 Jun 2023 09:38:34 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id E864EF80549; Tue, 13 Jun 2023 09:38:33 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 94D4EF80544; Tue, 13 Jun 2023 09:38:29 +0200 (CEST) Received: from bluemchen.kde.org (bluemchen.kde.org [IPv6:2001:470:142:8::100]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id A8D88F80130 for ; Tue, 13 Jun 2023 09:38:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz A8D88F80130 Received: from ugly.fritz.box (localhost [127.0.0.1]) by bluemchen.kde.org (Postfix) with ESMTP id 94B622426F; Tue, 13 Jun 2023 03:38:22 -0400 (EDT) Received: by ugly.fritz.box (masqmail 0.3.4, from userid 1000) id 1q8ybe-dRp-00; Tue, 13 Jun 2023 09:38:22 +0200 From: Oswald Buddenhagen To: alsa-devel@alsa-project.org Cc: Takashi Iwai , Jaroslav Kysela Subject: [PATCH 5/8] ALSA: add snd_ctl_add_locked() Date: Tue, 13 Jun 2023 09:38:19 +0200 Message-Id: <20230613073822.1343234-6-oswald.buddenhagen@gmx.de> X-Mailer: git-send-email 2.40.0.152.g15d061e6df In-Reply-To: <20230613073822.1343234-1-oswald.buddenhagen@gmx.de> References: <20230613073822.1343234-1-oswald.buddenhagen@gmx.de> MIME-Version: 1.0 Message-ID-Hash: 5PAAL2IJ6EO6O45KRZ3XL23KHXFCPQVM X-Message-ID-Hash: 5PAAL2IJ6EO6O45KRZ3XL23KHXFCPQVM X-MailFrom: ossi@kde.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This is in fact more symmetrical to snd_ctl_remove() than snd_ctl_add() is - the former could be named snd_ctl_remove_locked() just as well. This will be used to dynamically change the available controls from another control's put() callback, which is already locked. One might want to add snd_ctl_replace_locked() for completeness, but I have no use for it now. Signed-off-by: Oswald Buddenhagen --- include/sound/control.h | 1 + sound/core/control.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/sound/control.h b/include/sound/control.h index cc3dcc6cfb0f..d4e210831a38 100644 --- a/include/sound/control.h +++ b/include/sound/control.h @@ -134,6 +134,7 @@ void snd_ctl_notify_one(struct snd_card * card, unsigned int mask, struct snd_kc struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new * kcontrolnew, void * private_data); void snd_ctl_free_one(struct snd_kcontrol * kcontrol); int snd_ctl_add(struct snd_card * card, struct snd_kcontrol * kcontrol); +int snd_ctl_add_locked(struct snd_card * card, struct snd_kcontrol * kcontrol); int snd_ctl_remove(struct snd_card * card, struct snd_kcontrol * kcontrol); int snd_ctl_replace(struct snd_card *card, struct snd_kcontrol *kcontrol, bool add_on_replace); int snd_ctl_remove_id(struct snd_card * card, struct snd_ctl_elem_id *id); diff --git a/sound/core/control.c b/sound/core/control.c index 82aa1af1d1d8..ede5ab911add 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -527,6 +527,27 @@ static int snd_ctl_add_replace(struct snd_card *card, return err; } +static int snd_ctl_add_replace_locked(struct snd_card *card, + struct snd_kcontrol *kcontrol, + enum snd_ctl_add_mode mode) +{ + int err = -EINVAL; + + if (! kcontrol) + return err; + if (snd_BUG_ON(!card || !kcontrol->info)) + goto error; + + err = __snd_ctl_add_replace(card, kcontrol, mode); + if (err < 0) + goto error; + return 0; + + error: + snd_ctl_free_one(kcontrol); + return err; +} + /** * snd_ctl_add - add the control instance to the card * @card: the card instance @@ -547,6 +568,16 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol) } EXPORT_SYMBOL(snd_ctl_add); +/** + * snd_ctl_add_locked - same as snd_ctl_add(), but card->controls_rwsem + * is expected to be already locked if necessary. + */ +int snd_ctl_add_locked(struct snd_card *card, struct snd_kcontrol *kcontrol) +{ + return snd_ctl_add_replace_locked(card, kcontrol, CTL_ADD_EXCLUSIVE); +} +EXPORT_SYMBOL(snd_ctl_add_locked); + /** * snd_ctl_replace - replace the control instance of the card * @card: the card instance