From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.0 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796193916; b=ZlEtGkytVxRDkICO0VaJ3rVCwibwGWmUR8y3CHhHw4joPQN0NRg9HGJoNGt4ri42l1sO CAQxv1EAtkzclHrS3truJjAmSK1YzTauJKX7SGr87JzJz8ONnu/yJToldt31uNzAVijlV 0FTEBaOKh9vVT99gEk0+FkAmNRogefkIksKvqucfQhz3U3w4cnhp6znd5Q0+XkQmI1pa4 doxEQCpYCYdDQNmVjZDcz+QWHnZGqGEvXA2drlqb9E3ig7cu6Ddk1ZMpzq6NP60EkCO6/ Y1zm33BHvpK4Zy4IvVomeua/ZPIsa3rU5wZpBC5kOm/zGmMsnNzsbyeGVTaCeYOyCgA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796193916; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=46gwbpDYncoGuCYncUW+q9pv7sCP65ohD5Vj8S5ELkI=; b=E6za9jzwbdYzm05jM330JIeqJgw6tCgSu9/BJAkxycYlBXPECEw+SZbQUhFPFcMe3geI qyzdvWB/WXlXeoIH1i0z+5tKfP/FMpgJM5mz+XaPVDM4AhiluaXR8dNdroAav3d1Czn5a 2pNBlZUANjsBogPXyFe9HNPG35bMfUQvmDnqds+FX479IGe9p3vML1q4uasxe6zTcpLwB Rq4rsqN4Z+BNNvG+ZpFDOQpSVDt1ih7ZlivYsaopGXVnkgVUYc1Wxmcqz7ysrT7ipiKGy 8rnl9Z0uqDNKTf9j5U4eLmHShisd+vkA/OCrfmC5+uRMgfionPN7HVWm6lS92kqbZ+g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=yjm5xHPv; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.0 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013000.outbound.protection.outlook.com [40.93.201.0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 263CC606A325; Wed, 2 Dec 2026 06:45:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 263CC606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=yjm5xHPv ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Xi+bGo/qPlR//4DB4jT5JvyVVHKgyQuNLTcFP96aCygOUqPfwAWx5Er8vFkChWMsH3QD+W8fA7+eYF1wiehbNpkz9axMT784thVp4I41MFwGcnPrfHN/7W33D10ialr2U0ZSBGzM9kafOpXzy1fvH/q9KdZk9NB4sCHWuNlD2nVfyKOQACC6btj509qFF8aqEuMzrv1oA6DO8/QeeAYfOyWLuQmqrEyNwMdGSK32R52Hxn90JT/qw28IrWmE2iGwN95T4i7LHZf4E2rroI+c0bz//Gp5wWiRuK5sN6LVyVu1tbyYPkdd55Wo1LWOloLtuoKrV8xOd9zFaFtTFxtX3A== 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=46gwbpDYncoGuCYncUW+q9pv7sCP65ohD5Vj8S5ELkI=; b=MQpccenjNVKXl8LBy6yiX/iVl6QrTqOUwEFpgIZ/CSGPzmEjI1glgY93qbjGtt54aQH4hYymWYWUQ6ptEltiXiXNHihPMYRkVVnqw0CR/ANAINrVPUClAb6beFEfwIOQ9FzTpLtuINfZQRhcnrk3e/WFtIaAy/ynoMBMlQLOXcLFOjn2UoaeOnfNPa4OmoJC5JMlZYzMr2NaKi60aBEQVm+Mk6vd+igZYmE4H+T2+6XKD+x7My27bA/tIQDh/bU/BPlBKYKr4a1gx70TQZNzPCiiIemxeLlfbGe10x4RM2CYLTMvv4MRUDjb10dqB9b0nvI7WnKDa4EAgvnsvRaWEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=46gwbpDYncoGuCYncUW+q9pv7sCP65ohD5Vj8S5ELkI=; b=yjm5xHPvp7pyd5cfyWrj9yS/3qFFUgr7QxXWqfJa4oySF+AaSjwblkT5M4SALMJ8+JHBt4D0CyqG8Wp3yT7mVDFmB2IHAbTu8aHZWWTHe5ctFUVWTV9dMBfEkUh4l22EK85AyQW3vDFkf/xiB/a0afAZAJFWB8WTlDuBUR+5Hms= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from CY5PR12MB6252.namprd12.prod.outlook.com (2603:10b6:930:20::17) by CH3PR12MB9396.namprd12.prod.outlook.com (2603:10b6:610:1d0::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 06:45:12 +0000 Received: from CY5PR12MB6252.namprd12.prod.outlook.com ([fe80::ab00:d77:6014:64a2]) by CY5PR12MB6252.namprd12.prod.outlook.com ([fe80::ab00:d77:6014:64a2%4]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 06:45:12 +0000 Message-ID: Date: Wed, 2 Dec 2026 12:13:57 +0530 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts() To: Pierre-Louis Bossart , vkoul@kernel.org Cc: broonie@kernel.org, yung-chuan.liao@linux.intel.com, Sunil-kumar.Dommati@amd.com, venkataprasad.potturu@amd.com, Syed.SabaKareem@amd.com, Mario.Limonciello@amd.com, Richard.Gong@amd.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261201082651.3700713-1-Vijendar.Mukunda@amd.com> <89ff4a51-4346-4013-b645-4bcc8643509c@linux.dev> Content-Language: en-US From: "Mukunda,Vijendar" In-Reply-To: <89ff4a51-4346-4013-b645-4bcc8643509c@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: MA5PR01CA0135.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a01:1d5::12) To CY5PR12MB6252.namprd12.prod.outlook.com (2603:10b6:930:20::17) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6252:EE_|CH3PR12MB9396:EE_ X-MS-Office365-Filtering-Correlation-Id: 64004e8e-2a68-4da1-05f0-08df503fd054 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|1800799024|366016|376014|18002099003|22082099003|10067099003|56012099006|260925022911599003|260925021911599003|260925021311599003|261028144727099003|261026140227099003|261026121527099003|261102123227099003|261021121427099003|261021123027099003|261022075727099003|261022105027099003|261009223027099003|261009221227099003|4143699003|5023799004|11063799006|6133799003; X-Microsoft-Antispam-Message-Info: ldXrEYKFrXQaMXr0bExiBDzUGN2yEBOdEV+yAOwn+ysXNOsJuln1RUOqw42bBu2USpCB05ZOl7yOnDeuL4HNWPVJ9kMBdFRofpfPYB20ENAP75KTTH7Jak/jzkJPTx7XDQ15vd7q0FbOe45ZMHTEO/c4L4MrE3Hkn8OpABoNmIvJYmyIFCGJby8qcMuIuWWX+WvFhsuXN4p6GapppYLAkS2wFzalmDHVMVMKqX7/rsD4GKylNXxlsArPmrUzvxBDYGgA+Z2oSi7QyZ2rC5MRBUEZSso8HSSUi6HLBw18THme22TUBO39CwzLfjSiDZd+ArRsTE0rhsX3ZHF4RQnNfPiySjQIpYQ1CatzzzUkRmisvB/OAeMHBC46UUfoYevgUz+NhnWhENGCDGC7/ty7E3T4y1EDkQQv2tRnm1vso6Y7MAuNN8W3s4kEL5bRQETfbf1L4a7oRoih21eLmkqCKy7fB2mJA5phF5N+Mu40gnksIzM4xhqUtNWbNSuNEnd0DCGgIXF7VRtCN3w8Pb548sSv8slZiDkbyHaRZ9Dlp8yYarOSnDwPUsBlVulAXVkjikkykPLjuv72ymcSSBeN2Cck/z0YarGfqUP9W5KEmCY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6252.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(1800799024)(366016)(376014)(18002099003)(22082099003)(10067099003)(56012099006)(260925022911599003)(260925021911599003)(260925021311599003)(261028144727099003)(261026140227099003)(261026121527099003)(261102123227099003)(261021121427099003)(261021123027099003)(261022075727099003)(261022105027099003)(261009223027099003)(261009221227099003)(4143699003)(5023799004)(11063799006)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?My9RMittbER0dkVndHZPY1k5NFR3SDhubStxclVsOWd4NXFmL0NDVExlbThN?= =?utf-8?B?WVVCd1ltU21qMGxkTlRGQzA4QTF0Zk12TjBXM0s5Zng1NkgveGdlMXM1Z0Fh?= =?utf-8?B?cGRNMWtxWU9LTGNpRXVtV3FtZTdqWTUrQ0o4OFIxVk5jNGRJTkFMQ08zbHRD?= =?utf-8?B?dkwrY1lTdzFSRGR1RlhQVXpSQ000QXRHOHdMbGhhZG50b1dHMHVFTnpibWJF?= =?utf-8?B?YTlKNWpoYlNuaFpzaGd3WlpOc1U4alc1VXRITDZscmprbURwRzJMR3h0OTRz?= =?utf-8?B?R2F4bVBiaGJtc3pXc1NMeGg4TnRJNXlZNXNKT09Ta3J3OUFTN1FZbFVDenND?= =?utf-8?B?OWIzNzJJNDV2QnMyV1F5ZDNIeVQrUFE2TU4xSFlvQzRLVnFLWkE0QXNCVm13?= =?utf-8?B?ZU5WTWdSS3JKdUlrOVNudGV0dWkvbHZ4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= =?utf-8?B?a1lnd2ZhUWFkdVFKbE0wZnNBeWZSdFNwaTk4TGV5amFUT3ROQnJaVXlTcUdL?= =?utf-8?B?OGVtbnlHN3lIeFg4emNpOHdXRmREc3RGRC9hek1JeWozTnVUclM1QT09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64004e8e-2a68-4da1-05f0-08df503fd054 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6252.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 06:45:12.0752 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /rqXm4TsH5+OlqUT1unv46FWUHjOifJsr87BqV/4G7rNkOFccvuO0SIi5sJRWlO5e3JT02ABnH7KfrrWTZkIIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9396 On 12/1/26 22:44, Pierre-Louis Bossart wrote: > > > On 12/1/26 9:26 AM, Vijendar Mukunda wrote: >> sdw_handle_slave_alerts() calls pm_runtime_get_sync(&slave->dev) which, >> when slave->dev is not in RPM_ACTIVE, calls rpm_resume() on the slave. >> rpm_resume() propagates synchronously up the parent chain: slave->dev -> >> bus->dev -> manager->dev. If manager->dev is in RPM_SUSPENDING at that >> point, rpm_resume() blocks on dev->power.wait_queue waiting for the >> suspend to complete. >> >> This creates a deadlock: the manager's runtime_suspend callback is >> blocked >> in cancel_work_sync() waiting for the alert work to finish, while the >> alert >> work is blocked in pm_runtime_get_sync() waiting for the manager's >> runtime_suspend to complete. > > Can I ask why the manager doesn't disable the interrupts before > initiating a runtime pm_suspend and presumably stopping the clock? > > It's a known design feature btw with the clock stop, once you start > the transition you want to go all the way. If there is indeed a jack > or something, the device can keep the data line high to resume. > > I am not sure if there's any merit is requesting a resume that could > be done with the regular wake from clock stop? The fix in bus.c is generic and applies to all SoundWire managers. Even when a manager disables interrupts early in its suspend sequence, there is still a timing window where: 1. The slave asserts ALERT; the IRQ fires and the alert work is queued. 2. The manager transitions to RPM_SUSPENDING and runtime_suspend calls    cancel_work_sync() to drain the work. 3. The in-flight alert work reaches pm_runtime_get_sync(&slave->dev),    which propagates rpm_resume() up to the manager — blocking on    dev->power.wait_queue because the manager is in RPM_SUSPENDING. cancel_work_sync() and pm_runtime_get_sync() deadlock on each other. In theory this can occur on any SoundWire manager that calls cancel_work_sync() inside runtime_suspend. As per our understanding, the fix returns early from sdw_handle_slave_alerts() in that window to break the deadlock and calls pm_request_resume() so the alert is re-serviced after the manager reaches RPM_ACTIVE. This was originally identified during the AMD SoundWire driver series review and the bus.c fix was proposed as the resolution: https://sashiko.dev/#/message/9466c3c5-50f7-4566-9ff4-3d7d8aa4491f%40amd.com The issue has not been observed in practice on AMD platforms. Intel's cdns_update_slave_status_work() follows the same pattern, so the exposure is not AMD-specific. @Vinod, @Pierre-Louis: given that this has not been observed in practice and the clock-stop wake mechanism handles most scenarios, would you prefer to keep this fix or revert to the original pm_runtime_get_sync() path?  We are happy to defer to your guidance. > > we've gone back and forth on the use of pm_runtime_resume_and_get(), > it was great until we reverted most of my changes. > > see e9537962519e ("soundwire: bus: Fix unbalanced pm_runtime_put() > causing usage count underflow") Acknowledged.  The revert `e9537962519e` notes that the previous use of pm_runtime_resume_and_get() caused a usage count underflow because pm_runtime_put() was called unconditionally even when pm_runtime_resume_and_get() returned -EACCES (which does not increment the counter). The current implementation addresses this explicitly: have_pm_ref is set to true only when pm_runtime_resume_and_get() returns >= 0, and pm_runtime_put_autosuspend() at io_err: is guarded by have_pm_ref. The put is never called on an error path where no reference was taken.  This is precisely the conditional-put pattern that the revert commit described as the requirement for safe use of pm_runtime_resume_and_get(). >> >> Fixes: aa79293517b3 ("soundwire: bus: fix io error when processing >> alert event") >> Signed-off-by: Vijendar Mukunda >> --- >>   drivers/soundwire/bus.c | 60 +++++++++++++++++++++++++++++++++++++---- >>   1 file changed, 55 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c >> index 15c66effbf4f..5dc3598eb85f 100644 >> --- a/drivers/soundwire/bus.c >> +++ b/drivers/soundwire/bus.c >> @@ -1667,15 +1667,60 @@ static int sdw_handle_slave_alerts(struct >> sdw_slave *slave) >>       u8 buf, buf2[2]; >>       bool parity_check; >>       bool parity_quirk; >> +    bool have_pm_ref = false; >> +    bool have_mgr_ref = false; >> +    struct device *mgr_dev = slave->bus->dev->parent; >>         sdw_modify_slave_status(slave, SDW_SLAVE_ALERT); >>   -    ret = pm_runtime_get_sync(&slave->dev); >> +    ret = pm_runtime_get_if_active(mgr_dev); >> +    if (ret == 0) { >> +        /* >> +         * Manager is not RPM_ACTIVE (RPM_SUSPENDED, RPM_SUSPENDING, or >> +         * RPM_RESUMING). Return early to avoid I/O on potentially >> +         * inaccessible hardware and to prevent a deadlock: if the >> manager >> +         * is in RPM_SUSPENDING, its runtime_suspend callback may be >> blocked >> +         * in cancel_work_sync() waiting for this work, while this work >> +         * would block in pm_runtime_resume_and_get() waiting for the >> +         * manager to complete its suspend. >> +         * >> +         * Request an async resume so the deferred alert is >> re-serviced: >> +         * - RPM_SUSPENDING: pm_request_resume() sets >> deferred_resume so >> +         *   the manager resumes immediately after its suspend >> completes; >> +         *   on resume the peripheral re-asserts the alert via the >> first >> +         *   PING frame and the interrupt fires again. >> +         * - RPM_RESUMING: pm_request_resume() is a no-op (device >> already >> +         *   resuming); after the manager reaches RPM_ACTIVE, the >> peripheral >> +         *   re-asserts the alert via the first PING frame. >> +         * - RPM_SUSPENDED: pm_request_resume() triggers an async >> resume; >> +         *   after resume the peripheral re-asserts via PING. >> +         * >> +         * When the SoundWire link fully powers off (e.g. D3 or >> equivalent), >> +         * the peripheral loses power and its alert state does not >> survive; > > that statement isn't quite right, in theory for runtime_pm you *do* > want the ability to exit from clock stop. It's only in the system > suspend that it's ok to lose an alert and request the peripheral state > when the user restarts the device. Agreed, the comment is imprecise.  For runtime PM the peripheral retains its state via the clock-stop wake mechanism and the alert is re-asserted after the manager resumes; pm_request_resume() is therefore actively useful, not merely harmless.  Losing alert state without recovery is acceptable only in system suspend (S3/S4) where the peripheral may be fully powered off.  We will update the comment to make this distinction explicit. > >> +         * pm_request_resume() is unnecessary but harmless. >> +         */ >> +        pm_request_resume(mgr_dev); > > what happens if you don't do this? My take is that the clock stop wake > will be used. > For wake-capable CLK_STOP_MODE peripherals, agreed — the wake mechanism triggers a resume and the alert is re-serviced. The gap is non-wake-capable CLK_STOP_MODE peripherals.  Without pm_request_resume(), the manager completes its suspend, the clock stops, and nothing triggers a resume — the manager stays in RPM_SUSPENDED and the alert goes unserviced indefinitely. pm_request_resume() sets deferred_resume=true so the manager resumes immediately after runtime_suspend returns, restarts the clock, and the peripheral re-asserts the alert in the first PING. For POWER_OFF_MODE and CLK_STOP_BUS_RESET the bus reset on resume clears the peripheral's SCP state, so the alert is lost regardless; pm_request_resume() is harmless but not needed in that path. >> +        dev_dbg(&slave->dev, "Alert deferred: manager not active\n"); >> +        return 0; >> +    } >> +    if (ret > 0) >> +        have_mgr_ref = true; >> +    /* >> +     * ret < 0 (-EINVAL): PM is disabled (CONFIG_PM=n or >> disable_depth > 0). >> +     * Proceed without a manager reference. >> +     */ >> + >> +    ret = pm_runtime_resume_and_get(&slave->dev); >>       if (ret < 0 && ret != -EACCES) { >>           dev_err(&slave->dev, "Failed to resume device: %d\n", ret); >> -        pm_runtime_put_noidle(&slave->dev); >> -        return ret; >> +        goto mgr_put; >>       } >> +    if (ret >= 0) >> +        have_pm_ref = true; >> +    /* >> +     * ret == -EACCES: PM is disabled on slave; proceed without a >> +     * slave reference, consistent with the original -EACCES exemption. >> +     */ >>         /* Read Intstat 1, Intstat 2 and Intstat 3 registers */ >>       ret = sdw_read_no_pm(slave, SDW_SCP_INT1); >> @@ -1861,8 +1906,13 @@ static int sdw_handle_slave_alerts(struct >> sdw_slave *slave) >>           dev_warn(&slave->dev, "Reached MAX_RETRY on alert read\n"); >>     io_err: >> -    pm_runtime_mark_last_busy(&slave->dev); >> -    pm_runtime_put_autosuspend(&slave->dev); >> +    if (have_pm_ref) { >> +        pm_runtime_mark_last_busy(&slave->dev); >> +        pm_runtime_put_autosuspend(&slave->dev); >> +    } >> +mgr_put: >> +    if (have_mgr_ref) >> +        pm_runtime_put(mgr_dev); >>         return ret; >>   } >