Skip to contentSkip to conversation

regulator: fixed: Use devm_regulator_register

PATCH In review Manish Badarkhe 3 participants 4 messages Jan 25, 2014 – Jan 27, 2014

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

PATCH 1/1 regulator: fixed: Use devm_regulator_register

Use "devm_regulator_register" instead of "regulator_register" which simplifies the code.

---
:100644 100644 5ea64b9... 6d32341... M drivers/regulator/fixed.c

 drivers/regulator/fixed.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/fixed.c +2 -2
index 5ea64b9..6d32341 100644
@@ -186,7 +186,8 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
 	cfg.driver_data = drvdata;
 	cfg.of_node = pdev->dev.of_node;
 
-	drvdata->dev = regulator_register(&drvdata->desc, &cfg);
+	drvdata->dev = devm_regulator_register(&pdev->dev, &drvdata->desc,
+					       &cfg);
 	if (IS_ERR(drvdata->dev)) {
 		ret = PTR_ERR(drvdata->dev);
 		dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
@@ -212,7 +213,6 @@ static int reg_fixed_voltage_remove(struct platform_device *pdev)
 {
 	struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev);
 
-	regulator_unregister(drvdata->dev);
 	kfree(drvdata->desc.supply_name);
 	kfree(drvdata->desc.name);
 
Signature · 1 line
1.7.10.4
#1 lore raw

Hi Manish,

Quoted 2 lines · Manish Badarkhe

Use "devm_regulator_register" instead of "regulator_register" which simplifies the code.

... and also breaks the driver: now you are freeing desc->name and desc->supply_name while regulator structures are still alive and can be referenced from its sysfs attributes, etc.

Quoted 22 lines

---
:100644 100644 5ea64b9... 6d32341... M drivers/regulator/fixed.c

 drivers/regulator/fixed.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/fixed.c +2 -1
index 5ea64b9..6d32341 100644
@@ -186,7 +186,8 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
 	cfg.driver_data = drvdata;
 	cfg.of_node = pdev->dev.of_node;
 
-	drvdata->dev = regulator_register(&drvdata->desc, &cfg);
+	drvdata->dev = devm_regulator_register(&pdev->dev, &drvdata->desc,
+					       &cfg);
 	if (IS_ERR(drvdata->dev)) {
 		ret = PTR_ERR(drvdata->dev);
 		dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);

drivers/regulator/fixed.c static int reg_fixed_voltage_remove(struct platform_device *pdev) · line 218

Quoted 7 lines
drivers/regulator/fixed.c +0 -1
@@ -212,7 +213,6 @@ static int reg_fixed_voltage_remove(struct platform_device *pdev)
 {
 	struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev);
 
-	regulator_unregister(drvdata->dev);
 	kfree(drvdata->desc.supply_name);
 	kfree(drvdata->desc.name);
 

Thanks.

Signature · 1 line
Dmitry
maintainer
#2 lore raw
Quoted 8 lines · Dmitry Torokhov
Quoted 2 lines · Manish Badarkhe

Use "devm_regulator_register" instead of "regulator_register" which simplifies the code.

... and also breaks the driver: now you are freeing desc->name and desc->supply_name while regulator structures are still alive and can be referenced from its sysfs attributes, etc.

Yup, they need to be converted to managed allocations too if the regulator_register() is going to be converted (see previous discussions on similar patches). It would be good to do so.

#3 lore raw

Hi

Quoted 6 lines · Mark Brown
Quoted 4 lines · Dmitry Torokhov
Quoted 2 lines · Manish Badarkhe

Use "devm_regulator_register" instead of "regulator_register" which simplifies the code.

Quoted 7 lines
Quoted 3 lines

... and also breaks the driver: now you are freeing desc->name and desc->supply_name while regulator structures are still alive and can be referenced from its sysfs attributes, etc.

Yup, they need to be converted to managed allocations too if the regulator_register() is going to be converted (see previous discussions on similar patches). It would be good to do so.

Thank you for pointing this out.
I missed to convert these two " desc->name" and "desc->supply_name" to manage allocation. I will modify code and repost patch.

Regards
Manish Badarkhe