On 22/03/21 04:32PM, Michael Walle wrote:
Am 2021-03-22 15:21, schrieb Pratyush Yadav:
> On 18/03/21 10:24AM, Michael Walle wrote:
> > +
> > + sfdp->num_dwords = DIV_ROUND_UP(sfdp_size, sizeof(*sfdp->dwords));
>
> The SFDP spec says that Parameter Table Pointer should be DWORD aligned
> and Parameter Table length is specified in number of DWORDs. So,
> sfdp_size should always be a multiple of 4. Any SFDP table where this is
> not true is an invalid one.
>
> Also, the spec says "Device behavior when the Read SFDP command crosses
> the SFDP structure boundary is not defined".
>
> So I think this should be a check for alignment instead of a round-up.
Well, that woundn't help for debugging. I.e. you also want the SFDP data
in cases like this. IMHO we should try hard enough to actually get a
reasonable dump.
OTOH we also rely on the header and the pointers in the header. Any
other ideas, but just to chicken out?
Honestly, I don't think reading past the SFDP boundary would be too bad.
It probably will just be some garbage data. But if you want to avoid
that, you can always round down instead of up.
This way you will only
miss the last DWORD at most. In either case, a warning should be printed
so this problem can be brought to the user's attention.
> > + goto exit;
> > + }
> > +
> > + err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sfdp_size, sfdp->dwords);