2014-01-29 14:57:36

by Manish Badarkhe

[permalink] [raw]
Subject: [PATCH V4 0/2] devm_* API operation for fixed regulator

Use devm_* API operations for fixed regulator driver so that
driver core will manage resources.

Also, introduce a new API "devm_kstrdup" and used it in fixed
regulator driver to manage resources.

Changes since V3:
1. Update "devm_kstrdup" function to remove "size" argument.
Also,used "devm_kmalloc" instead of "devm_kzalloc".

Changes since V2:
1. Update driver to use new API "devm_kstrdup" instead of
"kstrdup".
2. Added a seperate patch to introduce new API "devm_kstrdup"

Changes since V1:
1. Updated driver to use "devm_kzalloc" instead of "kstrdup".
2. Updated commit message.

Manish Badarkhe (2):
devres: introduce API "devm_kstrdup"
regulator: fixed: update to devm_* API

drivers/base/devres.c | 26 ++++++++++++++++++++++++++
drivers/regulator/fixed.c | 42 ++++++++++++------------------------------
include/linux/device.h | 1 +
3 files changed, 39 insertions(+), 30 deletions(-)

--
1.7.10.4


2014-01-29 14:57:40

by Manish Badarkhe

[permalink] [raw]
Subject: [PATCH V4 1/2] devres: introduce API "devm_kstrdup"

This patch introduces "devm_kstrdup" API so that the
device's driver can allocate memory and copy string.

Signed-off-by: Manish Badarkhe <[email protected]>
---
:100644 100644 545c4de... db4e264... M drivers/base/devres.c
:100644 100644 952b010... ec1b6e2... M include/linux/device.h
drivers/base/devres.c | 26 ++++++++++++++++++++++++++
include/linux/device.h | 1 +
2 files changed, 27 insertions(+)

diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 545c4de..db4e264 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -791,6 +791,32 @@ void * devm_kmalloc(struct device *dev, size_t size, gfp_t gfp)
EXPORT_SYMBOL_GPL(devm_kmalloc);

/**
+ * devm_kstrdup - Allocate resource managed space and
+ * copy an existing string into that.
+ * @dev: Device to allocate memory for
+ * @s: the string to duplicate
+ * @gfp: the GFP mask used in the devm_kmalloc() call when
+ * allocating memory
+ * RETURNS:
+ * Pointer to allocated string on success, NULL on failure.
+ */
+char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp)
+{
+ size_t size;
+ char *buf;
+
+ if (!s)
+ return NULL;
+
+ size = strlen(s) + 1;
+ buf = devm_kmalloc(dev, size, gfp);
+ if (buf)
+ memcpy(buf, s, size);
+ return buf;
+}
+EXPORT_SYMBOL_GPL(devm_kstrdup);
+
+/**
* devm_kfree - Resource-managed kfree
* @dev: Device this memory belongs to
* @p: Memory to free
diff --git a/include/linux/device.h b/include/linux/device.h
index 952b010..ec1b6e2 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -626,6 +626,7 @@ static inline void *devm_kcalloc(struct device *dev,
return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
}
extern void devm_kfree(struct device *dev, void *p);
+extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp);

void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
void __iomem *devm_request_and_ioremap(struct device *dev,
--
1.7.10.4

2014-01-29 14:57:49

by Manish Badarkhe

[permalink] [raw]
Subject: [PATCH V4 2/2] regulator: fixed: update to devm_* API

Update the code to use devm_* API so that driver core will manage
resources.

Signed-off-by: Manish Badarkhe <[email protected]>
---
:100644 100644 5ea64b9... 3c307d6... M drivers/regulator/fixed.c
drivers/regulator/fixed.c | 42 ++++++++++++------------------------------
1 file changed, 12 insertions(+), 30 deletions(-)

diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index 5ea64b9..3c307d6 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -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_kstrdup(&pdev->dev,
+ config->supply_name,
+ 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_kstrdup(&pdev->dev,
+ config->input_supply,
+ 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,
--
1.7.10.4

2014-02-03 13:15:07

by Manish Badarkhe

[permalink] [raw]
Subject: Re: [PATCH V4 0/2] devm_* API operation for fixed regulator

Hi Mark,



On Wed, Jan 29, 2014 at 8:27 PM, Manish Badarkhe
<[email protected]> wrote:
> Use devm_* API operations for fixed regulator driver so that
> driver core will manage resources.
>
> Also, introduce a new API "devm_kstrdup" and used it in fixed
> regulator driver to manage resources.
>
> Changes since V3:
> 1. Update "devm_kstrdup" function to remove "size" argument.
> Also,used "devm_kmalloc" instead of "devm_kzalloc".
>
> Changes since V2:
> 1. Update driver to use new API "devm_kstrdup" instead of
> "kstrdup".
> 2. Added a seperate patch to introduce new API "devm_kstrdup"
>
> Changes since V1:
> 1. Updated driver to use "devm_kzalloc" instead of "kstrdup".
> 2. Updated commit message.
>
> Manish Badarkhe (2):
> devres: introduce API "devm_kstrdup"
> regulator: fixed: update to devm_* API
>
> drivers/base/devres.c | 26 ++++++++++++++++++++++++++
> drivers/regulator/fixed.c | 42 ++++++++++++------------------------------
> include/linux/device.h | 1 +
> 3 files changed, 39 insertions(+), 30 deletions(-)

Are there any review comments on this series?

Regards,
Manish Badarkhe

2014-02-04 13:12:21

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH V4 0/2] devm_* API operation for fixed regulator

On Mon, Feb 03, 2014 at 06:45:04PM +0530, Manish Badarkhe wrote:

> Are there any review comments on this series?

Don't send contentless pings, especially not less than a week after you
sent the original patch. That's just more mail to read. You need to
allow a reasonable time for review, for non-critical stuff a couple of
weeks would be more reasonable. In this case since you're touching the
core devres code so please bear in mind that those folks need time to
respond too.


Attachments:
(No filename) (483.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments

2014-02-11 16:35:45

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH V4 0/2] devm_* API operation for fixed regulator

On Wed, Jan 29, 2014 at 08:27:26PM +0530, Manish Badarkhe wrote:
> Use devm_* API operations for fixed regulator driver so that
> driver core will manage resources.

Applied both, thanks.


Attachments:
(No filename) (188.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments