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

Sascha Hauer s.hauer at pengutronix.de
Mon Apr 8 04:11:43 EDT 2013


On Mon, Apr 08, 2013 at 12:35:38AM +0200, Alexander Aring wrote:
> 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.

When we drop the condition we get this message everytime we do
nand0.erasebad=1. I only want to have it once when it is enabled
(and was disabled before).

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list