From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 7003C472541 for ; Tue, 28 Jul 2026 19:08:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785265707; cv=none; b=grsiRuxT4LU+Yi2UepXBchwVxCxMJkAWrsODzj1YNeOn8QsbKChfx9jYWJiR6U2nclHEBtNMSZT8wlZhMi0mRH2slv3g0lye3ih+IYU0HWrt54BiCdS7ibUl6neHVgcLqh0SMaCzF/Y3zQOhKGlK5+2fe8hw6o8f6qX8O8Kj1os= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785265707; c=relaxed/simple; bh=LFAVFR/Ebd0M8gVoXYCoH/VogyPRgNY1LFnFp/ZjP10=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D/DEUi2F697meAYcGa+J+6SOw2idfZ8LQcJthhqzblgUPBmmAU/8k6Sa4O1ZpSMfd+ixQnJKn6VJyoPCkvGC0Cg8HxElijjp/rvO5UKtblVQbW8solbfeqeWzYwOBsQyxwNYwvjHyYcwfs5620o5Q0scxNYav5WAjP1YqxmVBSM= 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=KSjX3zia; arc=none smtp.client-ip=209.85.219.54 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="KSjX3zia" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-8f0e5e36912so950256d6.2 for ; Tue, 28 Jul 2026 12:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785265704; x=1785870504; 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=KSjX3ziadDZPwq5I1I/hlu4OCfTSkoCktI/R14rN+cOtIhhF1Cly/QQeAMZTSTOpn1 ACgZQS2AZqxH5Z1iMFXLQH5op931ZFVUB0STkt15jqMIvIXfOrhg9UNTNmTcPr5VzLEx 1AGcw4MU9Zx/S/nVqmnTPPIlAgRMzXcWX95ej0QyY2ErUeQ3Fcm5oGOA4oQj+wzlciNX 0osn1za+hTgA09u/IvKl3UTvjX8g3MuUvKw6OAHj+RDYbGqozcEZrfoAw6V0PO8940Oq gKoLhqqO4APeiXN+KmcqKwKivpdFgFS4ebcwhBGS0tonlAvoWSfD9YXJp4o1H00sqb3p V9FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785265704; x=1785870504; 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=C12UBJaxqBwEACoyk54bfCOg41PprkRcBzlEugBoCz7yIpen2FkbfNukXzceYNP0YL rdDidrF/+UFky2V1uGrA22LRu772JUke/G9Fa0rWbhBe5SJN8xaOoiliPcaRzuSiI8Vs DlqXCWLENAkZYhslQpVBHCb8eYFiVH7aBn2d/FqSeVTYbhoPGJyqtQcHE40w8GhuK4ck UP4hqHe6FTh9APJXdSqmBcKf5fg/K2KDC48zD0dzotH+0SPTPBwp4vqVWv3YEj5LiQXh VO3Pcr7ub+m9vcOBfVlqjvHoR7/4qlBtlVAnCDCnFtxkl6eLmcQDBL9PKEAAtCy4UywW nefg== X-Forwarded-Encrypted: i=1; AHgh+RpZZLOjlsxNUT3DWVYp9ar85at3HFJSG+Dmgr4MZ6BwHZBzfk8hg6/4utFubt079oWxC1BB5zjemS4s6Xc=@vger.kernel.org X-Gm-Message-State: AOJu0YzyDIGvns9qRO6rHJfO0gZ9DtZ7VjWw1DvGohlOFAhr84C2AW+8 H90LFrtir1yWOvx/dmFI74tqdOAaySE6UubDuoQ2TfeFNK0IK7+Zf3UX X-Gm-Gg: AR+sD11BRNlNBgUa8OzOmWBOKKpWmFS620P4HrJ55lyo6+Li/X/8OKMFo0RWFJdY2jq YfaKV/Rova6pgSXfoA1zPNWbSi6zK5x8Tr7OAI/iskR8unPil2X4B+auFedTeIQohT3RjpLhyYf 6qxkuJncl9QIVWZHTJg59I9KTOyiSxFPauGLh1o+1krEi/J4c1hnIDTk9yc0pnKPPygKgMXPVwo BC1bP2eueBxvjpcACyri3DNuuSNAEl7hRQLEYiJpO2rB2iGnRz9PtAm0B1NyNe5FTxmqi5+x2qF PnejheDRB6b60cC9iWCQ5T7dwQE0+lsKOI6NVL0d8nI8eL8AFawnKwpCJHo7WJ+7tFEQHWitC64 zNfLoByE7VlkZVphH0rPgC3IDF6mYQuuGLGaJ8RpKgjkOGMgm5itoxsgHJdEWWcY7MVPjEc+1oA qsFLwDmpIBvpKVW7mXTlYkGA0oDBSoEuoTN0fQrWjxfA6Xcxe3tSqaYImX X-Received: by 2002:a05:6214:19e7:b0:8ef:db4:d85f with SMTP id 6a1803df08f44-908172c32e1mr46063076d6.41.1785265704274; Tue, 28 Jul 2026 12:08:24 -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 6a1803df08f44-9081dd68434sm5556936d6.38.2026.07.28.12.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 12:08:23 -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 v4 2/2] media: amd: isp4: fix self-deadlock in isp4sd_pwron_and_init() error path Date: Tue, 28 Jul 2026 19:07:40 +0000 Message-ID: <20260728190754.363464-3-gyf161023@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260728190754.363464-1-gyf161023@gmail.com> References: <20260728141659.62310-1-gyf161023@gmail.com> <20260728190754.363464-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