Re: goofy mtd m25p80 patches in GIT ...

David Brownell
2008-10-20T08:21:03Z

On Monday 20 October 2008, Chen Gong-B11801 wrote:
>
> >
> > Second:
> >
> >
> > http://git.kernel.org/?p=linux/kernel/git/dwmw2/mtd-2.6.git;a=
> > commitdiff;h=75d0ee2202b5740e94e913d8a52f91c6557c4c81
> >
> > That's just plain wrong ... the original code is correct, but the
> > patch changed it to be incorrect. (DMA from the stack is never
> > legal.)
> >
> > Just revert this one entirely.
>
> I know spi_write_then_read is different from spi_write, but here n_rx & rxbuf are
> both NULL, which means no real read operation are executed. Would you please
> give me more explanation for potential hazard ?

Documentation/DMA-mapping.txt, in the "What memory is DMA'able?"
section (the first one after overview) lists several hazards.
I won't elaborate on that text, but it also states explicitly
that DMA from stacks is not allowed (para 4, sentence one).

Note that the spi_write_then_read() is documented as always
copying its (small) data buffers, while spi_write() just
passes it down to the spi_master driver ... which requires
DMA-safe memory, as described in "What memory is DMA'able?".

Have a look at the implementation of spi_write_then_read(),
in drivers/spi/spi.c ... one of the main reasons for that
routine is to make some of the common cases easier to work
with, by masking those DMA issues.

- Dave