regulator: fixed: update to devm_* API
PATCH v2 1/1 regulator: fixed: update to devm_* API
Update the code to use devm_* API so that driver core will manage resources.
---
Changes since V1:
1. Updated driver to use "devm_kzalloc" to "kstrdup".
2. Updated commit message.
Not tested on any board.
:100644 100644 5ea64b9... e9763a4... M drivers/regulator/fixed.c
drivers/regulator/fixed.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-)
drivers/regulator/fixed.c +12 -30
@@ -132,15 +132,15 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) GFP_KERNEL);if (drvdata ==NULL ) {dev_err (&pdev->dev,"Failed to allocate device data\n" ); - ret = -ENOMEM ; - goto err; +return -ENOMEM ; } - drvdata->desc.name =kstrdup (config->supply_name,GFP_KERNEL ); + drvdata->desc.name =devm_kzalloc (&pdev->dev, +strlen (config->supply_name) +1 , +GFP_KERNEL );if (drvdata->desc.name ==NULL ) {dev_err (&pdev->dev,"Failed to allocate supply name\n" ); - ret = -ENOMEM ; - goto err; +return -ENOMEM ; } drvdata->desc.type =REGULATOR_VOLTAGE ; drvdata->desc.owner =THIS_MODULE ;
@@ -149,13 +149,13 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) drvdata->desc.enable_time = config->startup_delay;if (config->input_supply) { - drvdata->desc.supply_name =kstrdup (config->input_supply, -GFP_KERNEL ); + drvdata->desc.supply_name =devm_kzalloc (&pdev->dev, +strlen (config->input_supply) +1 , +GFP_KERNEL );if (!drvdata->desc.supply_name) {dev_err (&pdev->dev,"Failed to allocate input supply\n" ); - ret = -ENOMEM ; - goto err_name; +return -ENOMEM ; } }
@@ -186,11 +186,12 @@ 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); - goto err_input; +return ret; }platform_set_drvdata (pdev, drvdata);
@@ -199,24 +200,6 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) drvdata->desc.fixed_uV);return 0 ; - -err_input: -kfree (drvdata->desc.supply_name); -err_name: -kfree (drvdata->desc.name); -err: -return ret; -} - -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); - -return 0 ; }#if defined(CONFIG_OF )
@@ -229,7 +212,6 @@ MODULE_DEVICE_TABLE(of, fixed_of_match);static struct platform_driver regulator_fixed_voltage_driver = { .probe = reg_fixed_voltage_probe, - .remove = reg_fixed_voltage_remove, .driver = { .name ="reg-fixed-voltage" , .owner =THIS_MODULE ,
Signature · 1 line
1.7.10.4
Hi Manish,
Quoted 28 lines · Manish Badarkhe
Update the code to use devm_* API so that driver core will manage resources.
Signed-off-by Manish Badarkhe <[email protected]>---
Changes since V1:
1. Updated driver to use "devm_kzalloc" to "kstrdup".
2. Updated commit message.Not tested on any board.
:100644 100644 5ea64b9... e9763a4... M
drivers/regulator/fixed.cdrivers/regulator/fixed.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-)drivers/regulator/fixed.c +1
-2@@ -132,15 +132,15 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) GFP_KERNEL);if (drvdata ==NULL ) {dev_err (&pdev->dev,"Failed to allocate device data\n" ); - ret = -ENOMEM ; - goto err; +return -ENOMEM ; }
drivers/regulator/fixed.c static int reg_fixed_voltage_probe(struct platform_device *pdev) · line 144
Quoted 10 lines
drivers/regulator/fixed.c +4
-3- drvdata->desc.name =kstrdup (config->supply_name,GFP_KERNEL ); + drvdata->desc.name =devm_kzalloc (&pdev->dev, +strlen (config->supply_name) +1 , +GFP_KERNEL );if (drvdata->desc.name ==NULL ) {dev_err (&pdev->dev,"Failed to allocate supply name\n" ); - ret = -ENOMEM ; - goto err; +return -ENOMEM ; }
Umm, I am fairly certain that devm_kzalloc() can't be used as a substitute for kstrdup, at least not without accompanying memcpy.
Thanks.
Signature · 1 line
Dmitry
Hi Dmitry,
Thank you for your review.
Quoted 31 lines · Dmitry Torokhov
Hi Manish,
Quoted 28 lines · Manish Badarkhe
Update the code to use devm_* API so that driver core will manage resources.
Signed-off-by Manish Badarkhe <[email protected]>---
Changes since V1:
1. Updated driver to use "devm_kzalloc" to "kstrdup".
2. Updated commit message.Not tested on any board.
:100644 100644 5ea64b9... e9763a4... M
drivers/regulator/fixed.cdrivers/regulator/fixed.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-)drivers/regulator/fixed.c +1
-2@@ -132,15 +132,15 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) GFP_KERNEL);if (drvdata ==NULL ) {dev_err (&pdev->dev,"Failed to allocate device data\n" ); - ret = -ENOMEM ; - goto err; +return -ENOMEM ; }
Quoted 13 lines
drivers/regulator/fixed.c static int reg_fixed_voltage_probe(struct platform_device *pdev) · line 144
Quoted 10 lines
drivers/regulator/fixed.c +4
-3- drvdata->desc.name =kstrdup (config->supply_name,GFP_KERNEL ); + drvdata->desc.name =devm_kzalloc (&pdev->dev, +strlen (config->supply_name) +1 , +GFP_KERNEL );if (drvdata->desc.name ==NULL ) {dev_err (&pdev->dev,"Failed to allocate supply name\n" ); - ret = -ENOMEM ; - goto err; +return -ENOMEM ; }Umm, I am fairly certain that
devm_kzalloc()can't be used as a substitute for kstrdup, at least not without accompanying memcpy.
Yes, I have provided allocation but it should be followed with assignment. Can I modify like this,
+ drvdata->desc.name = devm_kzalloc(&pdev->dev,
+ strlen(config->supply_name) + 1,
+ GFP_KERNEL);
+ if (drvdata->desc.name)
+ sprintf(drvdata->desc.name, "%s", config->supply_name);
Thanks
Manish Badakhe
Quoted 66 lines · On Tuesday, 28. January 2014 12:46:01 Manish Badarkhe wrote:
Hi Dmitry,
Thank you for your review.
On Tue, Jan 28, 2014 at 12:03 PM, Dmitry Torokhov
Quoted 47 lines · <[email protected]> wrote:
Hi Manish,
Quoted 44 lines · Manish Badarkhe
Update the code to use devm_* API so that driver core will manage resources.
Signed-off-by Manish Badarkhe <[email protected]>---
Changes since V1:
1. Updated driver to use "devm_kzalloc" to "kstrdup".
2. Updated commit message.Not tested on any board.
:100644 100644 5ea64b9... e9763a4... M
drivers/regulator/fixed.c
:drivers/regulator/fixed.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-)drivers/regulator/fixed.c +0
-0@@ -132,15 +132,15 @@ static int reg_fixed_voltage_probe(struct
platform_device*pdev)>>GFP_KERNEL); if (drvdata == NULL) { dev_err(&pdev->dev, "Failed to allocate device data\n");drivers/regulator/fixed.c +4
-3- ret = -ENOMEM ; - goto err; +return -ENOMEM ; } - drvdata->desc.name =kstrdup (config->supply_name,GFP_KERNEL ); + drvdata->desc.name =devm_kzalloc (&pdev->dev, +strlen (config->supply_name) +1 , +GFP_KERNEL );if (drvdata->desc.name ==NULL ) {dev_err (&pdev->dev,"Failed to allocate supply name\n" );Quoted 8 lines
drivers/regulator/fixed.c static int reg_fixed_voltage_probe(struct platform_device *pdev) · line 144
Quoted 5 lines
drivers/regulator/fixed.c +1
-2- ret = -ENOMEM ; - goto err; +return -ENOMEM ; }Umm, I am fairly certain that
devm_kzalloc()can't be used as a substitute for kstrdup, at least not without accompanying memcpy.Yes, I have provided allocation but it should be followed with assignment. Can I modify like this,
drivers/regulator/fixed.c static int reg_fixed_voltage_probe(struct platform_device *pdev)
Quoted 5 lines
drivers/regulator/fixed.c +5
-0+ drvdata->desc.name =devm_kzalloc (&pdev->dev, +strlen (config->supply_name) +1 , +GFP_KERNEL ); +if (drvdata->desc.name) +sprintf (drvdata->desc.name,"%s" , config->supply_name);
hmm, so you replaced a general helper function by open coding the string- duplication. Doesn't this defeat the target of simplifying the code?
Heiko
Hi Heiko
Thank you for your reply.
Quoted 67 lines · Heiko Stübner
Quoted 66 lines · On Tuesday, 28. January 2014 12:46:01 Manish Badarkhe wrote:
Hi Dmitry,
Thank you for your review.
On Tue, Jan 28, 2014 at 12:03 PM, Dmitry Torokhov
Quoted 47 lines · <[email protected]> wrote:
Hi Manish,
Quoted 44 lines · Manish Badarkhe
Update the code to use devm_* API so that driver core will manage resources.
Signed-off-by Manish Badarkhe <[email protected]>---
Changes since V1:
1. Updated driver to use "devm_kzalloc" to "kstrdup".
2. Updated commit message.Not tested on any board.
:100644 100644 5ea64b9... e9763a4... M
drivers/regulator/fixed.c
:drivers/regulator/fixed.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-)drivers/regulator/fixed.c +0
-0@@ -132,15 +132,15 @@ static int reg_fixed_voltage_probe(struct
platform_device*pdev)>>GFP_KERNEL); if (drvdata == NULL) { dev_err(&pdev->dev, "Failed to allocate device data\n");drivers/regulator/fixed.c +4
-3- ret = -ENOMEM ; - goto err; +return -ENOMEM ; } - drvdata->desc.name =kstrdup (config->supply_name,GFP_KERNEL ); + drvdata->desc.name =devm_kzalloc (&pdev->dev, +strlen (config->supply_name) +1 , +GFP_KERNEL );if (drvdata->desc.name ==NULL ) {dev_err (&pdev->dev,"Failed to allocate supply name\n" );Quoted 8 lines
drivers/regulator/fixed.c static int reg_fixed_voltage_probe(struct platform_device *pdev) · line 144
Quoted 5 lines
drivers/regulator/fixed.c +1
-2- ret = -ENOMEM ; - goto err; +return -ENOMEM ; }Umm, I am fairly certain that
devm_kzalloc()can't be used as a substitute for kstrdup, at least not without accompanying memcpy.Yes, I have provided allocation but it should be followed with assignment. Can I modify like this,
Quoted 8 lines
drivers/regulator/fixed.c static int reg_fixed_voltage_probe(struct platform_device *pdev)
Quoted 5 lines
drivers/regulator/fixed.c +5
-0+ drvdata->desc.name =devm_kzalloc (&pdev->dev, +strlen (config->supply_name) +1 , +GFP_KERNEL ); +if (drvdata->desc.name) +sprintf (drvdata->desc.name,"%s" , config->supply_name);hmm, so you replaced a general helper function by open coding the string- duplication. Doesn't this defeat the target of simplifying the code?
Intention here, is to use devm_ API and to adopt this I have to do these modifications for "kstrdup" functions. I have seen in regulator folder almost all drivers adopted to "devm_" API. Hence same thing I am following to update this driver. Please let me know whether to go ahead with this patch or retain driver as it is.
Regards
Manish Badarkhe
Quoted 82 lines · On Tuesday, 28. January 2014 14:16:39 Manish Badarkhe wrote:
Hi Heiko
Thank you for your reply.
Quoted 77 lines · Heiko Stübner
Quoted 75 lines · On Tuesday, 28. January 2014 12:46:01 Manish Badarkhe wrote:
Hi Dmitry,
Thank you for your review.
On Tue, Jan 28, 2014 at 12:03 PM, Dmitry Torokhov
Quoted 50 lines · <[email protected]> wrote:
Hi Manish,
Quoted 47 lines · Manish Badarkhe
Update the code to use devm_* API so that driver core will manage resources.
Signed-off-by Manish Badarkhe <[email protected]>---
Changes since V1:
1. Updated driver to use "devm_kzalloc" to "kstrdup".
2. Updated commit message.Not tested on any board.
:100644 100644 5ea64b9... e9763a4... M
:drivers/regulator/fixed.c
:drivers/regulator/fixed.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-)drivers/regulator/fixed.c +0
-0@@ -132,15 +132,15 @@ static int reg_fixed_voltage_probe(struct
platform_device*pdev)>>GFP_KERNEL); if (drvdata == NULL) { dev_err(&pdev->dev, "Failed to allocate device data\n");drivers/regulator/fixed.c +3
-3- ret = -ENOMEM ; - goto err; +return -ENOMEM ; } - drvdata->desc.name =kstrdup (config->supply_name,GFP_KERNEL ); + drvdata->desc.name = devm_kzalloc(&pdev->dev, + strlen(config->supply_name) +1,
+GFP_KERNEL);if (drvdata->desc.name == NULL) { dev_err(&pdev->dev, "Failed to allocate supply name\n");Quoted 8 lines
drivers/regulator/fixed.c static int reg_fixed_voltage_probe(struct platform_device *pdev) · line 144
Quoted 5 lines
drivers/regulator/fixed.c +1
-2- ret = -ENOMEM ; - goto err; +return -ENOMEM ; }Umm, I am fairly certain that
devm_kzalloc()can't be used as a substitute for kstrdup, at least not without accompanying memcpy.Yes, I have provided allocation but it should be followed with assignment.
Can I modify like this,drivers/regulator/fixed.c +5
-0+ drvdata->desc.name =devm_kzalloc (&pdev->dev, +strlen (config->supply_name) +1 , +GFP_KERNEL ); +if (drvdata->desc.name) +sprintf (drvdata->desc.name,"%s" , config->supply_name);
Quoted 8 lines
Quoted 2 lines
hmm, so you replaced a general helper function by open coding the string- duplication. Doesn't this defeat the target of simplifying the code?
Intention here, is to use
devm_API and to adopt this I have to do these modifications for "kstrdup" functions. I have seen in regulator folder almost all drivers adopted to "devm_" API. Hence same thing I am following to update this driver. Please let me know whether to go ahead with this patch or retain driver as it is.
I don't have a strong opinion on this and others are most likely more qualified to have a definitive answer, I just found it strange to exchange one open-coded pattern against another open-coded one.
So don't let me keep you from it ;-)
Heiko
Quoted 92 lines · Heiko Stübner
Quoted 82 lines · On Tuesday, 28. January 2014 14:16:39 Manish Badarkhe wrote:
Hi Heiko
Thank you for your reply.
Quoted 77 lines · Heiko Stübner
Quoted 75 lines · On Tuesday, 28. January 2014 12:46:01 Manish Badarkhe wrote:
Hi Dmitry,
Thank you for your review.
On Tue, Jan 28, 2014 at 12:03 PM, Dmitry Torokhov
Quoted 50 lines · <[email protected]> wrote:
Hi Manish,
Quoted 47 lines · Manish Badarkhe
Update the code to use devm_* API so that driver core will manage resources.
Signed-off-by Manish Badarkhe <[email protected]>---
Changes since V1:
1. Updated driver to use "devm_kzalloc" to "kstrdup".
2. Updated commit message.Not tested on any board.
:100644 100644 5ea64b9... e9763a4... M
:drivers/regulator/fixed.c
:drivers/regulator/fixed.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-)drivers/regulator/fixed.c +0
-0@@ -132,15 +132,15 @@ static int reg_fixed_voltage_probe(struct
platform_device*pdev)>>GFP_KERNEL); if (drvdata == NULL) { dev_err(&pdev->dev, "Failed to allocate device data\n");drivers/regulator/fixed.c +3
-3- ret = -ENOMEM ; - goto err; +return -ENOMEM ; } - drvdata->desc.name =kstrdup (config->supply_name,GFP_KERNEL ); + drvdata->desc.name = devm_kzalloc(&pdev->dev, + strlen(config->supply_name) +1,
+GFP_KERNEL);if (drvdata->desc.name == NULL) { dev_err(&pdev->dev, "Failed to allocate supply name\n");Quoted 8 lines
drivers/regulator/fixed.c static int reg_fixed_voltage_probe(struct platform_device *pdev) · line 144
Quoted 5 lines
drivers/regulator/fixed.c +1
-2- ret = -ENOMEM ; - goto err; +return -ENOMEM ; }Umm, I am fairly certain that
devm_kzalloc()can't be used as a substitute for kstrdup, at least not without accompanying memcpy.Yes, I have provided allocation but it should be followed with assignment.
Can I modify like this,drivers/regulator/fixed.c +5
-0+ drvdata->desc.name =devm_kzalloc (&pdev->dev, +strlen (config->supply_name) +1 , +GFP_KERNEL ); +if (drvdata->desc.name) +sprintf (drvdata->desc.name,"%s" , config->supply_name);Quoted 8 lines
Quoted 2 lines
hmm, so you replaced a general helper function by open coding the string- duplication. Doesn't this defeat the target of simplifying the code?
Intention here, is to use
devm_API and to adopt this I have to do these modifications for "kstrdup" functions. I have seen in regulator folder almost all drivers adopted to "devm_" API. Hence same thing I am following to update this driver. Please let me know whether to go ahead with this patch or retain driver as it is.
Quoted 5 lines
I don't have a strong opinion on this and others are most likely more qualified to have a definitive answer, I just found it strange to exchange one open-coded pattern against another open-coded one.
So don't let me keep you from it ;-)
Okay.
@Mark, Dmitry: Please let me know your opinion on this.
Thanks
Manish Badarkhe
Mark Brown
maintainerQuoted 10 lines · Manish Badarkhe
Quoted 5 lines · Heiko Stübner
I don't have a strong opinion on this and others are most likely more qualified to have a definitive answer, I just found it strange to exchange one open-coded pattern against another open-coded one.
So don't let me keep you from it ;-)
Okay.
@Mark, Dmitry: Please let me know your opinion on this.
How about implementing devm_kstrdup() and then using that?
Quoted 2 lines · Manish Badarkhe
Update the code to use devm_* API so that driver core will manage resources.
I'm not sure why this patch is sent to [email protected]; it seems nothing to do with Tegra (or Samsung or OMAP for that matter).
Hi Stephan,
Quoted 6 lines · Stephen Warren
Quoted 2 lines · Manish Badarkhe
Update the code to use devm_* API so that driver core will manage resources.
I'm not sure why this patch is sent to [email protected]; it seems nothing to do with Tegra (or Samsung or OMAP for that matter).
Sorry, for the noise. I sent it to have review comments from community.
Regards
Manish Badarkhe
Hi Mark,
Quoted 7 lines · Mark Brown
Quoted 6 lines · Manish Badarkhe
Quoted 4 lines · Heiko Stübner
I don't have a strong opinion on this and others are most likely more qualified to have a definitive answer, I just found it strange to exchange one open-coded pattern against another open-coded one.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
So don't let me keep you from it ;-)
Okay.
@Mark, Dmitry: Please let me know your opinion on this.How about implementing
devm_kstrdup()and then using that?
Okay, I will update kstrdup()->devm_kstrdup() and post next version of patch.
Thanks
Manish Badarkhe