From patchwork Mon Apr 17 00:35:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 673851 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 D110CC77B61 for ; Mon, 17 Apr 2023 00:37:02 +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 BC9FE1D9; Mon, 17 Apr 2023 02:36:10 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz BC9FE1D9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1681691820; bh=M1wSwwL/WspWtOKyPWAAIoRPZ/EbNkDE3jMENU8zgxA=; h=From:Subject:To:In-Reply-To:References:Date:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=PjIASr4mpfBB8ornwiMCkjRcUlpxS+Z7WlzWEupSAL38rAJ7RqPxQ24deGvxdd6/5 RovFUIGuThHBZ0Ej6JU4W3gyizg+zE0EYqGveoEEQK5BHF5v6ftb7/csO2/B6M2z0d NF6goEHgrvc1VNvc0Jgmm1D/wKc0VkagglH2Kbok= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 0F494F80551; Mon, 17 Apr 2023 02:35:32 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 2CC0AF80551; Mon, 17 Apr 2023 02:35:28 +0200 (CEST) Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01on20707.outbound.protection.outlook.com [IPv6:2a01:111:f403:700c::707]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 4A539F8051F for ; Mon, 17 Apr 2023 02:35:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4A539F8051F Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=renesas.com header.i=@renesas.com header.a=rsa-sha256 header.s=selector1 header.b=OqM43wuX ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LQSizDZk1YeJ3yhCib7i+OPawjbV8tjZ6Oo3QGlfpvQ9k1yQW66llnAb3PXSaWfU2VgRAvt3YruLM0GuYyOyY4JQrzPVgbYHN96QKnsi9V800VjD6OA2qSxN8DA65y8bqjO05ANdTHqcaFSulgwPCq6S1hnCWPDPMQSD+ND+Y0jPcMDps+Hb2Ov5JoGJ06uj3gYSXdetTDH591zALQZd6Qoas0rsIGc2fppStnunImWRaGUx60nR5TEUpAJeRVzhq6Cp31fa3AxOVmMaE4N7vhsvElxW/DBnFYVflTK90l4zwcErvRUymg8n4xy/R2zdpwnMh4QId53IgIAuI0Yvww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1zU1RfcUHNiFAL2zI0ffpyDPF9l0VaQEfDvob84zYKE=; b=mhdgTJaiVgDMNRjXho7V4fhwefoWqvh4mXM7jZIAcEXx9MJEczasXX3ySoGs4ke3DcFBlj28MFICiMM9Iib5EF0HEw04jUwPkM6P1hkgK0qA7J6zhG99NxlQdatc+ilaz77JT4EX7f2mFhWxA/Wv6Z5J0qlfCV6EmfRnh7eoEnLN2uyqw4BLcGc/uC6j8YckEhqF6kcGGFObrxgJkOOk927XHM8m+6LkcmD6V5Jhx6rMExtbovyzwK/12TXoJnAp2eFsMkDwCbyevYJWAP9cSboYfwtSHXpd+R4F4kh1ZV3WUkfrVpMBMQcTMAS+l/049As+NWtXNz24z3YANVLCLQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=renesas.com; dmarc=pass action=none header.from=renesas.com; dkim=pass header.d=renesas.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1zU1RfcUHNiFAL2zI0ffpyDPF9l0VaQEfDvob84zYKE=; b=OqM43wuXUqjgXfB1DycERB4uV/Z6TCV1S2YlhWKVZ9HQ+9JYhwwtb8kqW60v1fLo/QJXjYLw4j5xI1YvV9GO5ZI7r7GBdu/kTRsaIvPURlZKZBQPnzbhYHW1jBZCP9jRGL3U0IoaGhLGt9i+spMBSNUFZkj9t0v+AGT/Rd90KMM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=renesas.com; Received: from OS3PR01MB8426.jpnprd01.prod.outlook.com (2603:1096:604:194::10) by TYWPR01MB9388.jpnprd01.prod.outlook.com (2603:1096:400:1a5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Mon, 17 Apr 2023 00:35:18 +0000 Received: from OS3PR01MB8426.jpnprd01.prod.outlook.com ([fe80::b005:5b0f:6ad8:3eb1]) by OS3PR01MB8426.jpnprd01.prod.outlook.com ([fe80::b005:5b0f:6ad8:3eb1%3]) with mapi id 15.20.6298.045; Mon, 17 Apr 2023 00:35:18 +0000 Message-ID: <87h6tftkft.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH resend 3/3] ASoC: add snd_soc_card_mutex_lock/unlock() User-Agent: Wanderlust/2.15.9 Emacs/27.1 Mule/6.0 To: Mark Brown In-Reply-To: <87leirtkh2.wl-kuninori.morimoto.gx@renesas.com> References: <87leirtkh2.wl-kuninori.morimoto.gx@renesas.com> Date: Mon, 17 Apr 2023 00:35:18 +0000 X-ClientProxiedBy: TYCPR01CA0098.jpnprd01.prod.outlook.com (2603:1096:405:4::14) To OS3PR01MB8426.jpnprd01.prod.outlook.com (2603:1096:604:194::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS3PR01MB8426:EE_|TYWPR01MB9388:EE_ X-MS-Office365-Filtering-Correlation-Id: 44265dd0-4c98-492b-e6e6-08db3edb9ec7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YFYf6m9cSTYKh23umiOAJIhy/bYkAI1uh+tt+SFjR4XPuv/QDT6N8tm6cqzBWsMVQ8d4bdhyMw7Mu4YsGL0ZGP8aD7/kBpRzJrJNnjsa1k2qaQBPCCGAunHmTPa+e0DPoft/BmJcbUroEER4KuUi6LtbQK6SY0hMHTVN3rqFX3Bcu+cojSmZlH5c77nbEq+StAv4E+iiHPJDlQzuJAoBf7onPXjE7+SjGeg1MQorYOptjW/pucpXode20RcJgtVMZyH/6qjCD5W1fXE+EXy/pjIvVtAQRYxQydm+wZztUhoMX/sKnKBaBWmt4gF1AZ/n/r4GCcLc5DS1pJ3MVfjA0/wjV/4HZQDlU85TpuMaN+ZxM/ATg4O9Bm9DmpGDqQv1i5vMaezKVEU3WNqz96o1Yjmi4+QcZOPsa1jSigQd/6htJEV4qaon3kdIgSe1dOLHZ7dm/Wzqv0Tin72L+LqDA7YUJ4k/q42p7/aebZ2n5jw3p/zLlb1OVGbEC4MXs7uUxLXLHi71G9/HXF4ip1C3+tYN0uhJz7hMKERM1uHzQaJQa0Udy0MGscgYpzg/JyTKLmBlW1iQ+r556dy2yuZTF6au8tZZEgrmxeATJcAmg6rp81+ySH+mO/shcIer9hb2NNrw0bwJYPBNJK9GqR8m4g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:OS3PR01MB8426.jpnprd01.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(136003)(396003)(366004)(346002)(376002)(451199021)(36756003)(2906002)(5660300002)(8936002)(8676002)(41300700001)(38350700002)(38100700002)(86362001)(478600001)(2616005)(6506007)(26005)(6512007)(186003)(6486002)(52116002)(4326008)(6916009)(66476007)(66556008)(66946007)(316002)(83380400001)(21314003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: O3FH5+v7Aby5S8OnoaoCYW2Lb0fI/eT6QVLRtel5b6XVZvJhZ8qcxMdIlrv/R1B9f9VnunUUN75QhFjiBhbifFBBPEljLgBHFAAh+Ujkip8zzuQnZmlGwYXDsgELj1VVyVXrtBDJofVIFPPbMe0hDwHzJSyUDOb2tJx1aLhSg3m1AidrkbB49lwv1Ule6457zvEP1Bqy5otQpdA6cJYmfwphjN8sc61dEt+afan4Rgh4ofeFl+3+enIjLbvH/kkOnXEn25V2Kd+R6TIzdwFDKEo0eH1BFJdDwgXKd7lOQcI6ma4Au4hVIa9x+uLfJ/8H0ZPuf7d4/huI5eI7ETxFqyAOki3SS2gvC2F1ryRr4pm7vuuwfC6Q1bH1QYj7iPsNF/GRKvW+Mel2L6NvCklbjGBRcqHyBGgiqB8p06zNH0hwyJLF8PApLQMofaLjdIJNQa7bJVKjQ3W4ZX+vY12YMYUODE0XBlpvGk3DujDpk5vwJy1P2GlusOC26kTm5BGdl9Xbvv5J8vJVAYLXhWRbddLNgsRMAZH15sWxCVXRH8XE3ewF7erUEbneVdQGFOk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atorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44265dd0-4c98-492b-e6e6-08db3edb9ec7 X-MS-Exchange-CrossTenant-AuthSource: OS3PR01MB8426.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2023 00:35:18.6612 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GLTrWA1/svfeVMRDq4jyC+6EN3YOkzaqJofdRGlxTKMdq206aU0IlZQ+qhcTy2waM7wAKLou5+NTCMz0/B4I4l07KkGmOggDnwsB1RGRYBn8BelFJ+cfucbWxrUj10Pe X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYWPR01MB9388 Message-ID-Hash: 2EWAZQWWTZDD6ZCM3DIHCGK7AZGX7NGQ X-Message-ID-Hash: 2EWAZQWWTZDD6ZCM3DIHCGK7AZGX7NGQ X-MailFrom: kuninori.morimoto.gx@renesas.com 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 CC: Linux-ALSA 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: ASoC need to use card->mutex with _INIT or _RUNTIME, but there is no helper function for it. This patch adds its helper function and use it. Because people might misunderstand that _init() is mutex initialization, this patch renames _INIT to _ROOT and adds new snd_soc_card_mutex_lock_root() for it. Signed-off-by: Kuninori Morimoto --- include/sound/soc-card.h | 17 ++++++++++++++++- sound/soc/soc-compress.c | 18 +++++++++--------- sound/soc/soc-core.c | 4 ++-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/include/sound/soc-card.h b/include/sound/soc-card.h index 9d31a5c0db33..fc94dfb0021f 100644 --- a/include/sound/soc-card.h +++ b/include/sound/soc-card.h @@ -9,10 +9,25 @@ #define __SOC_CARD_H enum snd_soc_card_subclass { - SND_SOC_CARD_CLASS_INIT = 0, + SND_SOC_CARD_CLASS_ROOT = 0, SND_SOC_CARD_CLASS_RUNTIME = 1, }; +static inline void snd_soc_card_mutex_lock_root(struct snd_soc_card *card) +{ + mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_ROOT); +} + +static inline void snd_soc_card_mutex_lock(struct snd_soc_card *card) +{ + mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME); +} + +static inline void snd_soc_card_mutex_unlock(struct snd_soc_card *card) +{ + mutex_unlock(&card->mutex); +} + struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card, const char *name); int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type, diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 661e9d70994f..d8715db5e415 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -140,7 +140,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ int ret; - mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); + snd_soc_card_mutex_lock(fe->card); ret = dpcm_path_get(fe, stream, &list); if (ret < 0) @@ -184,7 +184,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) snd_soc_runtime_activate(fe, stream); snd_soc_dpcm_mutex_unlock(fe); - mutex_unlock(&fe->card->mutex); + snd_soc_card_mutex_unlock(fe->card); return 0; @@ -196,7 +196,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) dpcm_path_put(&list); be_err: fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; - mutex_unlock(&fe->card->mutex); + snd_soc_card_mutex_unlock(fe->card); return ret; } @@ -207,7 +207,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) struct snd_soc_dpcm *dpcm; int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ - mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); + snd_soc_card_mutex_lock(fe->card); snd_soc_dpcm_mutex_lock(fe); snd_soc_runtime_deactivate(fe, stream); @@ -237,7 +237,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0); - mutex_unlock(&fe->card->mutex); + snd_soc_card_mutex_unlock(fe->card); return 0; } @@ -284,7 +284,7 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) cmd == SND_COMPR_TRIGGER_DRAIN) return snd_soc_component_compr_trigger(cstream, cmd); - mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); + snd_soc_card_mutex_lock(fe->card); ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd); if (ret < 0) @@ -315,7 +315,7 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) out: fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; - mutex_unlock(&fe->card->mutex); + snd_soc_card_mutex_unlock(fe->card); return ret; } @@ -373,7 +373,7 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream, int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ int ret; - mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); + snd_soc_card_mutex_lock(fe->card); /* * Create an empty hw_params for the BE as the machine driver must @@ -411,7 +411,7 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream, out: fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; - mutex_unlock(&fe->card->mutex); + snd_soc_card_mutex_unlock(fe->card); return ret; } diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 4594505cdae2..b48efc3a08d2 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1938,7 +1938,7 @@ static int snd_soc_bind_card(struct snd_soc_card *card) int ret; mutex_lock(&client_mutex); - mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); + snd_soc_card_mutex_lock_root(card); snd_soc_dapm_init(&card->dapm, card, NULL); @@ -2093,7 +2093,7 @@ static int snd_soc_bind_card(struct snd_soc_card *card) if (ret < 0) soc_cleanup_card_resources(card); - mutex_unlock(&card->mutex); + snd_soc_card_mutex_unlock(card); mutex_unlock(&client_mutex); return ret;