[PATCH v2] mfd: gateworks-gsc: Propagate I2C read errors
From: shao.mingyin
Date: Sun Nov 08 2026 - 02:11:45 EST
From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
gsc_read() retries the I2C transfer but then stores "ret & 0xff" in *val
and returns 0 even when the transfer failed. regmap_read() therefore
never reports an error: the FW_VER check in gsc_probe() and the two
GSC_FW_CRC checks added by the previous version are dead code, and on a
failed read the firmware revision is built from the low byte of the
negative errno.
Return the error from gsc_read() before touching *val, so regmap_read()
and its callers see the failure; the existing FW_VER check and the two
CRC checks then work as intended.
Fixes: d85234994b2f ("mfd: Add Gateworks System Controller core driver")
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
This supersedes 5/5 of the RESEND series; 1/5-4/5 are unchanged.
v2:
- report the failure of the I2C transfer from gsc_read() itself; without
it the pre-existing FW_VER check and the two GSC_FW_CRC checks added by
v1 are dead code
v1: https://lore.kernel.org/all/20261107162125044ldKkwYPQxZOTWg6IDe_LX@xxxxxxxxxx/
diff --git a/drivers/mfd/gateworks-gsc.c b/drivers/mfd/gateworks-gsc.c
--- 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;
}
@@ -219,9 +222,11 @@ static int gsc_probe(struct i2c_client *client)
return -EIO;
gsc->fwver = reg;
- regmap_read(gsc->regmap, GSC_FW_CRC, ®);
+ if (regmap_read(gsc->regmap, GSC_FW_CRC, ®))
+ return -EIO;
gsc->fwcrc = reg;
- regmap_read(gsc->regmap, GSC_FW_CRC + 1, ®);
+ if (regmap_read(gsc->regmap, GSC_FW_CRC + 1, ®))
+ return -EIO;
gsc->fwcrc |= reg << 8;
gsc->i2c_hwmon = devm_i2c_new_dummy_device(dev, client->adapter,
--
2.47.0