diff mbox

[gpio,1/4] drivers: gpio: use devm_kzalloc

Message ID 1427775551-6908-2-git-send-email-varkab@cdac.in
State New
Headers show

Commit Message

Varka Bhadram March 31, 2015, 4:19 a.m. UTC
We can use devres API for allocating memory. No need of using kfree.

Signed-off-by: Varka Bhadram <varkab@cdac.in>
---
 drivers/gpio/gpio-adp5588.c  |    3 +--
 drivers/gpio/gpio-mcp23s08.c |    7 ++++---
 2 files changed, 5 insertions(+), 5 deletions(-)

Comments

Linus Walleij April 7, 2015, 2:19 p.m. UTC | #1
On Tue, Mar 31, 2015 at 6:19 AM, Varka Bhadram <varkabhadram@gmail.com> wrote:

> We can use devres API for allocating memory. No need of using kfree.
>
> Signed-off-by: Varka Bhadram <varkab@cdac.in>

Straight forward clean-up. Patch applied.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johan Hovold April 7, 2015, 3:37 p.m. UTC | #2
On Tue, Mar 31, 2015 at 09:49:08AM +0530, Varka Bhadram wrote:
> We can use devres API for allocating memory. No need of using kfree.
> 
> Signed-off-by: Varka Bhadram <varkab@cdac.in>
> ---
>  drivers/gpio/gpio-adp5588.c  |    3 +--
>  drivers/gpio/gpio-mcp23s08.c |    7 ++++---
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-adp5588.c b/drivers/gpio/gpio-adp5588.c
> index 3beed6e..0de8c70 100644
> --- a/drivers/gpio/gpio-adp5588.c
> +++ b/drivers/gpio/gpio-adp5588.c
> @@ -378,7 +378,7 @@ static int adp5588_gpio_probe(struct i2c_client *client,
>  		return -EIO;
>  	}
>  
> -	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> +	dev = devm_kzalloc(&client->dev, sizeof(*dev), GFP_KERNEL);
>  	if (dev == NULL)
>  		return -ENOMEM;
>  
> @@ -446,7 +446,6 @@ static int adp5588_gpio_probe(struct i2c_client *client,
>  err_irq:
>  	adp5588_irq_teardown(dev);
>  err:
> -	kfree(dev);
>  	return ret;
>  }

You cannot just switch the allocation to devm_kzalloc without removing
the kfree from the remove callback.

> diff --git a/drivers/gpio/gpio-mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c
> index eea5d7e..a17b81f 100644
> --- a/drivers/gpio/gpio-mcp23s08.c
> +++ b/drivers/gpio/gpio-mcp23s08.c
> @@ -949,10 +949,12 @@ static int mcp23s08_probe(struct spi_device *spi)
>  	if (!chips)
>  		return -ENODEV;
>  
> -	data = kzalloc(sizeof(*data) + chips * sizeof(struct mcp23s08),
> -			GFP_KERNEL);
> +	data = devm_kzalloc(&spi->dev,
> +			    sizeof(*data) + chips * sizeof(struct mcp23s08),
> +			    GFP_KERNEL);
>  	if (!data)
>  		return -ENOMEM;
> +
>  	spi_set_drvdata(spi, data);
>  
>  	spi->irq = irq_of_parse_and_map(spi->dev.of_node, 0);
> @@ -989,7 +991,6 @@ fail:
>  			continue;
>  		gpiochip_remove(&data->mcp[addr]->chip);
>  	}
> -	kfree(data);
>  	return status;
>  }

Same bug again.

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johan Hovold April 7, 2015, 3:40 p.m. UTC | #3
On Tue, Apr 07, 2015 at 04:19:17PM +0200, Linus Walleij wrote:
> On Tue, Mar 31, 2015 at 6:19 AM, Varka Bhadram <varkabhadram@gmail.com> wrote:
> 
> > We can use devres API for allocating memory. No need of using kfree.
> >
> > Signed-off-by: Varka Bhadram <varkab@cdac.in>
> 
> Straight forward clean-up. Patch applied.

You should probably drop this one (or remove the kfrees from the remove
callbacks as a follow up).

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/gpio/gpio-adp5588.c b/drivers/gpio/gpio-adp5588.c
index 3beed6e..0de8c70 100644
--- a/drivers/gpio/gpio-adp5588.c
+++ b/drivers/gpio/gpio-adp5588.c
@@ -378,7 +378,7 @@  static int adp5588_gpio_probe(struct i2c_client *client,
 		return -EIO;
 	}
 
-	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	dev = devm_kzalloc(&client->dev, sizeof(*dev), GFP_KERNEL);
 	if (dev == NULL)
 		return -ENOMEM;
 
@@ -446,7 +446,6 @@  static int adp5588_gpio_probe(struct i2c_client *client,
 err_irq:
 	adp5588_irq_teardown(dev);
 err:
-	kfree(dev);
 	return ret;
 }
 
diff --git a/drivers/gpio/gpio-mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c
index eea5d7e..a17b81f 100644
--- a/drivers/gpio/gpio-mcp23s08.c
+++ b/drivers/gpio/gpio-mcp23s08.c
@@ -949,10 +949,12 @@  static int mcp23s08_probe(struct spi_device *spi)
 	if (!chips)
 		return -ENODEV;
 
-	data = kzalloc(sizeof(*data) + chips * sizeof(struct mcp23s08),
-			GFP_KERNEL);
+	data = devm_kzalloc(&spi->dev,
+			    sizeof(*data) + chips * sizeof(struct mcp23s08),
+			    GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
+
 	spi_set_drvdata(spi, data);
 
 	spi->irq = irq_of_parse_and_map(spi->dev.of_node, 0);
@@ -989,7 +991,6 @@  fail:
 			continue;
 		gpiochip_remove(&data->mcp[addr]->chip);
 	}
-	kfree(data);
 	return status;
 }