mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] mfd: gateworks-gsc: Propagate I2C read errors
@ 2026-11-09 11:14 shao.mingyin
  2026-11-18 20:37 ` Lee Jones
  0 siblings, 1 reply; 2+ messages in thread
From: shao.mingyin @ 2026-11-09 11:14 UTC (permalink / raw)
  To: lee, mfd; +Cc: tharvey, linux-kernel

From: Shao Mingyin <shao.mingyin@zte.com.cn>

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@zte.com.cn>
---
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@zte.com.cn/
v1: https://lore.kernel.org/all/20261107162125044ldKkwYPQxZOTWg6IDe_LX@zte.com.cn/

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, &reg);
+	if (regmap_read(gsc->regmap, GSC_FW_CRC, &reg))
+		return -EIO;
 	gsc->fwcrc = reg;
-	regmap_read(gsc->regmap, GSC_FW_CRC + 1, &reg);
+	if (regmap_read(gsc->regmap, GSC_FW_CRC + 1, &reg))
+		return -EIO;
 	gsc->fwcrc |= reg << 8;
 
 	gsc->i2c_hwmon = devm_i2c_new_dummy_device(dev, client->adapter,
-- 
2.47.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18 20:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 11:14 [PATCH v3] mfd: gateworks-gsc: Propagate I2C read errors shao.mingyin
2026-11-18 20:37 ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®