Skip to contentSkip to conversation

regulator: palmas: Check return value of palmas_smps_write()

PATCH New Aleksandrova Alyona 1 participant 1 message Jul 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 regulator: palmas: Check return value of palmas_smps_write()

palmas_set_mode_smps() updates the SMPS mode register when the rail is enabled, but it ignores a possible error from palmas_smps_write().

If the register write fails, the function still reports success to the caller even though the hardware mode has not been updated.

Return the error if palmas_smps_write() fails. Update current_reg_mode and enable_val only after a successful register write so that the cached driver state remains consistent with the hardware state.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes 51d3a0c999e1 ("regulator: palmas: preserve modes of rails during enable/disable")

---
v3:
- Remove the unnecessary new_mode variable.

v2:
- Update current_reg_mode and enable_val only after a successful register write to keep the cached state consistent with the hardware state.

 drivers/regulator/palmas-regulator.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/regulator/palmas-regulator.c +8 -3
index 337dd614695e..d0e604780750 100644
@@ -468,9 +468,14 @@ static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
 		return -EINVAL;
 	}
 
-	pmic->current_reg_mode[id] = reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
-	if (rail_enable)
-		palmas_smps_write(pmic->palmas, rinfo->ctrl_addr, reg);
+	if (rail_enable) {
+		ret = palmas_smps_write(pmic->palmas, rinfo->ctrl_addr, reg);
+		if (ret)
+			return ret;
+	}
+
+	pmic->current_reg_mode[id] =
+		reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
 
 	/* Switch the enable value to ensure this is used for enable */
 	pmic->desc[id].enable_val = pmic->current_reg_mode[id];
Signature · 1 line
2.26.2