diff mbox

mtd: nand: don't make vendor-specific code un-set their data pointer

Message ID 20170502000455.13240-2-computersforpeace@gmail.com
State Changes Requested
Delegated to: Brian Norris
Headers show

Commit Message

Brian Norris May 2, 2017, 12:04 a.m. UTC
It makes sense to do this in nand_base.

(Alternatively: we don't really need to do this at all.)

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
Compile tested only

 drivers/mtd/nand/nand_base.c  | 11 +++++++++--
 drivers/mtd/nand/nand_hynix.c |  1 -
 2 files changed, 9 insertions(+), 3 deletions(-)

Comments

Boris Brezillon May 2, 2017, 7:15 a.m. UTC | #1
On Mon,  1 May 2017 17:04:51 -0700
Brian Norris <computersforpeace@gmail.com> wrote:

> It makes sense to do this in nand_base.
> 
> (Alternatively: we don't really need to do this at all.)

Actually, I was just trying to handle a potential 'double-free' error
nicely (see the 'if (hynix) return;' statement at the beginning of
hynix_nand_cleanup(), but I'm not sure this was a good idea.

Let's drop this assignment.

> 
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> ---
> Compile tested only
> 
>  drivers/mtd/nand/nand_base.c  | 11 +++++++++--
>  drivers/mtd/nand/nand_hynix.c |  1 -
>  2 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index ed49a1d634b0..2adcc8cdedf1 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -3910,11 +3910,16 @@ static void nand_manufacturer_detect(struct nand_chip *chip)
>   */
>  static int nand_manufacturer_init(struct nand_chip *chip)
>  {
> +	int ret;
> +
>  	if (!chip->manufacturer.desc || !chip->manufacturer.desc->ops ||
>  	    !chip->manufacturer.desc->ops->init)
>  		return 0;
>  
> -	return chip->manufacturer.desc->ops->init(chip);
> +	ret = chip->manufacturer.desc->ops->init(chip);
> +	if (ret)
> +		nand_set_manufacturer_data(chip, NULL);
> +	return ret;
>  }
>  
>  /*
> @@ -3927,8 +3932,10 @@ static void nand_manufacturer_cleanup(struct nand_chip *chip)
>  {
>  	/* Release manufacturer private data */
>  	if (chip->manufacturer.desc && chip->manufacturer.desc->ops &&
> -	    chip->manufacturer.desc->ops->cleanup)
> +	    chip->manufacturer.desc->ops->cleanup) {
>  		chip->manufacturer.desc->ops->cleanup(chip);
> +		nand_set_manufacturer_data(chip, NULL);
> +	}
>  }
>  
>  /*
> diff --git a/drivers/mtd/nand/nand_hynix.c b/drivers/mtd/nand/nand_hynix.c
> index b12dc7325378..54d99f90aa9f 100644
> --- a/drivers/mtd/nand/nand_hynix.c
> +++ b/drivers/mtd/nand/nand_hynix.c
> @@ -598,7 +598,6 @@ static void hynix_nand_cleanup(struct nand_chip *chip)
>  
>  	kfree(hynix->read_retry);
>  	kfree(hynix);
> -	nand_set_manufacturer_data(chip, NULL);
>  }
>  
>  static int hynix_nand_init(struct nand_chip *chip)
diff mbox

Patch

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ed49a1d634b0..2adcc8cdedf1 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3910,11 +3910,16 @@  static void nand_manufacturer_detect(struct nand_chip *chip)
  */
 static int nand_manufacturer_init(struct nand_chip *chip)
 {
+	int ret;
+
 	if (!chip->manufacturer.desc || !chip->manufacturer.desc->ops ||
 	    !chip->manufacturer.desc->ops->init)
 		return 0;
 
-	return chip->manufacturer.desc->ops->init(chip);
+	ret = chip->manufacturer.desc->ops->init(chip);
+	if (ret)
+		nand_set_manufacturer_data(chip, NULL);
+	return ret;
 }
 
 /*
@@ -3927,8 +3932,10 @@  static void nand_manufacturer_cleanup(struct nand_chip *chip)
 {
 	/* Release manufacturer private data */
 	if (chip->manufacturer.desc && chip->manufacturer.desc->ops &&
-	    chip->manufacturer.desc->ops->cleanup)
+	    chip->manufacturer.desc->ops->cleanup) {
 		chip->manufacturer.desc->ops->cleanup(chip);
+		nand_set_manufacturer_data(chip, NULL);
+	}
 }
 
 /*
diff --git a/drivers/mtd/nand/nand_hynix.c b/drivers/mtd/nand/nand_hynix.c
index b12dc7325378..54d99f90aa9f 100644
--- a/drivers/mtd/nand/nand_hynix.c
+++ b/drivers/mtd/nand/nand_hynix.c
@@ -598,7 +598,6 @@  static void hynix_nand_cleanup(struct nand_chip *chip)
 
 	kfree(hynix->read_retry);
 	kfree(hynix);
-	nand_set_manufacturer_data(chip, NULL);
 }
 
 static int hynix_nand_init(struct nand_chip *chip)