Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jisheng Zhang" <jszhang@kernel.org>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 1/3] regulator: mp886x: fix vsel_mask
Date: Tue, 01 Sep 2026 05:02:34 +0000	[thread overview]
Message-ID: <20260901050234.8BF651F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260901043123.5401-2-jszhang@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Hardware I2C read/write errors during initialization are silently ignored, resulting in negative error codes stored in unsigned integers and corrupted state logic.
- [Medium] Potential division by zero in `mp8869_scale` due to unvalidated device tree properties.
--

commit e23dcb351cfbd15403625e41999e01844e07121f
Author: Jisheng Zhang <jszhang@kernel.org>

    regulator: mp886x: fix vsel_mask
    
    The MP886X vsel is 7bits, fix the vsel_mask.
    
    Fixes: 97be82880b61 ("regulator: add support for MP8869 regulator")

> diff --git a/drivers/regulator/mp886x.c b/drivers/regulator/mp886x.c
> index e0b62bc02a1e1..a10f3a20d413f 100644
> --- a/drivers/regulator/mp886x.c
> +++ b/drivers/regulator/mp886x.c
> @@ -267,14 +267,14 @@ static int mp886x_regulator_register(struct mp886x_device_info *di,
>  	rdesc->min_uV = 600000;
>  	rdesc->uV_step = 10000;
>  	rdesc->vsel_reg = MP886X_VSEL;
> -	rdesc->vsel_mask = 0x3f;
> +	rdesc->vsel_mask = 0x7f;
>  	rdesc->ramp_reg = MP886X_SYSCNTLREG1;
>  	rdesc->ramp_mask = MP886X_SLEW_MASK;
>  	rdesc->ramp_delay_table = di->ci->slew_rates;
>  	rdesc->n_ramp_values = ARRAY_SIZE(di->ci->slew_rates);
>  	rdesc->owner = THIS_MODULE;
>  
>  	rdev = devm_regulator_register(di->dev, &di->desc, config);
>  	if (IS_ERR(rdev))
>  		return PTR_ERR(rdev);
>  	di->sel = rdesc->ops->get_voltage_sel(rdev);

[Severity: High]
This is a pre-existing issue, but does this code properly handle negative error
codes if I2C communication fails?

If get_voltage_sel() fails and returns -EIO or another negative error code,
it gets implicitly cast and stored in the unsigned int di->sel. The error
is never returned to the caller.

This negative value could later cause issues in mp8867_set_voltage_sel():

drivers/regulator/mp886x.c:mp8867_set_voltage_sel() {
	...
	delta = di->sel - sel;
	if (abs(delta) <= 5)
		ret = regmap_update_bits(rdev->regmap, MP886X_SYSCNTLREG1,
					 MP886X_GO, 0);
	...
}

If di->sel holds an error code like -5 (0xFFFFFFFB), and sel is 0,
delta becomes -5. Since abs(-5) <= 5 is true, the driver incorrectly
writes to the register to clear MP886X_GO, masquerading an I2C error as a
valid small voltage step.

Additionally, hardware initialization errors appear to be ignored elsewhere,
such as in mp886x_set_switch_freq() where the return value of
regmap_update_bits() is not checked. Could the driver end up succeeding in
its probe even if the hardware is completely unresponsive?

[Severity: Medium]
This is also a pre-existing issue, but is there a risk of a division by zero
when reading the divider values from the device tree?

In mp886x_i2c_probe(), the driver reads the mps,fb-voltage-divider array:

drivers/regulator/mp886x.c:mp886x_i2c_probe() {
	...
	ret = of_property_read_u32_array(np, "mps,fb-voltage-divider",
					 di->r, 2);
	if (ret)
		return ret;
	...
}

There does not seem to be a check ensuring that the denominator (di->r[1])
is strictly positive. If the device tree provides a zero value for this second
resistor, wouldn't this cause a kernel panic when mp8869_scale() divides by
r2:

drivers/regulator/mp886x.c:mp8869_scale() {
	...
	u32 tmp = uv * r1 / r2;
	...
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260901043123.5401-1-jszhang@kernel.org?part=1

  reply	other threads:[~2026-09-01  5:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01  4:31 [PATCH 0/3] regulator: mp886x: add MP8864 support Jisheng Zhang
2026-09-01  4:31 ` [PATCH 1/3] regulator: mp886x: fix vsel_mask Jisheng Zhang
2026-09-01  5:02   ` sashiko-bot [this message]
2026-09-01  4:31 ` [PATCH 2/3] regulator: dt-bindings: mp886x: support mp8864 Jisheng Zhang
2026-09-01 17:42   ` Conor Dooley
2026-09-01  4:31 ` [PATCH 3/3] regulator: mp886x: add MP8864 support Jisheng Zhang
2026-09-01  5:00   ` sashiko-bot

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=20260901050234.8BF651F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jszhang@kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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