[PATCH v4] mfd: gateworks-gsc: Propagate I2C read errors
From: shao.mingyin
Date: Thu Nov 26 2026 - 22:54:24 EST
gsc_read() retries the SMBus read, but reports success and returns the
low byte of a negative errno if it ultimately fails. The MFD probe can
record an incorrect firmware version or CRC, and the hwmon driver can
convert the error byte into a sensor reading.
Return the error from gsc_read() before writing the output value. Have
gsc_probe() check the version and both CRC reads and return the original
error before registering the IRQ and child devices.
Fixes: d85234994b2f ("mfd: Add Gateworks System Controller core driver")
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
Changes in v4:
- Return the underlying errno from all three firmware reads.
Previous version: https://lore.kernel.org/all/202611091914028089L4I88l9WGcWziY8r3qZb@xxxxxxxxxx/
Build-tested on Linux-next next-20261118 with GCC 13.3.0 for x86_64.
drivers/mfd/gateworks-gsc.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/drivers/mfd/gateworks-gsc.c b/drivers/mfd/gateworks-gsc.c
index c034d54354f4..f3d44b775b5e 100644
--- a/drivers/mfd/gateworks-gsc.c
+++ b/drivers/mfd/gateworks-gsc.c
@@ -62,7 +62,10 @@ int gsc_read(void *context, unsigned int reg, unsigned int *val)
if (ret != -EAGAIN && ret != -EIO)
break;
}
- *val = ret & 0xff;
+ if (ret < 0)
+ return ret;
+
+ *val = ret;
return 0;
}
@@ -215,13 +218,19 @@ static int gsc_probe(struct i2c_client *client)
if (IS_ERR(gsc->regmap))
return PTR_ERR(gsc->regmap);
- if (regmap_read(gsc->regmap, GSC_FW_VER, ®))
- return -EIO;
+ ret = regmap_read(gsc->regmap, GSC_FW_VER, ®);
+ if (ret)
+ return ret;
gsc->fwver = reg;
- regmap_read(gsc->regmap, GSC_FW_CRC, ®);
+ ret = regmap_read(gsc->regmap, GSC_FW_CRC, ®);
+ if (ret)
+ return ret;
gsc->fwcrc = reg;
- regmap_read(gsc->regmap, GSC_FW_CRC + 1, ®);
+
+ ret = regmap_read(gsc->regmap, GSC_FW_CRC + 1, ®);
+ if (ret)
+ return ret;
gsc->fwcrc |= reg << 8;
gsc->i2c_hwmon = devm_i2c_new_dummy_device(dev, client->adapter,
base-commit: e8017d29067fd1310a65c3494ce1a1b492adbac6
--
2.43.0