Patchwork [12/13] i2c: viperboard: Use devm_kzalloc() functions

login
register
mail settings
Submitter Jingoo Han
Date Dec. 17, 2013, 7:01 a.m.
Message ID <003001cefaf5$d6618590$832490b0$%han@samsung.com>
Download mbox | patch
Permalink /patch/302014/
State Accepted
Headers show

Comments

Jingoo Han - Dec. 17, 2013, 7:01 a.m.
Use devm_kzalloc() functions to make cleanup paths simpler.

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
---
 drivers/i2c/busses/i2c-viperboard.c |   12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
Lars Poeschel - Dec. 19, 2013, 1:05 p.m.
Am Dienstag, 17. Dezember 2013, 16:01:41 schrieb Jingoo Han:
> Use devm_kzalloc() functions to make cleanup paths simpler.
> 
> Signed-off-by: Jingoo Han <jg1.han@samsung.com>
> ---
>  drivers/i2c/busses/i2c-viperboard.c |   12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-viperboard.c
> b/drivers/i2c/busses/i2c-viperboard.c index c68450c..6976e1c 100644
> --- a/drivers/i2c/busses/i2c-viperboard.c
> +++ b/drivers/i2c/busses/i2c-viperboard.c
> @@ -367,7 +367,7 @@ static int vprbrd_i2c_probe(struct platform_device
> *pdev) int ret;
>  	int pipe;
> 
> -	vb_i2c = kzalloc(sizeof(*vb_i2c), GFP_KERNEL);
> +	vb_i2c = devm_kzalloc(&pdev->dev, sizeof(*vb_i2c), GFP_KERNEL);
>  	if (vb_i2c == NULL)
>  		return -ENOMEM;
> 
> @@ -394,14 +394,12 @@ static int vprbrd_i2c_probe(struct platform_device
> *pdev) if (ret != 1) {
>  		dev_err(&pdev->dev,
>  			"failure setting i2c_bus_freq to %d\n", i2c_bus_freq);
> -		ret = -EIO;
> -		goto error;
> +		return -EIO;
>  	    }
>  	} else {
>  		dev_err(&pdev->dev,
>  			"invalid i2c_bus_freq setting:%d\n", i2c_bus_freq);
> -		ret = -EIO;
> -		goto error;
> +		return -EIO;
>  	}
> 
>  	vb_i2c->i2c.dev.parent = &pdev->dev;
> @@ -412,10 +410,6 @@ static int vprbrd_i2c_probe(struct platform_device
> *pdev) platform_set_drvdata(pdev, vb_i2c);
> 
>  	return 0;
> -
> -error:
> -	kfree(vb_i2c);
> -	return ret;
>  }
> 
>  static int vprbrd_i2c_remove(struct platform_device *pdev)

Acked-by: Lars Poeschel <poeschel@lemonage.de>

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang - Jan. 4, 2014, 9:16 p.m.
On Tue, Dec 17, 2013 at 04:01:41PM +0900, Jingoo Han wrote:
> Use devm_kzalloc() functions to make cleanup paths simpler.
> 
> Signed-off-by: Jingoo Han <jg1.han@samsung.com>

OK, this one got an Ack and even fixes a bug (no kfree in remove) what
should have been mentioned in the commit message. Applied to for-next,
thanks!

Patch

diff --git a/drivers/i2c/busses/i2c-viperboard.c b/drivers/i2c/busses/i2c-viperboard.c
index c68450c..6976e1c 100644
--- a/drivers/i2c/busses/i2c-viperboard.c
+++ b/drivers/i2c/busses/i2c-viperboard.c
@@ -367,7 +367,7 @@  static int vprbrd_i2c_probe(struct platform_device *pdev)
 	int ret;
 	int pipe;
 
-	vb_i2c = kzalloc(sizeof(*vb_i2c), GFP_KERNEL);
+	vb_i2c = devm_kzalloc(&pdev->dev, sizeof(*vb_i2c), GFP_KERNEL);
 	if (vb_i2c == NULL)
 		return -ENOMEM;
 
@@ -394,14 +394,12 @@  static int vprbrd_i2c_probe(struct platform_device *pdev)
 	    if (ret != 1) {
 		dev_err(&pdev->dev,
 			"failure setting i2c_bus_freq to %d\n", i2c_bus_freq);
-		ret = -EIO;
-		goto error;
+		return -EIO;
 	    }
 	} else {
 		dev_err(&pdev->dev,
 			"invalid i2c_bus_freq setting:%d\n", i2c_bus_freq);
-		ret = -EIO;
-		goto error;
+		return -EIO;
 	}
 
 	vb_i2c->i2c.dev.parent = &pdev->dev;
@@ -412,10 +410,6 @@  static int vprbrd_i2c_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, vb_i2c);
 
 	return 0;
-
-error:
-	kfree(vb_i2c);
-	return ret;
 }
 
 static int vprbrd_i2c_remove(struct platform_device *pdev)