[PATCH 19/21] mtd: Nand: Use dev_add_param_bool for erasebad parameter

Alexander Aring alex.aring at gmail.com
Sun Apr 7 18:35:38 EDT 2013


Hi Sascha,

On Sun, Apr 07, 2013 at 04:00:53PM +0200, Sascha Hauer wrote:
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  drivers/mtd/nand/nand_base.c | 22 ++++++++++++----------
>  include/linux/mtd/mtd.h      |  1 +
>  2 files changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index fa10d95..67e913a 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -1672,18 +1672,20 @@ EXPORT_SYMBOL(nand_scan_ident);
>  EXPORT_SYMBOL(nand_scan_tail);
>  EXPORT_SYMBOL(nand_release);
>  
> -static int mtd_set_erasebad(struct device_d *dev, struct param_d *param,
> -		const char *val)
> +static int mtd_set_erasebad(struct param_d *param, void *priv)
>  {
> -	struct mtd_info *mtd = container_of(dev, struct mtd_info, class_dev);
> -	int erasebad;
> +	struct mtd_info *mtd = priv;
>  
> -	erasebad = simple_strtoul(val, NULL, 0);
> +	if (!mtd->p_allow_erasebad) {
> +		mtd->allow_erasebad = false;
> +		return 0;
> +	}
>
> -	if (erasebad && !mtd->allow_erasebad)
> -		dev_warn(dev, "Allowing to erase bad blocks. This may be dangerous!\n");
> +	if (!mtd->allow_erasebad)
> +		dev_warn(&mtd->class_dev,
> +			"Allowing to erase bad blocks. This may be dangerous!\n");
>  
> -	mtd->allow_erasebad = erasebad ? true : false;
> +	mtd->allow_erasebad = true;
>  
>  	return 0;

I think we need to change it to:

...
dev_warn(....);
mtd->allow_erasebad = true;

return 0;

without condition.

The reason is that we are already in the truth "allow_erasebad" part after
the check of (!mtd->p_allow_erasebad).
The branch on (!mtd->allow_erasebad) is will never reach and we need to
print out the dev_warn when (mtd->allow_erasebad) is turning on?

I think we can drop this condition here.

Alex



More information about the barebox mailing list