From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED738606A31C for ; Mon, 30 Nov 2026 17:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=rvp6MG0S; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=ADKBonaq DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:CC:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=1/+1JFXE1GFkNUmx/ttmi7Aefv+D85bu9lzmdaD0vmc=; b=rvp6MG0SFj5bkr ZYBquRDMS4JKAlVgj1o2ZUOI6ayfzXw65p6KNgkZlnh0KomWjBedN/2dDj2/gGFrMijuSSfFFjMgn vpfHjFYC89sMY0ggS4HHuJyeAXzcSWZMfauFpIfl1QH5i9xu0XWcM0klSBHmY6r1QwNn2VbcVdFJ6 cCgOZabOP+KYxjxRw2fDslIHngsGIhSQKNq9MVeQpqcG1C5xZlV6YbOUMB+8aMokeb0qV8dvu8gee oyCsHIYIofzHUupzsGXoiSLWRuC0IxZy1Mjd7SMczztCBQg8LVvLIeBTlW4CVb3z5jPpkkAgPbuQQ yPtHEBu/hEDTrCJ8VONg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY51H-00000005Nb3-3jZX; Mon, 30 Nov 2026 17:18:27 +0000 Received: from mail-swedencentralazlp170130007.outbound.protection.outlook.com ([2a01:111:f403:c202::7] helo=GVXPR05CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY51A-00000005NXo-1fBh for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 17:18:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UzeO/4uSWMa4QnS1KFTu+GeUQBSYcPrPdZuLkRqfGO76ZcTB+YQxfyObLPBK6rkpIJwHVfOZYtfea1e5PyDMIYVKj77PCywhr/ApVSf28gy1l581O/ZSMbUWexm3CUpuo+jI1jOb4ylbpp7AtZgKzmwUNRM7/QFEEVQBHosZN2uW0ONM+vtxNJaDxrY8b+EwOP4f0GVlK/jRO+vQytq76j8ZSQMpcTc1OIlZFkhftU1W4K/ujGnw1xbKN109c8afI5mt+LC9UzmPZabJrFIw5TMqiI7lyQaa7aAYc9qExVunGVmRHEXBcGL7s7gwYorAm4PrXDqid2PX1iorXAmXeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=1/+1JFXE1GFkNUmx/ttmi7Aefv+D85bu9lzmdaD0vmc=; b=TZ8CycpSnMUlWT/e1cv38XI/9+DY6rCPPOGsYJ9HgS+Cf2z9M3UkkfUtiCQ5noleedM2LOr0nZ+P9rnsfZlmo38joBRGfKJAd1mQptSuho2L0zFHFjua8pxMaDqxsixAJ4iTmEWyOrg6t6B8TciH8dd9pnD2SSB+KcdllMT3LhAI3YeVPUBhCC36DLNdYPlt4S5QudxnowUUy2a4SCqD5USqQg9ZnPpIHe1JtIg04tTBaaGfGUpTUkpYb/xcHt3yo0y6Ls/I7nT35R5OSD4e3aFXj1k6RXIaRuvp+/d9fOGyf8QWIp0gYXVtsNVYdHJGl1qTQgxsdh52YbPh0bzqOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.60) smtp.rcpttodomain=gmail.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1/+1JFXE1GFkNUmx/ttmi7Aefv+D85bu9lzmdaD0vmc=; b=ADKBonaqPNjlGr+uipPKxH63gn1XMnj09oYfCQevXfwOD7UvFM5JtSkL9BqgCLhWh9SfpSSDY+eKeaQcXKJIJYHVVeaSAhZknJht5C8R52wBMeuNWc83j9eKw+d5Oo9iin4DMHizQiuhLBpTS+EfPnjoO83nfEy6r0m8C2i3Za+a4oLMEsOozkAX8mmrnZVylRHjVArTtkm9Pq6hGtSIbnpAyFFv2LykK3k/oBY2KxP2vWdRPEmdgs0RUBdgpXfnq+H8XfhFQIbD8nGUvJH9/VUDxGVleJ6uuPtmXf8TRRV+Xt9JLOWnPUXAwsQsPXSX0H8JKGV39Zi8fE3L73g6Cw== Received: from DU2PR04CA0312.eurprd04.prod.outlook.com (2603:10a6:10:2b5::17) by PA1PR10MB8840.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:102:453::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.9; Mon, 30 Nov 2026 17:18:03 +0000 Received: from DU2PEPF00028D06.eurprd03.prod.outlook.com (2603:10a6:10:2b5:cafe::51) by DU2PR04CA0312.outlook.office365.com (2603:10a6:10:2b5::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.12 via Frontend Transport; Mon, 30 Nov 2026 17:18:03 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.60) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.60 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.60; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.60) by DU2PEPF00028D06.mail.protection.outlook.com (10.167.242.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Mon, 30 Nov 2026 17:18:02 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpO365.st.com (10.250.44.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Mon, 30 Nov 2026 18:19:20 +0100 Received: from [10.48.87.64] (10.48.87.64) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Mon, 30 Nov 2026 18:18:01 +0100 Message-ID: Date: Mon, 30 Nov 2026 18:18:00 +0100 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/3] ASoC: stm32: spdifrx: Fix refcount on sync failure To: , Mark Brown CC: Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Arnaud Pouliquen , Maxime Coquelin , , , , , Alexandre Torgue References: <20261127092345.12383-1-phucduc.bui@gmail.com> <20261127092345.12383-3-phucduc.bui@gmail.com> Content-Language: en-US From: Olivier MOYSAN In-Reply-To: <20261127092345.12383-3-phucduc.bui@gmail.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: ENXCAS1NODE2.st.com (10.75.128.138) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D06:EE_|PA1PR10MB8840:EE_ X-MS-Office365-Filtering-Correlation-Id: f2e700e2-a87c-4a51-7715-08df4f05e41e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|23010399003|1800799024|82310400026|376014|7416014|56012099006|10067099003|261028144727099003|261102123227099003|261021121427099003|261021123027099003|261022075727099003|261026140227099003|261022105027099003|18002099003|22082099003|4143699003|11063799006|6133799003|261009223027099003; X-Microsoft-Antispam-Message-Info: rBnV7cCA0h1kZawkV2Or1uxDrb9iesXp45b9+UbxWbWXkQG6+49kylztqaTkpoIlxwIVATCr7lpfP5Wil8fXmnk+nh0Sd/in3JeNjSORE2mdbjBpWFL8rcAwn15K4qeviXAK8gw7l+Oo8VPxhlsZPA2MSj06e+KrSqRryANyMvlEPpPADaz72A0XlbynDoWQQB1VFIyn1BHmmpwdUlsEMhuzfVGDlJU1/jta+qZEuEgmgTjz1SgRy92AaEUr9TAyFPC4FqZ2T3nxOA0xAMQNC7kscFqkVwPBdmX9OMoje37BcSphmaxZyaTySqym6Z96N1ozLnex5EP/n2nCbvuIAlncV2Ghl+pLj/Nivc9oIQshqv74rGtGniaapsNOsBE8h2lv7K1okRRNAGTfvLqbqmPdZXZT4h1FsWGEnchWuW7LPfUEht9W3SzWOjToavEH8PF/sE4dJtkAzjiT4Idlz9Vco27qjN9XQy/Omu4vAki7IrtBu6xisTBlNJHCChOab7SNWKGJ62LRKsWjz6kBQqarJZJPsygtHq0nqdW0lZa3F9UydPK3pfSYff/agMWaZayDCJ/MRzJ+9puOFB+kVPCyYYifepCfK39C5OsUXO27ZlxQHg8tMn+nG+hj9JJX06Rn6fR68kxEVsEwKgCxu7tkSe0UKr+wHHBg16bJco9uC2uqWwIUW4TWMXhHCm8cEkD0fXRGF4YrmZU7zV4pyw== X-Forefront-Antispam-Report: CIP:164.130.1.60;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(23010399003)(1800799024)(82310400026)(376014)(7416014)(56012099006)(10067099003)(261028144727099003)(261102123227099003)(261021121427099003)(261021123027099003)(261022075727099003)(261026140227099003)(261022105027099003)(18002099003)(22082099003)(4143699003)(11063799006)(6133799003)(261009223027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GHxHKqRoy+2YxRp6y0XekozESpu3UN1VjMj/BIb0jKCoFWqDjgrZ+COEpPtI3Wy8wQR0lgQts69NlBRNtan1MYUuZdLC2kl5UhrEoO1QZnZM061HZECE9nKU/cdLwUHFa2fqI48OhdPqvxZuyzpVAL7mT9a0rhi5flUkXqn2rfbIl+nuoIEf0edsdirJff346OXCS45dQUMcIAK714xo1pTnadNa2UfI23C6pcH52mqrNGm4Hsz6gk394j6fyq1gpVQa858UWI97xpDtwihiNApN+4Pypy/HEc+XsmWyxB5Tc+cwvQPJXKv2I1GQb5b1CkSkhLEcJnxKd4eHWuYUyckPn+MHJBE4vc84ziuFZkzraqKW0bkTxTY2D8wbdUqyqrYef8CRFsr+1HEnPNmjVobAVshsoiphZhHztaWtl+o+E37MraJQs2PVBWUhAGbc X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 17:18:02.9427 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f2e700e2-a87c-4a51-7715-08df4f05e41e X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.60];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D06.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR10MB8840 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_091820_674969_F9ABC637 X-CRM114-Status: GOOD ( 20.29 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi, Thanks for your patches. On 11/27/26 10:23, phucduc.bui@gmail.com wrote: > From: bui duc phuc > > Roll back the refcount when starting synchronization fails. > Disable interrupts if no users remain. > > Signed-off-by: bui duc phuc > --- > sound/soc/stm/stm32_spdifrx.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/sound/soc/stm/stm32_spdifrx.c b/sound/soc/stm/stm32_spdifrx.c > index 467c3c583a00..ba6c715750aa 100644 > --- a/sound/soc/stm/stm32_spdifrx.c > +++ b/sound/soc/stm/stm32_spdifrx.c > @@ -358,9 +358,15 @@ static int stm32_spdifrx_start_sync(struct stm32_spdifrx_data *spdifrx) > cr_mask |= SPDIFRX_CR_SPDIFEN_MASK; > ret = regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_CR, > cr_mask, cr); > - if (ret < 0) > + if (ret < 0) { > dev_err(&spdifrx->pdev->dev, > "Failed to start synchronization\n"); > + spdifrx->refcount--; > + if (!spdifrx->refcount) > + regmap_update_bits(spdifrx->regmap, > + STM32_SPDIFRX_IMR, > + SPDIFRX_XIMR_MASK, 0); > + } > } > > return ret; stm32_spdifrx_start_sync() is called in both control and data path. The patch fixes the stm32_spdifrx_get_ctrl_data() path but it seems that it can break the stm32_spdifrx_trigger path. If the trigger START fails (on SPDIFRX_CR update), ALSA calls trigger STOP and runs stm32_spdifrx_stop() a second time. The refcount goes to -1, so stm32_spdifrx_stop() returns early and the spdifrx is never disabled. An alternate could be to ensure that stm32_spdifrx_stop() is called in stm32_spdifrx_get_ctrl_data() when stm32_spdifrx_start_sync() fails. Below is the suggested change: --- a/sound/soc/stm/stm32_spdifrx.c +++ b/sound/soc/stm/stm32_spdifrx.c @@ -322,16 +322,17 @@ static int stm32_spdifrx_start_sync(struct stm32_spdifrx_data *spdifrx) { int cr, cr_mask, imr, ret; + guard(spinlock_irqsave)(&spdifrx->lock); + + /* Callers always balance refcount with stm32_spdifrx_stop(). */ + spdifrx->refcount++; + /* Enable IRQs */ imr = SPDIFRX_IMR_IFEIE | SPDIFRX_IMR_SYNCDIE | SPDIFRX_IMR_PERRIE; ret = regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_IMR, imr, imr); if (ret) return ret; - guard(spinlock_irqsave)(&spdifrx->lock); - - spdifrx->refcount++; - regmap_read(spdifrx->regmap, STM32_SPDIFRX_CR, &cr); if (!(cr & SPDIFRX_CR_SPDIFEN_MASK)) { @@ -480,7 +481,7 @@ static int stm32_spdifrx_get_ctrl_data(struct stm32_spdifrx_data *spdifrx) ret = stm32_spdifrx_start_sync(spdifrx); if (ret < 0) - goto end; + goto stop; if (wait_for_completion_interruptible_timeout(&spdifrx->cs_completion, msecs_to_jiffies(100)) @@ -489,6 +490,7 @@ static int stm32_spdifrx_get_ctrl_data(struct stm32_spdifrx_data *spdifrx) ret = -EAGAIN; } +stop: stm32_spdifrx_stop(spdifrx); stm32_spdifrx_dma_ctrl_stop(spdifrx); I realize that cleanup path needs to be at least re-ordered. I will think about another patch to fix this. Regards Olivier