linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] regulator: max8907: Fix using wrong dev argument for calling of_regulator_match
@ 2013-01-25  2:20 Axel Lin
  2013-01-25  2:24 ` [PATCH 2/3] regulator: max77686: Fix using wrong dev argument at various places Axel Lin
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Axel Lin @ 2013-01-25  2:20 UTC (permalink / raw)
  To: Mark Brown
  Cc: Gyungoh Yoo, Stephen Warren, Laxman Dewangan, Graeme Gregory,
	Liam Girdwood, linux-kernel

The dev parameter is the device requesting the data.
In this case it should be &pdev->dev rather than pdev->dev.parent.

The dev parameter is used to call devm_kzalloc in of_get_regulator_init_data(),
which means this fixes a memory leak because the memory is allocated every time
probe() is called, thus it should be freed when this driver is unloaded.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/max8907-regulator.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/regulator/max8907-regulator.c b/drivers/regulator/max8907-regulator.c
index d1a7751..d40cf7f 100644
--- a/drivers/regulator/max8907-regulator.c
+++ b/drivers/regulator/max8907-regulator.c
@@ -237,8 +237,7 @@ static int max8907_regulator_parse_dt(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	ret = of_regulator_match(pdev->dev.parent, regulators,
-				 max8907_matches,
+	ret = of_regulator_match(&pdev->dev, regulators, max8907_matches,
 				 ARRAY_SIZE(max8907_matches));
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
-- 
1.7.9.5




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] regulator: max77686: Fix using wrong dev argument at various places
  2013-01-25  2:20 [PATCH 1/3] regulator: max8907: Fix using wrong dev argument for calling of_regulator_match Axel Lin
@ 2013-01-25  2:24 ` Axel Lin
  2013-01-27 13:51   ` Yadwinder Singh Brar
  2013-01-25  2:26 ` [PATCH 3/3] regulator: max8997: " Axel Lin
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Axel Lin @ 2013-01-25  2:24 UTC (permalink / raw)
  To: Mark Brown
  Cc: Chiwoong Byun, Jonghwa Lee, Myungjoo Ham, Yadwinder Singh Brar,
	Liam Girdwood, linux-kernel

Use &pdev->dev rather than iodev->dev for dev_err().
Use &pdev->dev rather than iodev->dev for devm_kzalloc() and
of_regulator_match(), this fixes memory leak.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/max77686.c |   15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
index b85040c..cca18a3 100644
--- a/drivers/regulator/max77686.c
+++ b/drivers/regulator/max77686.c
@@ -379,9 +379,10 @@ static struct regulator_desc regulators[] = {
 };
 
 #ifdef CONFIG_OF
-static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev,
+static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev,
 					struct max77686_platform_data *pdata)
 {
+	struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
 	struct device_node *pmic_np, *regulators_np;
 	struct max77686_regulator_data *rdata;
 	struct of_regulator_match rmatch;
@@ -390,15 +391,15 @@ static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev,
 	pmic_np = iodev->dev->of_node;
 	regulators_np = of_find_node_by_name(pmic_np, "voltage-regulators");
 	if (!regulators_np) {
-		dev_err(iodev->dev, "could not find regulators sub-node\n");
+		dev_err(&pdev->dev, "could not find regulators sub-node\n");
 		return -EINVAL;
 	}
 
 	pdata->num_regulators = ARRAY_SIZE(regulators);
-	rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) *
+	rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) *
 			     pdata->num_regulators, GFP_KERNEL);
 	if (!rdata) {
-		dev_err(iodev->dev,
+		dev_err(&pdev->dev,
 			"could not allocate memory for regulator data\n");
 		return -ENOMEM;
 	}
@@ -407,7 +408,7 @@ static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev,
 		rmatch.name = regulators[i].name;
 		rmatch.init_data = NULL;
 		rmatch.of_node = NULL;
-		of_regulator_match(iodev->dev, regulators_np, &rmatch, 1);
+		of_regulator_match(&pdev->dev, regulators_np, &rmatch, 1);
 		rdata[i].initdata = rmatch.init_data;
 		rdata[i].of_node = rmatch.of_node;
 	}
@@ -417,7 +418,7 @@ static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev,
 	return 0;
 }
 #else
-static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev,
+static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev,
 					struct max77686_platform_data *pdata)
 {
 	return 0;
@@ -440,7 +441,7 @@ static int max77686_pmic_probe(struct platform_device *pdev)
 	}
 
 	if (iodev->dev->of_node) {
-		ret = max77686_pmic_dt_parse_pdata(iodev, pdata);
+		ret = max77686_pmic_dt_parse_pdata(pdev, pdata);
 		if (ret)
 			return ret;
 	}
-- 
1.7.9.5




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] regulator: max8997: Fix using wrong dev argument at various places
  2013-01-25  2:20 [PATCH 1/3] regulator: max8907: Fix using wrong dev argument for calling of_regulator_match Axel Lin
  2013-01-25  2:24 ` [PATCH 2/3] regulator: max77686: Fix using wrong dev argument at various places Axel Lin
@ 2013-01-25  2:26 ` Axel Lin
  2013-01-25  4:55 ` [PATCH 1/3] regulator: max8907: Fix using wrong dev argument for calling of_regulator_match Stephen Warren
  2013-01-27  2:57 ` Mark Brown
  3 siblings, 0 replies; 6+ messages in thread
From: Axel Lin @ 2013-01-25  2:26 UTC (permalink / raw)
  To: Mark Brown
  Cc: MyungJoo Ham, Thomas Abraham, Tomasz Figa, Liam Girdwood, linux-kernel

Use &pdev->dev rather than iodev->dev for dev_err(), dev_warn() and dev_info().
Use &pdev->dev rather than iodev->dev for devm_kzalloc() and
of_get_regulator_init_data(), this fixes memory leak.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/max8997.c |   39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
index 1a1ae99..5556a15 100644
--- a/drivers/regulator/max8997.c
+++ b/drivers/regulator/max8997.c
@@ -891,7 +891,7 @@ static struct regulator_desc regulators[] = {
 };
 
 #ifdef CONFIG_OF
-static int max8997_pmic_dt_parse_dvs_gpio(struct max8997_dev *iodev,
+static int max8997_pmic_dt_parse_dvs_gpio(struct platform_device *pdev,
 			struct max8997_platform_data *pdata,
 			struct device_node *pmic_np)
 {
@@ -901,7 +901,7 @@ static int max8997_pmic_dt_parse_dvs_gpio(struct max8997_dev *iodev,
 		gpio = of_get_named_gpio(pmic_np,
 					"max8997,pmic-buck125-dvs-gpios", i);
 		if (!gpio_is_valid(gpio)) {
-			dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio);
+			dev_err(&pdev->dev, "invalid gpio[%d]: %d\n", i, gpio);
 			return -EINVAL;
 		}
 		pdata->buck125_gpios[i] = gpio;
@@ -909,22 +909,23 @@ static int max8997_pmic_dt_parse_dvs_gpio(struct max8997_dev *iodev,
 	return 0;
 }
 
-static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,
+static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,
 					struct max8997_platform_data *pdata)
 {
+	struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
 	struct device_node *pmic_np, *regulators_np, *reg_np;
 	struct max8997_regulator_data *rdata;
 	unsigned int i, dvs_voltage_nr = 1, ret;
 
 	pmic_np = iodev->dev->of_node;
 	if (!pmic_np) {
-		dev_err(iodev->dev, "could not find pmic sub-node\n");
+		dev_err(&pdev->dev, "could not find pmic sub-node\n");
 		return -ENODEV;
 	}
 
 	regulators_np = of_find_node_by_name(pmic_np, "regulators");
 	if (!regulators_np) {
-		dev_err(iodev->dev, "could not find regulators sub-node\n");
+		dev_err(&pdev->dev, "could not find regulators sub-node\n");
 		return -EINVAL;
 	}
 
@@ -933,11 +934,10 @@ static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,
 	for_each_child_of_node(regulators_np, reg_np)
 		pdata->num_regulators++;
 
-	rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) *
+	rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) *
 				pdata->num_regulators, GFP_KERNEL);
 	if (!rdata) {
-		dev_err(iodev->dev, "could not allocate memory for "
-						"regulator data\n");
+		dev_err(&pdev->dev, "could not allocate memory for regulator data\n");
 		return -ENOMEM;
 	}
 
@@ -948,14 +948,14 @@ static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,
 				break;
 
 		if (i == ARRAY_SIZE(regulators)) {
-			dev_warn(iodev->dev, "don't know how to configure "
-				"regulator %s\n", reg_np->name);
+			dev_warn(&pdev->dev, "don't know how to configure regulator %s\n",
+				 reg_np->name);
 			continue;
 		}
 
 		rdata->id = i;
-		rdata->initdata = of_get_regulator_init_data(
-						iodev->dev, reg_np);
+		rdata->initdata = of_get_regulator_init_data(&pdev->dev,
+							     reg_np);
 		rdata->reg_node = reg_np;
 		rdata++;
 	}
@@ -971,7 +971,7 @@ static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,
 
 	if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs ||
 						pdata->buck5_gpiodvs) {
-		ret = max8997_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np);
+		ret = max8997_pmic_dt_parse_dvs_gpio(pdev, pdata, pmic_np);
 		if (ret)
 			return -EINVAL;
 
@@ -982,8 +982,7 @@ static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,
 		} else {
 			if (pdata->buck125_default_idx >= 8) {
 				pdata->buck125_default_idx = 0;
-				dev_info(iodev->dev, "invalid value for "
-				"default dvs index, using 0 instead\n");
+				dev_info(&pdev->dev, "invalid value for default dvs index, using 0 instead\n");
 			}
 		}
 
@@ -997,28 +996,28 @@ static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,
 	if (of_property_read_u32_array(pmic_np,
 				"max8997,pmic-buck1-dvs-voltage",
 				pdata->buck1_voltage, dvs_voltage_nr)) {
-		dev_err(iodev->dev, "buck1 voltages not specified\n");
+		dev_err(&pdev->dev, "buck1 voltages not specified\n");
 		return -EINVAL;
 	}
 
 	if (of_property_read_u32_array(pmic_np,
 				"max8997,pmic-buck2-dvs-voltage",
 				pdata->buck2_voltage, dvs_voltage_nr)) {
-		dev_err(iodev->dev, "buck2 voltages not specified\n");
+		dev_err(&pdev->dev, "buck2 voltages not specified\n");
 		return -EINVAL;
 	}
 
 	if (of_property_read_u32_array(pmic_np,
 				"max8997,pmic-buck5-dvs-voltage",
 				pdata->buck5_voltage, dvs_voltage_nr)) {
-		dev_err(iodev->dev, "buck5 voltages not specified\n");
+		dev_err(&pdev->dev, "buck5 voltages not specified\n");
 		return -EINVAL;
 	}
 
 	return 0;
 }
 #else
-static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,
+static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,
 					struct max8997_platform_data *pdata)
 {
 	return 0;
@@ -1042,7 +1041,7 @@ static int max8997_pmic_probe(struct platform_device *pdev)
 	}
 
 	if (iodev->dev->of_node) {
-		ret = max8997_pmic_dt_parse_pdata(iodev, pdata);
+		ret = max8997_pmic_dt_parse_pdata(pdev, pdata);
 		if (ret)
 			return ret;
 	}
-- 
1.7.9.5




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] regulator: max8907: Fix using wrong dev argument for calling of_regulator_match
  2013-01-25  2:20 [PATCH 1/3] regulator: max8907: Fix using wrong dev argument for calling of_regulator_match Axel Lin
  2013-01-25  2:24 ` [PATCH 2/3] regulator: max77686: Fix using wrong dev argument at various places Axel Lin
  2013-01-25  2:26 ` [PATCH 3/3] regulator: max8997: " Axel Lin
@ 2013-01-25  4:55 ` Stephen Warren
  2013-01-27  2:57 ` Mark Brown
  3 siblings, 0 replies; 6+ messages in thread
From: Stephen Warren @ 2013-01-25  4:55 UTC (permalink / raw)
  To: Axel Lin
  Cc: Mark Brown, Gyungoh Yoo, Laxman Dewangan, Graeme Gregory,
	Liam Girdwood, linux-kernel

On 01/24/2013 06:20 PM, Axel Lin wrote:
> The dev parameter is the device requesting the data.
> In this case it should be &pdev->dev rather than pdev->dev.parent.
> 
> The dev parameter is used to call devm_kzalloc in of_get_regulator_init_data(),
> which means this fixes a memory leak because the memory is allocated every time
> probe() is called, thus it should be freed when this driver is unloaded.

Reviewed-by: Stephen Warren <swarren@nvidia.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] regulator: max8907: Fix using wrong dev argument for calling of_regulator_match
  2013-01-25  2:20 [PATCH 1/3] regulator: max8907: Fix using wrong dev argument for calling of_regulator_match Axel Lin
                   ` (2 preceding siblings ...)
  2013-01-25  4:55 ` [PATCH 1/3] regulator: max8907: Fix using wrong dev argument for calling of_regulator_match Stephen Warren
@ 2013-01-27  2:57 ` Mark Brown
  3 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2013-01-27  2:57 UTC (permalink / raw)
  To: Axel Lin
  Cc: Gyungoh Yoo, Stephen Warren, Laxman Dewangan, Graeme Gregory,
	Liam Girdwood, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 204 bytes --]

On Fri, Jan 25, 2013 at 10:20:29AM +0800, Axel Lin wrote:
> The dev parameter is the device requesting the data.
> In this case it should be &pdev->dev rather than pdev->dev.parent.

Applied all, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] regulator: max77686: Fix using wrong dev argument at various places
  2013-01-25  2:24 ` [PATCH 2/3] regulator: max77686: Fix using wrong dev argument at various places Axel Lin
@ 2013-01-27 13:51   ` Yadwinder Singh Brar
  0 siblings, 0 replies; 6+ messages in thread
From: Yadwinder Singh Brar @ 2013-01-27 13:51 UTC (permalink / raw)
  To: Axel Lin
  Cc: Mark Brown, Chiwoong Byun, Jonghwa Lee, Myungjoo Ham,
	Yadwinder Singh Brar, Liam Girdwood, linux-kernel

On Fri, Jan 25, 2013 at 7:54 AM, Axel Lin <axel.lin@ingics.com> wrote:
> Use &pdev->dev rather than iodev->dev for dev_err().
> Use &pdev->dev rather than iodev->dev for devm_kzalloc() and
> of_regulator_match(), this fixes memory leak.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---

Reviewed-by: Yadwinder Singh Brar <yadi.brar@samsung.com>

Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-01-27 13:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-25  2:20 [PATCH 1/3] regulator: max8907: Fix using wrong dev argument for calling of_regulator_match Axel Lin
2013-01-25  2:24 ` [PATCH 2/3] regulator: max77686: Fix using wrong dev argument at various places Axel Lin
2013-01-27 13:51   ` Yadwinder Singh Brar
2013-01-25  2:26 ` [PATCH 3/3] regulator: max8997: " Axel Lin
2013-01-25  4:55 ` [PATCH 1/3] regulator: max8907: Fix using wrong dev argument for calling of_regulator_match Stephen Warren
2013-01-27  2:57 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).