regulator: mt6358: return error for get/set mode op on linear range LDO

Message ID 20230919083647.3909889-1-wenst@chromium.org
State New
Headers
Series regulator: mt6358: return error for get/set mode op on linear range LDO |

Commit Message

Chen-Yu Tsai Sept. 19, 2023, 8:36 a.m. UTC
  The buck and linear range (VSRAM_*) regulators share one set of ops.
This set includes support for get/set mode. However this only makes
sense for buck regulators, not LDOs. The callbacks were not checking
whether the register offset and/or mask for mode setting was valid or
not. This ends up making the kernel report "normal" mode operation for
the LDOs.

Instead, make the callbacks return -EINVAL if the mode register mask is
not set, signaling that it is not supported.

Fixes: f67ff1bd58f0 ("regulator: mt6358: Add support for MT6358 regulator")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
 drivers/regulator/mt6358-regulator.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Mark Brown Sept. 19, 2023, 12:26 p.m. UTC | #1
On Tue, Sep 19, 2023 at 04:36:46PM +0800, Chen-Yu Tsai wrote:
> The buck and linear range (VSRAM_*) regulators share one set of ops.
> This set includes support for get/set mode. However this only makes
> sense for buck regulators, not LDOs. The callbacks were not checking
> whether the register offset and/or mask for mode setting was valid or
> not. This ends up making the kernel report "normal" mode operation for
> the LDOs.
> 
> Instead, make the callbacks return -EINVAL if the mode register mask is
> not set, signaling that it is not supported.

It would be better to use separate ops for the two cases, that way the
core knows that the operations aren't supported and can handle things
better.
  

Patch

diff --git a/drivers/regulator/mt6358-regulator.c b/drivers/regulator/mt6358-regulator.c
index b9cda2210c33..120c60d40ed4 100644
--- a/drivers/regulator/mt6358-regulator.c
+++ b/drivers/regulator/mt6358-regulator.c
@@ -408,6 +408,9 @@  static int mt6358_regulator_set_mode(struct regulator_dev *rdev,
 	const struct mt6358_regulator_info *info = to_regulator_info(rdev->desc);
 	int val;
 
+	if (!info->modeset_mask)
+		return -EINVAL;
+
 	switch (mode) {
 	case REGULATOR_MODE_FAST:
 		val = MT6358_BUCK_MODE_FORCE_PWM;
@@ -433,6 +436,9 @@  static unsigned int mt6358_regulator_get_mode(struct regulator_dev *rdev)
 	const struct mt6358_regulator_info *info = to_regulator_info(rdev->desc);
 	int ret, regval;
 
+	if (!info->modeset_mask)
+		return -EINVAL;
+
 	ret = regmap_read(rdev->regmap, info->modeset_reg, &regval);
 	if (ret != 0) {
 		dev_err(&rdev->dev,