diff mbox series

[03/10] mtd: rawnand: fsl_upm: Allocate the fsl_upm_nand object using devm_kzalloc()

Message ID 20200603134922.1352340-4-boris.brezillon@collabora.com
State Accepted
Headers show
Series mtd: rawnand: fsl_upm: Convert to exec_op() (and more) | expand

Commit Message

Boris Brezillon June 3, 2020, 1:49 p.m. UTC
This simplifies the init error patch and remove function.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
 drivers/mtd/nand/raw/fsl_upm.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

Comments

Miquel Raynal June 3, 2020, 1:52 p.m. UTC | #1
Boris Brezillon <boris.brezillon@collabora.com> wrote on Wed,  3 Jun
2020 15:49:15 +0200:

> This simplifies the init error patch and remove function.

                                 path?

Otherwise:

Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>

> 
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
>  drivers/mtd/nand/raw/fsl_upm.c | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/fsl_upm.c b/drivers/mtd/nand/raw/fsl_upm.c
> index 6eba2f4a2f5a..9cf79c62ef22 100644
> --- a/drivers/mtd/nand/raw/fsl_upm.c
> +++ b/drivers/mtd/nand/raw/fsl_upm.c
> @@ -205,36 +205,34 @@ static int fun_probe(struct platform_device *ofdev)
>  	int size;
>  	int i;
>  
> -	fun = kzalloc(sizeof(*fun), GFP_KERNEL);
> +	fun = devm_kzalloc(&ofdev->dev, sizeof(*fun), GFP_KERNEL);
>  	if (!fun)
>  		return -ENOMEM;
>  
>  	ret = of_address_to_resource(ofdev->dev.of_node, 0, &io_res);
>  	if (ret) {
>  		dev_err(&ofdev->dev, "can't get IO base\n");
> -		goto err1;
> +		return ret;
>  	}
>  
>  	ret = fsl_upm_find(io_res.start, &fun->upm);
>  	if (ret) {
>  		dev_err(&ofdev->dev, "can't find UPM\n");
> -		goto err1;
> +		return ret;
>  	}
>  
>  	prop = of_get_property(ofdev->dev.of_node, "fsl,upm-addr-offset",
>  			       &size);
>  	if (!prop || size != sizeof(uint32_t)) {
>  		dev_err(&ofdev->dev, "can't get UPM address offset\n");
> -		ret = -EINVAL;
> -		goto err1;
> +		return -EINVAL;
>  	}
>  	fun->upm_addr_offset = *prop;
>  
>  	prop = of_get_property(ofdev->dev.of_node, "fsl,upm-cmd-offset", &size);
>  	if (!prop || size != sizeof(uint32_t)) {
>  		dev_err(&ofdev->dev, "can't get UPM command offset\n");
> -		ret = -EINVAL;
> -		goto err1;
> +		return -EINVAL;
>  	}
>  	fun->upm_cmd_offset = *prop;
>  
> @@ -244,7 +242,7 @@ static int fun_probe(struct platform_device *ofdev)
>  		fun->mchip_count = size / sizeof(uint32_t);
>  		if (fun->mchip_count >= NAND_MAX_CHIPS) {
>  			dev_err(&ofdev->dev, "too much multiple chips\n");
> -			goto err1;
> +			return -EINVAL;
>  		}
>  		for (i = 0; i < fun->mchip_count; i++)
>  			fun->mchip_offsets[i] = be32_to_cpu(prop[i]);
> @@ -306,8 +304,6 @@ static int fun_probe(struct platform_device *ofdev)
>  			break;
>  		gpio_free(fun->rnb_gpio[i]);
>  	}
> -err1:
> -	kfree(fun);
>  
>  	return ret;
>  }
> @@ -330,8 +326,6 @@ static int fun_remove(struct platform_device *ofdev)
>  		gpio_free(fun->rnb_gpio[i]);
>  	}
>  
> -	kfree(fun);
> -
>  	return 0;
>  }
>
Miquel Raynal June 15, 2020, 9:02 a.m. UTC | #2
On Wed, 2020-06-03 at 13:49:15 UTC, Boris Brezillon wrote:
> This simplifies the init error patch and remove function.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel
diff mbox series

Patch

diff --git a/drivers/mtd/nand/raw/fsl_upm.c b/drivers/mtd/nand/raw/fsl_upm.c
index 6eba2f4a2f5a..9cf79c62ef22 100644
--- a/drivers/mtd/nand/raw/fsl_upm.c
+++ b/drivers/mtd/nand/raw/fsl_upm.c
@@ -205,36 +205,34 @@  static int fun_probe(struct platform_device *ofdev)
 	int size;
 	int i;
 
-	fun = kzalloc(sizeof(*fun), GFP_KERNEL);
+	fun = devm_kzalloc(&ofdev->dev, sizeof(*fun), GFP_KERNEL);
 	if (!fun)
 		return -ENOMEM;
 
 	ret = of_address_to_resource(ofdev->dev.of_node, 0, &io_res);
 	if (ret) {
 		dev_err(&ofdev->dev, "can't get IO base\n");
-		goto err1;
+		return ret;
 	}
 
 	ret = fsl_upm_find(io_res.start, &fun->upm);
 	if (ret) {
 		dev_err(&ofdev->dev, "can't find UPM\n");
-		goto err1;
+		return ret;
 	}
 
 	prop = of_get_property(ofdev->dev.of_node, "fsl,upm-addr-offset",
 			       &size);
 	if (!prop || size != sizeof(uint32_t)) {
 		dev_err(&ofdev->dev, "can't get UPM address offset\n");
-		ret = -EINVAL;
-		goto err1;
+		return -EINVAL;
 	}
 	fun->upm_addr_offset = *prop;
 
 	prop = of_get_property(ofdev->dev.of_node, "fsl,upm-cmd-offset", &size);
 	if (!prop || size != sizeof(uint32_t)) {
 		dev_err(&ofdev->dev, "can't get UPM command offset\n");
-		ret = -EINVAL;
-		goto err1;
+		return -EINVAL;
 	}
 	fun->upm_cmd_offset = *prop;
 
@@ -244,7 +242,7 @@  static int fun_probe(struct platform_device *ofdev)
 		fun->mchip_count = size / sizeof(uint32_t);
 		if (fun->mchip_count >= NAND_MAX_CHIPS) {
 			dev_err(&ofdev->dev, "too much multiple chips\n");
-			goto err1;
+			return -EINVAL;
 		}
 		for (i = 0; i < fun->mchip_count; i++)
 			fun->mchip_offsets[i] = be32_to_cpu(prop[i]);
@@ -306,8 +304,6 @@  static int fun_probe(struct platform_device *ofdev)
 			break;
 		gpio_free(fun->rnb_gpio[i]);
 	}
-err1:
-	kfree(fun);
 
 	return ret;
 }
@@ -330,8 +326,6 @@  static int fun_remove(struct platform_device *ofdev)
 		gpio_free(fun->rnb_gpio[i]);
 	}
 
-	kfree(fun);
-
 	return 0;
 }