Re: [PATCH v1] mtd: rawnand: Add Macronix NAND read retry support

From: Thomas Petazzoni
Date: Tue May 14 2019 - 03:42:49 EST


Hello,

On Tue, 14 May 2019 09:53:16 +0800
masonccyang@xxxxxxxxxxx wrote:

> > > -------------------------------------------------------------------
> > > static void macronix_nand_onfi_init(struct nand_chip *chip)
> > > {
> > > struct nand_parameters *p = &chip->parameters;
> > > struct nand_onfi_vendor_macronix *mxic = (void
> > > *)p->onfi->vendor;
> >
> > Why cast to void*, instead of casting directly to struct
> > nand_onfi_vendor_macronix * ?
>
> Due to got a warning:
>
> warning: initialization from incompatible pointer type
> struct nand_onfi_vendor_macronix *mxic = p->onfi->vendor;

You didn't look at my code, I suggested:

mxic = (struct nand_onfi_vendor_macronix *) p->info->vendor;

I.e, you indeed still need a cast, because p->info->vendor is a u8[].
But instead of casting to void*, and then implicitly casting to struct
nand_onfi_vendor_macronix *, I suggest to cast directly to struct
nand_onfi_vendor_macronix *.

> > > if (!p->onfi ||
> > > ((mxic->reliability_func & MACRONIX_READ_RETRY_BIT) ==
> 0))
> > > return;
> >
> > So, the code should be:
> >
> > struct nand_onfi_vendor_macronix *mxic;
> >
> > if (!p->onfi)
> > return;
> >
> > mxic = (struct nand_onfi_vendor_macronix *) p->info->vendor;
> >
> > if ((mxic->reliability_func & MACRONIX_READ_RETRY_BIT) == 0)
> > return;
>
> Also got a warning:
>
> warning: ISO C90 forbids mixed declarations and code
> [-Wdeclaration-after-statement]

No, you don't get this warning if you use my code. You get this warning
if you declare and initialized the "mxic" variable at the same location.

> static void macronix_nand_onfi_init(struct nand_chip *chip)
> {
> struct nand_parameters *p = &chip->parameters;
> struct nand_onfi_vendor_macronix *mxic = (void *)p->onfi->vendor;

You are dereferencing p->info...

>
> if (!p->onfi)
> return;

... before you check it is NULL. This is wrong.

Please check again the code I sent in my previous e-mail:

struct nand_onfi_vendor_macronix *mxic;

if (!p->onfi)
return;

mxic = (struct nand_onfi_vendor_macronix *) p->info->vendor;

if ((mxic->reliability_func & MACRONIX_READ_RETRY_BIT) == 0)
return;

Best regards,

Thomas Petazzoni
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com