From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CA6043E08D for ; Thu, 30 Jul 2026 14:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785420879; cv=none; b=IkXH2QRvQYJuNKmaGp15MQJpHpUnV+f1zMwv5A7NNoO8BPbHgRBMVa8rZT/lIUQxOmlJx2EmbPMMMWR7Ao1p/KeK42gC31jkZC+g2cVGpEfR497+FX7KVODlwNUMuHoPFekSPWOaBeDBeGsA58Eavt5bEBdSEqXzBn8/lgcqfQs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785420879; c=relaxed/simple; bh=LFAVFR/Ebd0M8gVoXYCoH/VogyPRgNY1LFnFp/ZjP10=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Oug8o6qvMwBILxk09VFVvj8RazssJfXiwYQY6kLANOiV+RIsKRPqeo8+m1keyT1r2hYbU7X+bmBinRWO7ff5dWGw2SniNF1hpNr8xuG6LckIsI2oh4bZRYKfjJn1Z/c7oe8tiTm1Yozc+umYQMfPKvDAftdtjKjveV56wN5/Pv0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TlHN+I60; arc=none smtp.client-ip=209.85.160.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TlHN+I60" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-526f963372aso15767441cf.1 for ; Thu, 30 Jul 2026 07:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785420877; x=1786025677; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=r2Ag2eYiDFYwVSdn+oCdd0do6bhUzUtBZUhVY0F4OiY=; b=TlHN+I603i5D7i6/c4uyfDF3JNOPP6FU9mcolDbcVPoJ1HpWcpp2DtuoUu7tGE92lo +S5VbL5WyZ0J8s32P4l1Myg1OJ/i1FCnWvAGbMyEkEvkMVj7wwnl95Ab84irpJG8EI7a 6Ks1qAJPxQgE+hKSYemw/OfBTukIduFWOxV7ATwLK+NCMx/tmGFVNS1pR/ZvM+vdwdUz m2uIN9sbfexu2toBo1nm4MtECXGzbpMt8CcKv0PD1pSWRxATLjEl3AKuge6mMWdmmbx8 MOGy5pombvvVBjl01R6i/ZBlP35pF4Uaic4aVCKtZU+SXD23NgAKmP2QTClisdcM/WT1 IZJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785420877; x=1786025677; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=r2Ag2eYiDFYwVSdn+oCdd0do6bhUzUtBZUhVY0F4OiY=; b=NJBD00tA0KJslmEZvQA5qUQwrf/3aSRrO4Ty7eSpiMl1BiyZN/773Pf/GOTi/PFA1+ mTYwac4khFa8QqBhZGsIUev89y2nBveacrA8FWZABzTb31Dmtlhasgl++KAXGqXsXCua kZcNP/jUBKshxI1GlvEhYGYB3siHFWTg2Ib+uvTjTz8JqHSEm1G2glyp3xeoeJqRNgH4 jJOvhOSsCDNat3dbXVto5bVasuSc1RwKncCrU6MCsgcYYmoMIdUwHAMzL8fsV7B0Z+Mr 2aK8oeoH9qy3tt0nkDKs1jy2OEmJx04gjrU3SDJgotdlyrF0/A19beFI6kv30pNzx0hZ 0UCQ== X-Forwarded-Encrypted: i=1; AHgh+RoMR3pPq/b7QmvbjoieOX90QrRlo3aSglhcJUOC05oy0yKc2k0wcw1LdJI0rYMvecrE3qoCj0yKCZ/5/4Y=@vger.kernel.org X-Gm-Message-State: AOJu0YwXSqZyKRmjjKFKZtRflsgCtklAfpeVOhhbDiDWUFPq/yM9L4r1 wlY9RjzAfVacZJ7Y/fHI1p2uSKBO2YEviK+UnI6h5VWOa8LVHQF5t7gp X-Gm-Gg: AR+sD13J6UskzKSuTwJXMMeivaW6cv3Cjv+CzTbBse4JI7PRRNr0wDq9VVoaiKvb3Nd xvmESLsnlGm7NGj81M5L+O8Qc+JUEDfA06eq5cttvFUf4VzTHuzo0L+3tyvRauU15/O2PqN0boc ChjLnXhYPvxp8MYa9oeZFpGK5MRXwYAqmf3z+4WGzpDAwR/OyAsfJR22IGM50ze/OkY25v8Egyz p+uK3YyF65mFwDz0wWr+jgzfBc6j/Y47qP4AE2pfv8TjHuiJ9TChNTPJME1Uc7BiN38Ou9hC/M6 48Eet9rj+cGPPOTnZDtzUQPNWi9QhIa54GQOeckSHbltE4nVvYxyGtYcrALn1uq83bb6jJZT544 uRl0Xm7O7g03OHgge6tSUWgV3rTXB61AvVtugksw/EWodHCUWlbZovAIjRgBE2z1rd6H1Z6YuhA O44BCpejFg8K0DmB1UPbbCJD8s3bhOUucqF6A0sFcwRuPXEPY4Oki7jzWJMEKrPSpGkF9v+HiRz lj4+A90sPXW57rhVMLhd1Tol4fFXKFFNyqS1qZwAqQ= X-Received: by 2002:ac8:5750:0:b0:51c:9e6:ec42 with SMTP id d75a77b69052e-52b38678acbmr30445901cf.57.1785420876340; Thu, 30 Jul 2026 07:14:36 -0700 (PDT) Received: from LAPTOP-DPAKMOI4.it.purdue.edu (pal-210-106-74.itap.purdue.edu. [128.210.106.74]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-529e2ff6f31sm41998101cf.27.2026.07.30.07.14.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 07:14:35 -0700 (PDT) From: Yifei Gao To: Bin Du , Nirujogi Pratap , Mauro Carvalho Chehab , Sakari Ailus Cc: Sultan Alsawaf , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Yifei Gao Subject: [PATCH v5 2/2] media: amd: isp4: fix self-deadlock in isp4sd_pwron_and_init() error path Date: Thu, 30 Jul 2026 14:14:04 +0000 Message-ID: <20260730141413.4136502-3-gyf161023@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260730141413.4136502-1-gyf161023@gmail.com> References: <20260728190754.363464-1-gyf161023@gmail.com> <20260730141413.4136502-1-gyf161023@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit isp4sd_pwron_and_init() holds ops_mutex via guard(mutex) and, on any init failure, jumps to err_deinit and calls isp4sd_pwroff_and_deinit(). That helper takes the same ops_mutex, re-acquiring a non-recursive mutex already held by the current thread, so any init failure deadlocks. Unwind the error path in stages instead, releasing only what each failure point acquired. This also avoids the issues that an unconditional teardown would hit at the earlier failures, such as a runtime-PM underflow from pm_runtime_resume_and_get() and MMIO access while the device is unpowered. Fixes: 4e5e7a7ddb4a ("media: platform: amd: isp4 subdev and firmware loading handling added") Assisted-by: Claude:claude-opus-4-8 smatch Signed-off-by: Yifei Gao --- drivers/media/platform/amd/isp4/isp4_subdev.c | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/amd/isp4/isp4_subdev.c b/drivers/media/platform/amd/isp4/isp4_subdev.c index 48deea79ce6c..868d1c74d35e 100644 --- a/drivers/media/platform/amd/isp4/isp4_subdev.c +++ b/drivers/media/platform/amd/isp4/isp4_subdev.c @@ -687,7 +687,7 @@ int isp4sd_pwron_and_init(struct v4l2_subdev *sd) if (ret) { dev_err(dev, "fail to power on isp_subdev ret %d\n", ret); - goto err_deinit; + goto err_module_disable; } /* ISPPG ISP Power Status */ @@ -697,7 +697,7 @@ int isp4sd_pwron_and_init(struct v4l2_subdev *sd) dev_err(dev, "fail to set performance state %u, ret %d\n", perf_state, ret); - goto err_deinit; + goto err_power_off; } ispif->status = ISP4IF_STATUS_PWR_ON; @@ -709,12 +709,12 @@ int isp4sd_pwron_and_init(struct v4l2_subdev *sd) ret = isp4if_start(ispif); if (ret) { dev_err(dev, "fail to start isp_subdev interface\n"); - goto err_deinit; + goto err_perf_restore; } if (isp4sd_start_resp_proc_threads(isp_subdev)) { dev_err(dev, "isp_start_resp_proc_threads fail\n"); - goto err_deinit; + goto err_stop_interface; } dev_dbg(dev, "create resp threads ok\n"); @@ -724,8 +724,24 @@ int isp4sd_pwron_and_init(struct v4l2_subdev *sd) isp_subdev->irq_enabled = true; return 0; -err_deinit: - isp4sd_pwroff_and_deinit(sd); + +err_stop_interface: + isp4if_stop(ispif); +err_perf_restore: + ret = dev_pm_genpd_set_performance_state(dev, ISP4SD_PERFORMANCE_STATE_LOW); + if (ret) + dev_err(dev, "fail to set performance state %u, ret %d\n", + ISP4SD_PERFORMANCE_STATE_LOW, ret); +err_power_off: + isp4hw_wreg(isp_subdev->mmio, ISP_SOFT_RESET, 0); + isp4hw_wreg(isp_subdev->mmio, ISP_POWER_STATUS, 0); + ret = pm_runtime_put_sync(dev); + if (ret) + dev_err(dev, "power off isp_subdev fail %d\n", ret); + ispif->status = ISP4IF_STATUS_PWR_OFF; +err_module_disable: + isp4sd_module_enable(isp_subdev, false); + msleep(20); return -EINVAL; } -- 2.43.0