Skip to contentSkip to conversation

i2c: k1: Initialize variable before use

PATCH In review Andi Shyti 2 participants 2 messages Mar 20, 2025 – Mar 24, 2025

Subsystems (2)
lore
Share & tools
lore

Andi Shyti

author maintainer
#0 lore raw

PATCH 1/1 i2c: k1: Initialize variable before use

Commit 95a8ca229032 ("i2c: spacemit: add support for SpacemiT K1 SoC") introduced a check in the probe function to warn the user if the DTS has incorrect frequency settings. In such cases, the driver falls back to default values.

However, the return value of of_property_read_u32() was not stored, making the check ineffective. Fix this by storing the return value in 'ret' and evaluating it properly.

---
Cc: Alex Elder <[email protected]>

 drivers/i2c/busses/i2c-k1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-k1.c +1 -1
index 0d8763b852db..5965b4cf6220 100644
@@ -514,7 +514,7 @@ static int spacemit_i2c_probe(struct platform_device *pdev)
 	if (!i2c)
 		return -ENOMEM;
 
-	of_property_read_u32(of_node, "clock-frequency", &i2c->clock_freq);
+	ret = of_property_read_u32(of_node, "clock-frequency", &i2c->clock_freq);
 	if (ret && ret != -EINVAL)
 		dev_warn(dev, "failed to read clock-frequency property: %d\n", ret);
 
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Andi Shyti

Commit 95a8ca229032 ("i2c: spacemit: add support for SpacemiT K1 SoC") introduced a check in the probe function to warn the user if the DTS has incorrect frequency settings. In such cases, the driver falls back to default values.

Quoted 8 lines

However, the return value of of_property_read_u32() was not stored, making the check ineffective. Fix this by storing the return value in 'ret' and evaluating it properly.

This landed in my junk folder for some reason. I noticed this on an earlier version but didn't check in v8. The fix looks good (in case you haven't already applied it).

Quoted 19 lines

---
Cc: Alex Elder <[email protected]>

  drivers/i2c/busses/i2c-k1.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-k1.c +1 -1
index 0d8763b852db..5965b4cf6220 100644
@@ -514,7 +514,7 @@ static int spacemit_i2c_probe(struct platform_device *pdev)
  	if (!i2c)
  		return -ENOMEM;
 
-	of_property_read_u32(of_node, "clock-frequency", &i2c->clock_freq);
+	ret = of_property_read_u32(of_node, "clock-frequency", &i2c->clock_freq);
  	if (ret && ret != -EINVAL)
  		dev_warn(dev, "failed to read clock-frequency property: %d\n", ret);