summaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-05-02 17:17:56 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2024-05-03 08:50:35 +0200
commit6d42b2827243ab7b7bfb854a579cbda09714f6ac (patch)
tree188950d0d3a4af8e2cddb2d834a37cf8ef23359c /drivers/net
parent372d21e79e308df7ca41fc03439872edebfab16a (diff)
downloadbarebox-6d42b2827243ab7b7bfb854a579cbda09714f6ac.tar.gz
barebox-6d42b2827243ab7b7bfb854a579cbda09714f6ac.tar.xz
net: dsa: ksz9477: report 0 as value when returning error
Most register accesses via the ksz_read* functions don't expect that they can fail and don't check for an error. This assumption is wrong if there is a problem with the underlying transport, e.g. an I2C bus. In that case, the functions would return an error code that mostly goes unchecked and *val is set to an uninitialized value. The original Linux driver suffers from a similar problem: There, *val is only set on success, but if the read fails, there's a warning printed to log, but still the uninitialized variable in the caller function will be used instead. This likely goes unnoticed, because GCC builds on Linux have -Wno-maybe-uninitialized, but we have implicit -W-maybe-uninitialized in barebox. As we sync the code from Linux, one should probably fix this there first, but let's improve the situation a bit by not reporting an uninitialized value, but a deterministic zero. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240502151757.3964461-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/ksz_common.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/net/ksz_common.h b/drivers/net/ksz_common.h
index 291488fe34..44b5055ee3 100644
--- a/drivers/net/ksz_common.h
+++ b/drivers/net/ksz_common.h
@@ -20,7 +20,7 @@ struct ksz_switch {
static inline int ksz_read8(struct ksz_switch *priv, u32 reg, u8 *val)
{
- unsigned int value;
+ unsigned int value = 0;
int ret = regmap_read(priv->regmap[0], reg, &value);
*val = value;
@@ -29,7 +29,7 @@ static inline int ksz_read8(struct ksz_switch *priv, u32 reg, u8 *val)
static inline int ksz_read16(struct ksz_switch *priv, u32 reg, u16 *val)
{
- unsigned int value;
+ unsigned int value = 0;
int ret = regmap_read(priv->regmap[1], reg, &value);
*val = value;
@@ -38,7 +38,7 @@ static inline int ksz_read16(struct ksz_switch *priv, u32 reg, u16 *val)
static inline int ksz_read32(struct ksz_switch *priv, u32 reg, u32 *val)
{
- unsigned int value;
+ unsigned int value = 0;
int ret = regmap_read(priv->regmap[2], reg, &value);
*val = value;