Skip to contentSkip to conversation

regulator: max14577: Fix invalid return value on DT parse success

PATCH Superseded Krzysztof Kozlowski 2 participants 5 messages Feb 20, 2014 – Feb 21, 2014

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regulator: max14577: Fix invalid return value on DT parse success

This fixes bug introduced in 667a6b7a (regulator: max14577: Add missing of_node_put). The DTS parsing function returned number of matched regulators as success status which then was compared against 0 in probe.

Result was a probe fail after successful parsing the DTS:
max14577-regulator: probe of max14577-regulator failed with error 2

---
 drivers/regulator/max14577.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/regulator/max14577.c +3 -1
index 186df8785a91..6ba11a8dd23d 100644
@@ -168,11 +168,13 @@ static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
 			MAX14577_REG_MAX);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);
+		of_node_put(np);
+		return ret;
 	}
 
 	of_node_put(np);
 
-	return ret;
+	return 0;
 }
 
 static inline struct regulator_init_data *match_init_data(int index)
Signature · 1 line
1.7.9.5
#1 lore raw

Hi Krzysztof,

Quoted 19 lines · Krzysztof Kozlowski

This fixes bug introduced in 667a6b7a (regulator: max14577: Add missing of_node_put). The DTS parsing function returned number of matched regulators as success status which then was compared against 0 in probe.

Result was a probe fail after successful parsing the DTS:
max14577-regulator: probe of max14577-regulator failed with error 2

---
 drivers/regulator/max14577.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/regulator/max14577.c +0 -0
index 186df8785a91..6ba11a8dd23d 100644
@@ -168,11 +168,13 @@ static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
                        MAX14577_REG_MAX);
        if (ret < 0) {

drivers/regulator/max14577.c static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev) · line 178

Quoted 10 lines
drivers/regulator/max14577.c +3 -1
                dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);
+               of_node_put(np);
+               return ret;
        }
 
        of_node_put(np);
 
-       return ret;
+       return 0;
 }

Instead of so many changes here, you could simply make the following change in the max14577_regulator_probe function.

ret = max14577_regulator_dt_parse_pdata(pdev);
if (ret < 0)

        return ret;
Signature · 2 lines
With warm regards,
Sachin
#2 lore raw
Quoted 36 lines · Sachin Kamat

Hi Krzysztof,

Quoted 19 lines · Krzysztof Kozlowski

This fixes bug introduced in 667a6b7a (regulator: max14577: Add missing of_node_put). The DTS parsing function returned number of matched regulators as success status which then was compared against 0 in probe.

Result was a probe fail after successful parsing the DTS:
max14577-regulator: probe of max14577-regulator failed with error 2

---
 drivers/regulator/max14577.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/regulator/max14577.c +0 -0
index 186df8785a91..6ba11a8dd23d 100644
@@ -168,11 +168,13 @@ static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
                        MAX14577_REG_MAX);
        if (ret < 0) {

drivers/regulator/max14577.c static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev) · line 178

Quoted 10 lines
drivers/regulator/max14577.c +3 -1
                dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);
+               of_node_put(np);
+               return ret;
        }
 
        of_node_put(np);
 
-       return ret;
+       return 0;
 }

Instead of so many changes here, you could simply make the following change in the max14577_regulator_probe function.

Quoted 3 lines

ret = max14577_regulator_dt_parse_pdata(pdev);
if (ret < 0)

        return ret;

That still wouldn't be sufficient because later in probe() the 'ret' is not reassigned (if devm_regulator_register succeeds) and it is directly returned at the probe() end. So still the number of matched regulators would be returned as probe result.

Best regards,
Krzysztof

#3 lore raw
Quoted 37 lines · Krzysztof Kozlowski
Quoted 36 lines · Sachin Kamat

Hi Krzysztof,

Quoted 19 lines · Krzysztof Kozlowski

This fixes bug introduced in 667a6b7a (regulator: max14577: Add missing of_node_put). The DTS parsing function returned number of matched regulators as success status which then was compared against 0 in probe.

Result was a probe fail after successful parsing the DTS:
max14577-regulator: probe of max14577-regulator failed with error 2

---
 drivers/regulator/max14577.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/regulator/max14577.c +0 -0
index 186df8785a91..6ba11a8dd23d 100644
@@ -168,11 +168,13 @@ static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
                        MAX14577_REG_MAX);
        if (ret < 0) {

drivers/regulator/max14577.c static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev) · line 178

Quoted 10 lines
drivers/regulator/max14577.c +3 -1
                dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);
+               of_node_put(np);
+               return ret;
        }
 
        of_node_put(np);
 
-       return ret;
+       return 0;
 }

Instead of so many changes here, you could simply make the following change in the max14577_regulator_probe function.

Quoted 8 lines
Quoted 3 lines

ret = max14577_regulator_dt_parse_pdata(pdev);
if (ret < 0)

        return ret;

That still wouldn't be sufficient because later in probe() the 'ret' is not reassigned (if devm_regulator_register succeeds) and it is directly returned at the probe() end. So still the number of matched regulators would be returned as probe result.

Ah, you are right. In that case how about the following:

- if (ret < 0) {
+ if (ret < 0)

      dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);

- }
+ else
+ ret = 0;

I am just trying to see if we can avoid any code duplication.

Signature · 2 lines
With warm regards,
Sachin
#4 lore raw
Quoted 56 lines · Sachin Kamat
Quoted 37 lines · Krzysztof Kozlowski
Quoted 36 lines · Sachin Kamat

Hi Krzysztof,

Quoted 19 lines · Krzysztof Kozlowski

This fixes bug introduced in 667a6b7a (regulator: max14577: Add missing of_node_put). The DTS parsing function returned number of matched regulators as success status which then was compared against 0 in probe.

Result was a probe fail after successful parsing the DTS:
max14577-regulator: probe of max14577-regulator failed with error 2

---
 drivers/regulator/max14577.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/regulator/max14577.c +0 -0
index 186df8785a91..6ba11a8dd23d 100644
@@ -168,11 +168,13 @@ static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
                        MAX14577_REG_MAX);
        if (ret < 0) {

drivers/regulator/max14577.c static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev) · line 178

Quoted 10 lines
drivers/regulator/max14577.c +3 -1
                dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);
+               of_node_put(np);
+               return ret;
        }
 
        of_node_put(np);
 
-       return ret;
+       return 0;
 }

Instead of so many changes here, you could simply make the following change in the max14577_regulator_probe function.

Quoted 8 lines
Quoted 3 lines

ret = max14577_regulator_dt_parse_pdata(pdev);
if (ret < 0)

        return ret;

That still wouldn't be sufficient because later in probe() the 'ret' is not reassigned (if devm_regulator_register succeeds) and it is directly returned at the probe() end. So still the number of matched regulators would be returned as probe result.

Ah, you are right. In that case how about the following:

(quoted diff) +3 -2
-  if (ret < 0) {
+ if (ret < 0)
      dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);
-  }
+ else
+      ret = 0;
Quoted 1 line

I am just trying to see if we can avoid any code duplication.

Looks good. Thanks for idea, I'll send v2.

Best regards,
Krzysztof