Skip to contentSkip to conversation

i2c: i2c-mux-reg: wrong condition checked for of_address_to_resource return value

PATCH Superseded Lukasz Gemborowski 2 participants 4 messages Jun 27, 2016 – Jul 5, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: i2c-mux-reg: wrong condition checked for of_address_to_resource return value

of_address_to_resource return 0 on successful call but devm_ioremap_resource is called only if it returns non-zero value

---
 drivers/i2c/muxes/i2c-mux-reg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/muxes/i2c-mux-reg.c +1 -1
index 26e7c51..012a7ab 100644
@@ -145,7 +145,7 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux,
 		mux->data.idle_in_use = true;
 
 	/* map address from "reg" if exists */
-	if (of_address_to_resource(np, 0, &res)) {
+	if (!of_address_to_resource(np, 0, &res)) {
 		mux->data.reg_size = resource_size(&res);
 		mux->data.reg = devm_ioremap_resource(&pdev->dev, &res);
 		if (IS_ERR(mux->data.reg))
Signature · 1 line
2.5.0
#1 lore raw
Quoted 14 lines · Lukasz Gemborowski

of_address_to_resource return 0 on successful call but devm_ioremap_resource is called only if it returns non-zero value

---
 drivers/i2c/muxes/i2c-mux-reg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/muxes/i2c-mux-reg.c +0 -0
index 26e7c51..012a7ab 100644

drivers/i2c/muxes/i2c-mux-reg.c static int i2c_mux_reg_probe_dt(struct regmux *mux, · line 148

Quoted 5 lines
drivers/i2c/muxes/i2c-mux-reg.c +1 -1
@@ -145,7 +145,7 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux,
 		mux->data.idle_in_use = true;
 
 	/* map address from "reg" if exists */
-	if (of_address_to_resource(np, 0, &res)) {
+	if (!of_address_to_resource(np, 0, &res)) {

Minor nit: I prefer '== 0' in those cases to prevent the misleading reading of "if not of_address_to_resource...". '== 0' can be easier read as 'is OK'.

#2 lore raw

PATCH v2 1/1 i2c: i2c-mux-reg: wrong condition checked for of_address_to_resource return value

of_address_to_resource return 0 on successful call but devm_ioremap_resource is called only if it returns non-zero value

---
Changelog:
v2:
Changed style of conditional expression as suggested by Wolfram.

 drivers/i2c/muxes/i2c-mux-reg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/muxes/i2c-mux-reg.c +1 -1
index 26e7c51..c6a90b4 100644
@@ -145,7 +145,7 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux,
 		mux->data.idle_in_use = true;
 
 	/* map address from "reg" if exists */
-	if (of_address_to_resource(np, 0, &res)) {
+	if (of_address_to_resource(np, 0, &res) == 0) {
 		mux->data.reg_size = resource_size(&res);
 		mux->data.reg = devm_ioremap_resource(&pdev->dev, &res);
 		if (IS_ERR(mux->data.reg))
Signature · 1 line
2.5.0