From patchwork Tue Jul 18 14:13:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13317358 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 D600FEB64DA for ; Tue, 18 Jul 2023 14:15:44 +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 3237FAE8; Tue, 18 Jul 2023 16:14:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3237FAE8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1689689743; bh=SbMgOKp/Dtk3OU3upvxhl1FQGNla/w5yOt+xhBf0LM4=; 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=vrwmobbxwCoGIWYk1eG3hVA9nrndEPe7ZLPJ29r9VR4tDgHYoO8ozFS7K5JjxeWKW McAhjmNj96iHi3lWi5tMpPYNV8iSk9tbHemG79C1jcjkjaXB1bvgnrc7DZod2LYdgh y2hEIyrzY6o7Az1NL5ca/0qGwsd16EqMfiU1BqC8= Received: by alsa1.perex.cz (Postfix, from userid 50401) id EC596F805BA; Tue, 18 Jul 2023 16:13:45 +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 1BFE3F805BE; Tue, 18 Jul 2023 16:13:45 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B933EF80527; Tue, 18 Jul 2023 16:13:36 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id D54F3F80552 for ; Tue, 18 Jul 2023 16:13:16 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D54F3F80552 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=CRnIYMug; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=mpjDyG0U Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0D5A821921; Tue, 18 Jul 2023 14:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1689689596; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BM/vb7fAL/Hn07pLPymOKUcn4k96qSSJvPcodZlHYmA=; b=CRnIYMug2b07stZhdcYnCF7OHcKOF7ataf/3dF0nhSmbWgKdsc8xyp1FU8whaC867uJiXi mlj6HwdJQ3EFM4k7MqMUL+bCg9PImguvhHIaJ6IGM+D09IrkNkjMAjHYTQIjI69lj07cHl GXvZEBmkA4qSwSM4eUgnK6LRIozJsGI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1689689596; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BM/vb7fAL/Hn07pLPymOKUcn4k96qSSJvPcodZlHYmA=; b=mpjDyG0U/q1v9HqiA6WfaRFtYhqPRjrABdZEEDk50nm94uZTN/H7tU0EVF6/62wpDyIk4y igUZEArwjqfPFdDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CD2FD138EC; Tue, 18 Jul 2023 14:13:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8NM8MfudtmQ8AQAAMHmgww (envelope-from ); Tue, 18 Jul 2023 14:13:15 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: Takashi Iwai , Vaibhav Agarwal , Mark Greer , Johan Hovold , Alex Elder , Greg Kroah-Hartman , greybus-dev@lists.linaro.org Subject: [PATCH 07/11] staging: greybus: Avoid abusing controls_rwsem Date: Tue, 18 Jul 2023 16:13:00 +0200 Message-Id: <20230718141304.1032-8-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230718141304.1032-1-tiwai@suse.de> References: <20230718141304.1032-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: 54ASDGW5AXPMFIV7SIJSWXC47REFGBCS X-Message-ID-Hash: 54ASDGW5AXPMFIV7SIJSWXC47REFGBCS X-MailFrom: tiwai@suse.de 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: The controls_rwsem of snd_card object is rather an internal lock, and not really meant to be used by others for its data protection. This patch addresses it by replacing the controls_rwsem usages with the own (new) mutex. Note that the up_write() and down_write() calls around gbaudio_remove_component_controls() are simply dropped without replacement. These temporary up/down were a workaround since gbaudio_remove_component_controls() itself took the rwsem. Now it was also gone, we can clean up the workaround, too. Cc: Vaibhav Agarwal Cc: Mark Greer Cc: Johan Hovold Cc: Alex Elder Cc: Greg Kroah-Hartman Cc: greybus-dev@lists.linaro.org Signed-off-by: Takashi Iwai Acked-by: Greg Kroah-Hartman --- drivers/staging/greybus/audio_codec.c | 18 +++++++----------- drivers/staging/greybus/audio_codec.h | 1 + 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c index 72ace74ea605..2f05e761fb9a 100644 --- a/drivers/staging/greybus/audio_codec.c +++ b/drivers/staging/greybus/audio_codec.c @@ -807,7 +807,6 @@ int gbaudio_register_module(struct gbaudio_module_info *module) { int ret; struct snd_soc_component *comp; - struct snd_card *card; struct gbaudio_jack *jack = NULL; if (!gbcodec) { @@ -816,21 +815,20 @@ int gbaudio_register_module(struct gbaudio_module_info *module) } comp = gbcodec->component; - card = comp->card->snd_card; - down_write(&card->controls_rwsem); + mutex_lock(&gbcodec->register_mutex); if (module->num_dais) { dev_err(gbcodec->dev, "%d:DAIs not supported via gbcodec driver\n", module->num_dais); - up_write(&card->controls_rwsem); + mutex_unlock(&gbcodec->register_mutex); return -EINVAL; } ret = gbaudio_init_jack(module, comp->card); if (ret) { - up_write(&card->controls_rwsem); + mutex_unlock(&gbcodec->register_mutex); return ret; } @@ -867,7 +865,7 @@ int gbaudio_register_module(struct gbaudio_module_info *module) ret = snd_soc_dapm_new_widgets(comp->card); dev_dbg(comp->dev, "Registered %s module\n", module->name); - up_write(&card->controls_rwsem); + mutex_unlock(&gbcodec->register_mutex); return ret; } EXPORT_SYMBOL(gbaudio_register_module); @@ -935,13 +933,12 @@ static void gbaudio_codec_cleanup(struct gbaudio_module_info *module) void gbaudio_unregister_module(struct gbaudio_module_info *module) { struct snd_soc_component *comp = gbcodec->component; - struct snd_card *card = comp->card->snd_card; struct gbaudio_jack *jack, *n; int mask; dev_dbg(comp->dev, "Unregister %s module\n", module->name); - down_write(&card->controls_rwsem); + mutex_lock(&gbcodec->register_mutex); mutex_lock(&gbcodec->lock); gbaudio_codec_cleanup(module); list_del(&module->list); @@ -978,10 +975,8 @@ void gbaudio_unregister_module(struct gbaudio_module_info *module) dev_dbg(comp->dev, "Removing %d controls\n", module->num_controls); /* release control semaphore */ - up_write(&card->controls_rwsem); gbaudio_remove_component_controls(comp, module->controls, module->num_controls); - down_write(&card->controls_rwsem); } if (module->dapm_widgets) { dev_dbg(comp->dev, "Removing %d widgets\n", @@ -992,7 +987,7 @@ void gbaudio_unregister_module(struct gbaudio_module_info *module) dev_dbg(comp->dev, "Unregistered %s module\n", module->name); - up_write(&card->controls_rwsem); + mutex_unlock(&gbcodec->register_mutex); } EXPORT_SYMBOL(gbaudio_unregister_module); @@ -1012,6 +1007,7 @@ static int gbcodec_probe(struct snd_soc_component *comp) info->dev = comp->dev; INIT_LIST_HEAD(&info->module_list); mutex_init(&info->lock); + mutex_init(&info->register_mutex); INIT_LIST_HEAD(&info->dai_list); /* init dai_list used to maintain runtime stream info */ diff --git a/drivers/staging/greybus/audio_codec.h b/drivers/staging/greybus/audio_codec.h index ce15e800e607..f3f7a7ec6be4 100644 --- a/drivers/staging/greybus/audio_codec.h +++ b/drivers/staging/greybus/audio_codec.h @@ -71,6 +71,7 @@ struct gbaudio_codec_info { /* to maintain runtime stream params for each DAI */ struct list_head dai_list; struct mutex lock; + struct mutex register_mutex; }; struct gbaudio_widget {