[PATCH v3] mfd: gateworks-gsc: Propagate I2C read errors
From: shao.mingyin
Date: Mon Nov 09 2026 - 06:16:32 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, so the FW_VER check in gsc_probe() and the two
GSC_FW_CRC checks that this patch adds 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 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.
v3:
- reword the commit message: the two GSC_FW_CRC checks are added by this
patch, so say that instead of referring to "the previous version"; the
second paragraph no longer calls them pre-existing. No code change
v2: https://lore.kernel.org/all/20261108151125513PyebyF3QC3r_DTxS9ZMf6@xxxxxxxxxx/
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