Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Kamal Wadhwa <kamal.wadhwa@oss.qualcomm.com>,
	Mark Brown <broonie@kernel.org>, Sasha Levin <sashal@kernel.org>,
	lgirdwood@gmail.com, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH AUTOSEL 6.16-6.12] regulator: pm8008: fix probe failure due to negative voltage selector
Date: Tue,  2 Sep 2025 08:08:22 -0400	[thread overview]
Message-ID: <20250902120833.1342615-11-sashal@kernel.org> (raw)
In-Reply-To: <20250902120833.1342615-1-sashal@kernel.org>

From: Kamal Wadhwa <kamal.wadhwa@oss.qualcomm.com>

[ Upstream commit ef3e9c91ed87f13dba877a20569f4a0accf0612c ]

In the current design, the `pm8008_regulator_get_voltage_sel()` callback
can return a negative value if the raw voltage value is read as 0 uV from
the PMIC HW register. This can cause the probe to fail when the
`machine_constraints_voltage()` check is called during the regulator
registration flow.

Fix this by using the helper `regulator_map_voltage_linear_range()` to
convert the raw value to a voltage selector inside the mentioned get
voltage selector function. This ensures that the value returned is always
within the defined range.

Signed-off-by: Kamal Wadhwa <kamal.wadhwa@oss.qualcomm.com>
Message-ID: <20250823-pm8008-negitive-selector-v1-1-52b026a4b5e8@quicinc.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

**Backport Status: YES**

## Extensive Analysis:

This commit is a clear candidate for backporting to stable kernel trees
based on the following analysis:

### 1. **Bug Fix Nature**
The commit fixes a real probe failure bug in the pm8008 regulator
driver. Looking at the code change at line 99 (`drivers/regulator/qcom-
pm8008-regulator.c:99`), the original implementation had a mathematical
bug:
```c
// OLD (buggy):
return (uV - preg->desc.min_uV) / preg->desc.uV_step;

// NEW (fixed):
return regulator_map_voltage_linear_range(rdev, uV, INT_MAX);
```

### 2. **The Critical Bug**
The original code directly calculates the voltage selector using simple
arithmetic: `(uV - min_uV) / step`. When the hardware register returns 0
(which gets converted to 0 uV), this formula produces a **negative
value** because:
- For NLDO ranges: min_uV = 528000, so (0 - 528000) / 8000 = -66
- For PLDO ranges: min_uV = 1504000, so (0 - 1504000) / 8000 = -188

This negative selector value causes the regulator probe to fail during
`machine_constraints_voltage()` validation, making the entire PM8008
PMIC unusable.

### 3. **Small and Contained Fix**
The fix is minimal - just a single line change that replaces manual
calculation with a proper helper function. The
`regulator_map_voltage_linear_range()` helper properly validates the
voltage against the defined ranges and returns a valid selector or an
error code, preventing negative values.

### 4. **No Architectural Changes**
The fix doesn't introduce any new features or change the driver's
architecture. It simply corrects the voltage selector calculation to use
the proper regulator framework helper.

### 5. **Clear User Impact**
This bug prevents the PM8008 PMIC from initializing at all when the
hardware returns 0V initially. This is a complete failure scenario
affecting real devices like:
- Fairphone FP4 and FP5 (as seen in recent DT commits)
- Qualcomm SC8280XP X13s laptop

### 6. **Recently Introduced Driver**
The driver was only added in June 2024 (commit `11d861d227ed1`), making
this an early bug fix for a relatively new driver. The bug has existed
since the driver's introduction.

### 7. **Already Marked for Stable**
The commit message shows `[ Upstream commit ef3e9c91ed87...]` indicating
this has already been identified for stable backporting by maintainers.

### 8. **Meets Stable Criteria**
According to stable kernel rules, this fix perfectly qualifies because
it:
- Fixes a real bug that affects users (probe failure)
- Is small (1 line change)
- Has no risk of introducing new issues (uses standard helper)
- Fixes a regression (driver never worked with 0V register values)
- Is obviously correct (proper use of framework helper)

The fix is essential for devices using the PM8008 PMIC and should be
backported to all stable kernels that include the original driver
(v6.11+).

 drivers/regulator/qcom-pm8008-regulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/qcom-pm8008-regulator.c b/drivers/regulator/qcom-pm8008-regulator.c
index da017c1969d0c..90c78ee1c37bf 100644
--- a/drivers/regulator/qcom-pm8008-regulator.c
+++ b/drivers/regulator/qcom-pm8008-regulator.c
@@ -96,7 +96,7 @@ static int pm8008_regulator_get_voltage_sel(struct regulator_dev *rdev)
 
 	uV = le16_to_cpu(val) * 1000;
 
-	return (uV - preg->desc.min_uV) / preg->desc.uV_step;
+	return regulator_map_voltage_linear_range(rdev, uV, INT_MAX);
 }
 
 static const struct regulator_ops pm8008_regulator_ops = {
-- 
2.50.1


  parent reply	other threads:[~2025-09-02 12:08 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 12:08 [PATCH AUTOSEL 6.16] gpiolib: acpi: Add quirk for ASUS ProArt PX13 Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16] pinctrl: meson: Fix typo in device table macro Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-5.15] HID: intel-ish-hid: Increase ISHTP resume ack timeout to 300ms Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-5.4] gpio: timberdale: fix off-by-one in IRQ type boundary check Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-6.12] drm/msm: Fix a7xx debugbus read Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-6.1] ata: ahci_xgene: Use int type for 'rc' to store error codes Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16] HID: elecom: add support for ELECOM M-DT2DRBK Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-6.12] hid: fix I2C read buffer overflow in raw_event() for mcp2221 Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-6.12] drm/msm: Fix a7xx TPL1 cluster snapshot Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-6.1] virtio_input: Improve freeze handling Sasha Levin
2025-09-02 12:08 ` Sasha Levin [this message]
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-6.12] drm/msm: Fix debugbus snapshot Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-6.6] HID: quirks: add support for Legion Go dual dinput modes Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-6.6] HID: logitech: Add ids for G PRO 2 LIGHTSPEED Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-6.12] drm/msm: Fix order of selector programming in cluster snapshot Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16-5.4] HID: hid-ntrig: fix unable to handle page fault in ntrig_report_version() Sasha Levin
2025-09-02 12:08 ` [PATCH AUTOSEL 6.16] virtio_net: adjust the execution order of function `virtnet_close` during freeze Sasha Levin

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=20250902120833.1342615-11-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=broonie@kernel.org \
    --cc=kamal.wadhwa@oss.qualcomm.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@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