Skip to contentSkip to conversation

regulator: anatop-regulator: Remove unneeded check

PATCH NAK Fabio Estevam 3 participants 5 messages Dec 20, 2013 – Dec 21, 2013 Voltage and current regulator framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 regulator: anatop-regulator: Remove unneeded check

From: Fabio Estevam <[email protected]>

At the 'anatop_probe_end' error path, the variable 'ret' is known to be non-zero, so there is no need to check it.

---
 drivers/regulator/anatop-regulator.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/regulator/anatop-regulator.c +1 -2
index c734d09..0a3597b 100644
@@ -211,8 +211,7 @@ static int anatop_regulator_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, rdev);
 
 anatop_probe_end:
-	if (ret)
-		kfree(sreg->name);
+	kfree(sreg->name);
 
 	return ret;
 }
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH 2/2 regulator: anatop-regulator: Remove unneeded variable

From: Fabio Estevam <[email protected]>

There is no need to create a local variable for accessing sreg->name.

Access it directly instead.

---
 drivers/regulator/anatop-regulator.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/regulator/anatop-regulator.c +1 -2
index 0a3597b..7d7c05e 100644
@@ -220,9 +220,8 @@ static int anatop_regulator_remove(struct platform_device *pdev)
 {
 	struct regulator_dev *rdev = platform_get_drvdata(pdev);
 	struct anatop_regulator *sreg = rdev_get_drvdata(rdev);
-	const char *name = sreg->name;
 
-	kfree(name);
+	kfree(sreg->name);
 
 	return 0;
 }
Signature · 1 line
1.8.1.2
#2 lore raw
In reply to Fabio Estevam
Quoted 15 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

At the 'anatop_probe_end' error path, the variable 'ret' is known to be non-zero, so there is no need to check it.

---
 drivers/regulator/anatop-regulator.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/regulator/anatop-regulator.c +0 -0
index c734d09..0a3597b 100644

drivers/regulator/anatop-regulator.c static int anatop_regulator_probe(struct platform_device *pdev) · line 214

Quoted 6 lines
drivers/regulator/anatop-regulator.c +1 -2
@@ -211,8 +211,7 @@ static int anatop_regulator_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, rdev);
 
 anatop_probe_end:
-	if (ret)
-		kfree(sreg->name);
+	kfree(sreg->name);

NAK

With the change, a successful probe will end up with calling this kfree() as well.

Shawn

Quoted 6 lines
drivers/regulator/anatop-regulator.c +0 -0
 	return ret;
 }
Signature · 1 line
1.8.1.2
#3 lore raw
Quoted 25 lines · Shawn Guo
Quoted 15 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

At the 'anatop_probe_end' error path, the variable 'ret' is known to be non-zero, so there is no need to check it.

---
 drivers/regulator/anatop-regulator.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/regulator/anatop-regulator.c +0 -0
index c734d09..0a3597b 100644

drivers/regulator/anatop-regulator.c static int anatop_regulator_probe(struct platform_device *pdev) · line 214

Quoted 6 lines
drivers/regulator/anatop-regulator.c +1 -2
@@ -211,8 +211,7 @@ static int anatop_regulator_probe(struct platform_device *pdev)
      platform_set_drvdata(pdev, rdev);
 
 anatop_probe_end:
-     if (ret)
-             kfree(sreg->name);
+     kfree(sreg->name);

NAK

Quoted 2 lines

With the change, a successful probe will end up with calling this kfree() as well.

I see. Then we can do this instead, so that the successful probe and the error path are clearer:

drivers/regulator/anatop-regulator.c +3 -2
@@ -210,9 +210,10 @@ static int anatop_regulator_probe(struct platform_device *p
 
        platform_set_drvdata(pdev, rdev);
 
+       return 0;
+
 anatop_probe_end:
-       if (ret)
-               kfree(sreg->name);
+       kfree(sreg->name);
 
        return ret;
 }

Regards,

Fabio Estevam

maintainer
#4 lore raw
Quoted 2 lines · Fabio Estevam

I see. Then we can do this instead, so that the successful probe and the error path are clearer:

Yes, that's going to cause fewer surprises.