From: Yaohan Li <shunsheng1218@gmail.com>
To: Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: Dan Carpenter <dan@pereq.eu>, Dan Carpenter <error27@gmail.com>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] regulator: qcom-labibb: unwind failed OCP IRQ setup
Date: Tue, 1 Dec 2026 15:06:15 +0800 [thread overview]
Message-ID: <20261201070615.3115855-1-shunsheng1218@gmail.com> (raw)
qcom_labibb_setup_ocp_irq() currently requests the over-current IRQ and
sets vreg->ocp_irq_done before calling qcom_labibb_ocp_hw_enable(), so a
hardware enable failure leaves the IRQ registered for the devres action
to release later. That triggers a Smatch warning on the error path and
also allows a repeated call to qcom_labibb_set_ocp() (when
vreg->ocp_irq_done is already true) to call qcom_labibb_ocp_hw_enable()
again while ocp_recovery_work is managing an active OCP event.
Request the IRQ with IRQF_NO_AUTOEN so the handler cannot run before the
hardware source is enabled, log a warning if the best-effort
qcom_labibb_ocp_hw_disable() rollback fails, free the IRQ locally when
qcom_labibb_ocp_hw_enable() fails, and enable the IRQ only once setup
succeeds. Return early when vreg->ocp_irq_done is already set so
repeated constraint setup does not race with ocp_recovery_work.
Fixes: d23ba232a8fe ("regulator: qcom-labibb: stop the recovery workers on teardown")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/20261125184601.R647t8Sj-lkp@intel.com/
Suggested-by: Dan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/r/awkf4CNhSPz-lcEk@stanley.mountain/
Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
---
Based on broonie/regulator.git for-7.5 (21cff6dd85cb).
I don't have physical PMI8998 hardware, so I exercised this in QEMU
(x86_64, KASAN + PROVE_LOCKING) with a small test module driving the
driver against a simulated SPMI regmap and virtual IRQ chip: covering
request_threaded_irq() failure and retry, LATCHED_CLR / INT_EN_SET
enable failures with local free_irq() rollback, repeated set_ocp()
calls while ocp_recovery_work is active, unbind with recovery work
pending, and simultaneous INT_EN_SET + INT_EN_CLR failures (where
software logs the warning and frees the IRQ cleanly, though if
INT_EN_CLR itself fails software cannot guarantee the PMIC hardware
interrupt source was silenced). Also build-tested on x86_64 and arm64
with W=1.
AI assistance: Claude (Anthropic) helped with the analysis, the QEMU
test module, and drafting the patch and changelog. I reviewed the
code paths, IRQ-depth invariants, test logs, and final patch myself.
drivers/regulator/qcom-labibb-regulator.c | 79 ++++++++++++-----------
1 file changed, 43 insertions(+), 36 deletions(-)
diff --git a/drivers/regulator/qcom-labibb-regulator.c b/drivers/regulator/qcom-labibb-regulator.c
index 8dc0c0c..1613be7 100644
--- a/drivers/regulator/qcom-labibb-regulator.c
+++ b/drivers/regulator/qcom-labibb-regulator.c
@@ -392,56 +392,63 @@ static void qcom_labibb_stop_works(void *data)
*/
static int qcom_labibb_setup_ocp_irq(struct labibb_regulator *vreg)
{
- u32 irq_flags = IRQF_ONESHOT;
- int ret;
+ u32 irq_flags = IRQF_ONESHOT | IRQF_NO_AUTOEN;
+ int ret, cleanup_ret;
lockdep_assert_held(&vreg->ocp_lock);
if (vreg->shutting_down)
return -ESHUTDOWN;
- if (!vreg->ocp_requested)
+ if (!vreg->ocp_requested || vreg->ocp_irq_done)
return 0;
- if (!vreg->ocp_irq_done) {
- /* IRQ polarities - LAB: trigger-low, IBB: trigger-high */
- switch (vreg->type) {
- case QCOM_LAB_TYPE:
- irq_flags |= IRQF_TRIGGER_LOW;
- break;
- case QCOM_IBB_TYPE:
- irq_flags |= IRQF_TRIGGER_HIGH;
- break;
- default:
- return -EINVAL;
- }
-
- /*
- * The interrupt is owned and released by the cleanup
- * action, so its name has to outlive the interrupt:
- * devres would release a name allocated here before the
- * action runs, while vreg->desc.name is owned by the
- * driver data.
- */
- ret = request_threaded_irq(vreg->ocp_irq, NULL,
- qcom_labibb_ocp_isr, irq_flags,
- vreg->desc.name, vreg);
- if (ret)
- return ret;
-
- vreg->ocp_irq_done = true;
+ /* IRQ polarities - LAB: trigger-low, IBB: trigger-high */
+ switch (vreg->type) {
+ case QCOM_LAB_TYPE:
+ irq_flags |= IRQF_TRIGGER_LOW;
+ break;
+ case QCOM_IBB_TYPE:
+ irq_flags |= IRQF_TRIGGER_HIGH;
+ break;
+ default:
+ return -EINVAL;
}
/*
- * Enable the hardware source only once a handler exists, and turn
- * it back off if that failed, so that a later attempt can retry
- * without leaving the source enabled on its own.
+ * The interrupt is owned and released by the cleanup action, so
+ * its name has to outlive the interrupt: devres would release a
+ * name allocated here before the action runs, while
+ * vreg->desc.name is owned by the driver data.
+ *
+ * Request with IRQF_NO_AUTOEN so the handler cannot run before
+ * the hardware source is enabled, allowing local free_irq() on
+ * hardware enable failure without racing with the ISR or worker.
*/
- ret = qcom_labibb_ocp_hw_enable(vreg->rdev);
+ ret = request_threaded_irq(vreg->ocp_irq, NULL,
+ qcom_labibb_ocp_isr, irq_flags,
+ vreg->desc.name, vreg);
if (ret)
- qcom_labibb_ocp_hw_disable(vreg->rdev);
+ return ret;
- return ret;
+ /*
+ * Best-effort hardware disable on failure: a failed regmap write
+ * does not guarantee the hardware state remained unchanged.
+ */
+ ret = qcom_labibb_ocp_hw_enable(vreg->rdev);
+ if (ret) {
+ cleanup_ret = qcom_labibb_ocp_hw_disable(vreg->rdev);
+ if (cleanup_ret)
+ dev_warn(vreg->dev,
+ "Failed to disable OCP IRQ source: %d\n",
+ cleanup_ret);
+ free_irq(vreg->ocp_irq, vreg);
+ return ret;
+ }
+
+ vreg->ocp_irq_done = true;
+ enable_irq(vreg->ocp_irq);
+ return 0;
}
static int qcom_labibb_set_ocp(struct regulator_dev *rdev, int lim,
--
2.43.0
reply other threads:[~2026-12-01 7:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201070615.3115855-1-shunsheng1218@gmail.com \
--to=shunsheng1218@gmail.com \
--cc=broonie@kernel.org \
--cc=dan@pereq.eu \
--cc=error27@gmail.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®