Re: [RESEND v5 05/21] mtd: rawnand: Return an enum from of_get_nand_ecc_algo()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 26 May 2020 21:56:17 +0200
Miquel Raynal <miquel.raynal@xxxxxxxxxxx> wrote:

> There is an enumeration to list ECC algorithm, let's use it instead of
> returning an int.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx>

Reviewed-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx>

> ---
>  drivers/mtd/nand/raw/nand_base.c | 35 +++++++++++++++++---------------
>  1 file changed, 19 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index 7176e513a0bb..a756f3193558 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -5048,17 +5048,20 @@ static const char * const nand_ecc_algos[] = {
>  	[NAND_ECC_RS]		= "rs",
>  };
>  
> -static int of_get_nand_ecc_algo(struct device_node *np)
> +static enum nand_ecc_algo of_get_nand_ecc_algo(struct device_node *np)
>  {
> +	enum nand_ecc_algo ecc_algo;
>  	const char *pm;
> -	int err, i;
> +	int err;
>  
>  	err = of_property_read_string(np, "nand-ecc-algo", &pm);
>  	if (!err) {
> -		for (i = NAND_ECC_HAMMING; i < ARRAY_SIZE(nand_ecc_algos); i++)
> -			if (!strcasecmp(pm, nand_ecc_algos[i]))
> -				return i;
> -		return -ENODEV;
> +		for (ecc_algo = NAND_ECC_HAMMING;
> +		     ecc_algo < ARRAY_SIZE(nand_ecc_algos);
> +		     ecc_algo++) {
> +			if (!strcasecmp(pm, nand_ecc_algos[ecc_algo]))
> +				return ecc_algo;
> +		}
>  	}
>  
>  	/*
> @@ -5066,15 +5069,14 @@ static int of_get_nand_ecc_algo(struct device_node *np)
>  	 * for some obsoleted values that were specifying ECC algorithm.
>  	 */
>  	err = of_property_read_string(np, "nand-ecc-mode", &pm);
> -	if (err < 0)
> -		return err;
> +	if (!err) {
> +		if (!strcasecmp(pm, "soft"))
> +			return NAND_ECC_HAMMING;
> +		else if (!strcasecmp(pm, "soft_bch"))
> +			return NAND_ECC_BCH;
> +	}
>  
> -	if (!strcasecmp(pm, "soft"))
> -		return NAND_ECC_HAMMING;
> -	else if (!strcasecmp(pm, "soft_bch"))
> -		return NAND_ECC_BCH;
> -
> -	return -ENODEV;
> +	return NAND_ECC_UNKNOWN;
>  }
>  
>  static int of_get_nand_ecc_step_size(struct device_node *np)
> @@ -5119,7 +5121,8 @@ static bool of_get_nand_on_flash_bbt(struct device_node *np)
>  static int nand_dt_init(struct nand_chip *chip)
>  {
>  	struct device_node *dn = nand_get_flash_node(chip);
> -	int ecc_mode, ecc_algo, ecc_strength, ecc_step;
> +	enum nand_ecc_algo ecc_algo;
> +	int ecc_mode, ecc_strength, ecc_step;
>  
>  	if (!dn)
>  		return 0;
> @@ -5141,7 +5144,7 @@ static int nand_dt_init(struct nand_chip *chip)
>  	if (ecc_mode >= 0)
>  		chip->ecc.mode = ecc_mode;
>  
> -	if (ecc_algo >= 0)
> +	if (ecc_algo != NAND_ECC_UNKNOWN)
>  		chip->ecc.algo = ecc_algo;
>  
>  	if (ecc_strength >= 0)




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux