git: e41207729840 - main - axp81x: Check the errors of the register accesses
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 10 Nov 2026 13:42:56 UTC
The branch main has been updated by manu:
URL: https://cgit.FreeBSD.org/src/commit/?id=e41207729840f817a45a1db9894c5d633f541009
commit e41207729840f817a45a1db9894c5d633f541009
Author: Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-11-10 08:25:57 +0000
Commit: Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-10 13:42:45 +0000
axp81x: Check the errors of the register accesses
axp8xx_regnode_enable() wrote back a value computed from a register it
failed to read, which clears the enable bits of all the other
regulators of that register. Return an error instead, and do the same
in the other regnode methods, which used an uninitialised value when an
access failed.
Also initialise udelay in axp8xx_regnode_init(), as
axp8xx_regnode_set_voltage() can now fail before setting it.
Tested on: A64, H6
---
sys/arm/allwinner/axp81x.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/sys/arm/allwinner/axp81x.c b/sys/arm/allwinner/axp81x.c
index cbdc147585f8..63e6e06cc6d0 100644
--- a/sys/arm/allwinner/axp81x.c
+++ b/sys/arm/allwinner/axp81x.c
@@ -758,6 +758,7 @@ axp8xx_regnode_init(struct regnode *regnode)
struct regnode_std_param *param;
int rv, udelay;
+ udelay = 0;
param = regnode_get_stdparam(regnode);
if (param->min_uvolt == 0)
return (0);
@@ -781,6 +782,7 @@ axp8xx_regnode_enable(struct regnode *regnode, bool enable, int *udelay)
struct axp8xx_softc *asc;
struct axp8xx_reg_sc *sc;
uint8_t val;
+ int error;
sc = regnode_get_softc(regnode);
asc = device_get_softc(sc->base_dev);
@@ -793,7 +795,11 @@ axp8xx_regnode_enable(struct regnode *regnode, bool enable, int *udelay)
/* The regulators share the enable registers */
sx_xlock(&asc->reglock);
- axp8xx_read(sc->base_dev, sc->def->enable_reg, &val, 1);
+ if (axp8xx_read(sc->base_dev, sc->def->enable_reg, &val, 1) != 0) {
+ /* Do not write back a value we do not know */
+ sx_xunlock(&asc->reglock);
+ return (EIO);
+ }
val &= ~sc->def->enable_mask;
if (enable)
val |= sc->def->enable_value;
@@ -803,8 +809,10 @@ axp8xx_regnode_enable(struct regnode *regnode, bool enable, int *udelay)
else
val &= ~sc->def->enable_value;
}
- axp8xx_write(sc->base_dev, sc->def->enable_reg, val);
+ error = axp8xx_write(sc->base_dev, sc->def->enable_reg, val);
sx_xunlock(&asc->reglock);
+ if (error != 0)
+ return (EIO);
*udelay = 0;
@@ -859,7 +867,8 @@ axp8xx_regnode_status(struct regnode *regnode, int *status)
sc = regnode_get_softc(regnode);
*status = 0;
- axp8xx_read(sc->base_dev, sc->def->enable_reg, &val, 1);
+ if (axp8xx_read(sc->base_dev, sc->def->enable_reg, &val, 1) != 0)
+ return (EIO);
if (val & sc->def->enable_mask)
*status = REGULATOR_STATUS_ENABLED;
@@ -887,7 +896,8 @@ axp8xx_regnode_set_voltage(struct regnode *regnode, int min_uvolt,
if (axp8xx_regnode_voltage_to_reg(sc, min_uvolt, max_uvolt, &val) != 0)
return (ERANGE);
- axp8xx_write(sc->base_dev, sc->def->voltage_reg, val);
+ if (axp8xx_write(sc->base_dev, sc->def->voltage_reg, val) != 0)
+ return (EIO);
*udelay = 0;
@@ -905,7 +915,8 @@ axp8xx_regnode_get_voltage(struct regnode *regnode, int *uvolt)
if (!sc->def->voltage_step1 || !sc->def->voltage_step2)
return (ENXIO);
- axp8xx_read(sc->base_dev, sc->def->voltage_reg, &val, 1);
+ if (axp8xx_read(sc->base_dev, sc->def->voltage_reg, &val, 1) != 0)
+ return (EIO);
axp8xx_regnode_reg_to_voltage(sc, val & AXP_VOLTCTL_MASK, uvolt);
return (0);