kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/6] drivers/mfd: drop frees of devm allocated data
@ 2012-08-04 16:50 Julia Lawall
  2012-08-06 14:05 ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2012-08-04 16:50 UTC (permalink / raw)
  To: Samuel Ortiz; +Cc: kernel-janitors, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

devm_kfree should not have to be explicitly used.
devm_regmap_init_i2c also does not require an explicit free.

The semantic patch that fixes the first problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x,d;
@@

x = devm_kzalloc(...)
...
?-devm_kfree(d,x);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/mfd/88pm800.c |    5 +----
 drivers/mfd/88pm80x.c |   20 +++-----------------
 2 files changed, 4 insertions(+), 21 deletions(-)

diff --git a/drivers/mfd/88pm800.c b/drivers/mfd/88pm800.c
index b67a301..a2e5bd8 100644
--- a/drivers/mfd/88pm800.c
+++ b/drivers/mfd/88pm800.c
@@ -530,7 +530,7 @@ static int __devinit pm800_probe(struct i2c_client *client,
 	ret = device_800_init(chip, pdata);
 	if (ret) {
 		dev_err(chip->dev, "%s id 0x%x failed!\n", __func__, chip->id);
-		goto err_800_init;
+		goto err_subchip_alloc;
 	}
 
 	ret = pm800_pages_init(chip);
@@ -545,8 +545,6 @@ static int __devinit pm800_probe(struct i2c_client *client,
 err_page_init:
 	mfd_remove_devices(chip->dev);
 	device_irq_exit_800(chip);
-err_800_init:
-	devm_kfree(&client->dev, subchip);
 err_subchip_alloc:
 	pm80x_deinit(client);
 out_init:
@@ -561,7 +559,6 @@ static int __devexit pm800_remove(struct i2c_client *client)
 	device_irq_exit_800(chip);
 
 	pm800_pages_exit(chip);
-	devm_kfree(&client->dev, chip->subchip);
 
 	pm80x_deinit(client);
 
diff --git a/drivers/mfd/88pm80x.c b/drivers/mfd/88pm80x.c
index cd0bf52..2bd090e 100644
--- a/drivers/mfd/88pm80x.c
+++ b/drivers/mfd/88pm80x.c
@@ -45,17 +45,14 @@ int __devinit pm80x_init(struct i2c_client *client,
 
 	map = devm_regmap_init_i2c(client, &pm80x_regmap_config);
 	if (IS_ERR(map)) {
-		ret = PTR_ERR(map);
 		dev_err(&client->dev, "Failed to allocate register map: %d\n",
 			ret);
-		goto err_regmap_init;
+		return PTR_ERR(map);
 	}
 
 	chip->id = id->driver_data;
-	if (chip->id < CHIP_PM800 || chip->id > CHIP_PM805) {
-		ret = -EINVAL;
-		goto err_chip_id;
-	}
+	if (chip->id < CHIP_PM800 || chip->id > CHIP_PM805)
+		return -EINVAL;
 
 	chip->client = client;
 	chip->regmap = map;
@@ -82,19 +79,11 @@ int __devinit pm80x_init(struct i2c_client *client,
 	}
 
 	return 0;
-
-err_chip_id:
-	regmap_exit(map);
-err_regmap_init:
-	devm_kfree(&client->dev, chip);
-	return ret;
 }
 EXPORT_SYMBOL_GPL(pm80x_init);
 
 int pm80x_deinit(struct i2c_client *client)
 {
-	struct pm80x_chip *chip = i2c_get_clientdata(client);
-
 	/*
 	 * workaround: clear the dependency between pm800 and pm805.
 	 * would remove it after HW chip fixes the issue.
@@ -104,9 +93,6 @@ int pm80x_deinit(struct i2c_client *client)
 	else
 		g_pm80x_chip = NULL;
 
-	regmap_exit(chip->regmap);
-	devm_kfree(&client->dev, chip);
-
 	return 0;
 }
 EXPORT_SYMBOL_GPL(pm80x_deinit);


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

* Re: [PATCH 2/6] drivers/mfd: drop frees of devm allocated data
  2012-08-04 16:50 [PATCH 2/6] drivers/mfd: drop frees of devm allocated data Julia Lawall
@ 2012-08-06 14:05 ` Dan Carpenter
  2012-08-06 19:57   ` Julia.Lawall
  2012-08-13 19:36   ` Julia Lawall
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2012-08-06 14:05 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Samuel Ortiz, kernel-janitors, linux-kernel

On Sat, Aug 04, 2012 at 06:50:45PM +0200, Julia Lawall wrote:
> diff --git a/drivers/mfd/88pm80x.c b/drivers/mfd/88pm80x.c
> index cd0bf52..2bd090e 100644
> --- a/drivers/mfd/88pm80x.c
> +++ b/drivers/mfd/88pm80x.c
> @@ -45,17 +45,14 @@ int __devinit pm80x_init(struct i2c_client *client,
>  
>  	map = devm_regmap_init_i2c(client, &pm80x_regmap_config);
>  	if (IS_ERR(map)) {
> -		ret = PTR_ERR(map);
>  		dev_err(&client->dev, "Failed to allocate register map: %d\n",
>  			ret);
                        ^^^
The ret = PTR_ERR(map); is still needed for the error message.

> -		goto err_regmap_init;
> +		return PTR_ERR(map);
>  	}

regards,
dan carpenter


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

* Re: [PATCH 2/6] drivers/mfd: drop frees of devm allocated data
  2012-08-06 14:05 ` Dan Carpenter
@ 2012-08-06 19:57   ` Julia.Lawall
  2012-08-13 19:36   ` Julia Lawall
  1 sibling, 0 replies; 5+ messages in thread
From: Julia.Lawall @ 2012-08-06 19:57 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Julia Lawall, Samuel Ortiz, kernel-janitors, linux-kernel

Quoting Dan Carpenter <dan.carpenter@oracle.com>:

> On Sat, Aug 04, 2012 at 06:50:45PM +0200, Julia Lawall wrote:
>> diff --git a/drivers/mfd/88pm80x.c b/drivers/mfd/88pm80x.c
>> index cd0bf52..2bd090e 100644
>> --- a/drivers/mfd/88pm80x.c
>> +++ b/drivers/mfd/88pm80x.c
>> @@ -45,17 +45,14 @@ int __devinit pm80x_init(struct i2c_client *client,
>>
>>  	map = devm_regmap_init_i2c(client, &pm80x_regmap_config);
>>  	if (IS_ERR(map)) {
>> -		ret = PTR_ERR(map);
>>  		dev_err(&client->dev, "Failed to allocate register map: %d\n",
>>  			ret);
>                         ^^^
> The ret = PTR_ERR(map); is still needed for the error message.

Good point.  Thanks.  I will fix it as soon as possible, at the end of  
the week.

julia

>> -		goto err_regmap_init;
>> +		return PTR_ERR(map);
>>  	}
>
> regards,
> dan carpenter
>
>





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

* Re: [PATCH 2/6] drivers/mfd: drop frees of devm allocated data
  2012-08-06 14:05 ` Dan Carpenter
  2012-08-06 19:57   ` Julia.Lawall
@ 2012-08-13 19:36   ` Julia Lawall
  2012-09-16 23:24     ` Samuel Ortiz
  1 sibling, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2012-08-13 19:36 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Samuel Ortiz, kernel-janitors, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

devm_kfree should not have to be explicitly used.
devm_regmap_init_i2c also does not require an explicit free.

The semantic patch that fixes the first problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x,d;
@@

x = devm_kzalloc(...)
...
?-devm_kfree(d,x);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
v2: Removed over-eager optimization of some error-handling code.

  drivers/mfd/88pm800.c |    5 +----
  drivers/mfd/88pm80x.c |   19 +++----------------
  2 files changed, 4 insertions(+), 20 deletions(-)

diff --git a/drivers/mfd/88pm800.c b/drivers/mfd/88pm800.c
index b67a301..a2e5bd8 100644
--- a/drivers/mfd/88pm800.c
+++ b/drivers/mfd/88pm800.c
@@ -530,7 +530,7 @@ static int __devinit pm800_probe(struct i2c_client *client,
  	ret = device_800_init(chip, pdata);
  	if (ret) {
  		dev_err(chip->dev, "%s id 0x%x failed!\n", __func__, chip->id);
-		goto err_800_init;
+		goto err_subchip_alloc;
  	}

  	ret = pm800_pages_init(chip);
@@ -545,8 +545,6 @@ static int __devinit pm800_probe(struct i2c_client *client,
  err_page_init:
  	mfd_remove_devices(chip->dev);
  	device_irq_exit_800(chip);
-err_800_init:
-	devm_kfree(&client->dev, subchip);
  err_subchip_alloc:
  	pm80x_deinit(client);
  out_init:
@@ -561,7 +559,6 @@ static int __devexit pm800_remove(struct i2c_client *client)
  	device_irq_exit_800(chip);

  	pm800_pages_exit(chip);
-	devm_kfree(&client->dev, chip->subchip);

  	pm80x_deinit(client);

diff --git a/drivers/mfd/88pm80x.c b/drivers/mfd/88pm80x.c
index cd0bf52..ae2bb85 100644
--- a/drivers/mfd/88pm80x.c
+++ b/drivers/mfd/88pm80x.c
@@ -48,14 +48,12 @@ int __devinit pm80x_init(struct i2c_client *client,
  		ret = PTR_ERR(map);
  		dev_err(&client->dev, "Failed to allocate register map: %d\n",
  			ret);
-		goto err_regmap_init;
+		return ret;
  	}

  	chip->id = id->driver_data;
-	if (chip->id < CHIP_PM800 || chip->id > CHIP_PM805) {
-		ret = -EINVAL;
-		goto err_chip_id;
-	}
+	if (chip->id < CHIP_PM800 || chip->id > CHIP_PM805)
+		return -EINVAL;

  	chip->client = client;
  	chip->regmap = map;
@@ -82,19 +80,11 @@ int __devinit pm80x_init(struct i2c_client *client,
  	}

  	return 0;
-
-err_chip_id:
-	regmap_exit(map);
-err_regmap_init:
-	devm_kfree(&client->dev, chip);
-	return ret;
  }
  EXPORT_SYMBOL_GPL(pm80x_init);

  int pm80x_deinit(struct i2c_client *client)
  {
-	struct pm80x_chip *chip = i2c_get_clientdata(client);
-
  	/*
  	 * workaround: clear the dependency between pm800 and pm805.
  	 * would remove it after HW chip fixes the issue.
@@ -104,9 +94,6 @@ int pm80x_deinit(struct i2c_client *client)
  	else
  		g_pm80x_chip = NULL;

-	regmap_exit(chip->regmap);
-	devm_kfree(&client->dev, chip);
-
  	return 0;
  }
  EXPORT_SYMBOL_GPL(pm80x_deinit);

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

* Re: [PATCH 2/6] drivers/mfd: drop frees of devm allocated data
  2012-08-13 19:36   ` Julia Lawall
@ 2012-09-16 23:24     ` Samuel Ortiz
  0 siblings, 0 replies; 5+ messages in thread
From: Samuel Ortiz @ 2012-09-16 23:24 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Dan Carpenter, kernel-janitors, linux-kernel

Hi Julia,

On Mon, Aug 13, 2012 at 09:36:06PM +0200, Julia Lawall wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> devm_kfree should not have to be explicitly used.
> devm_regmap_init_i2c also does not require an explicit free.
> 
> The semantic patch that fixes the first problem is as follows:
> (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@
> expression x,d;
> @@
> 
> x = devm_kzalloc(...)
> ...
> ?-devm_kfree(d,x);
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---
> v2: Removed over-eager optimization of some error-handling code.
> 
>  drivers/mfd/88pm800.c |    5 +----
>  drivers/mfd/88pm80x.c |   19 +++----------------
>  2 files changed, 4 insertions(+), 20 deletions(-)
This one does not apply to my for-next branch, would you please mind rebasing
it against that branch ?

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/

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

end of thread, other threads:[~2012-09-16 23:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-04 16:50 [PATCH 2/6] drivers/mfd: drop frees of devm allocated data Julia Lawall
2012-08-06 14:05 ` Dan Carpenter
2012-08-06 19:57   ` Julia.Lawall
2012-08-13 19:36   ` Julia Lawall
2012-09-16 23:24     ` Samuel Ortiz

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).