• Cyrille Pitchen's avatar
    mtd: spi-nor: fix DMA unsafe buffer issue in spi_nor_read_sfdp() · bfa41337
    Cyrille Pitchen authored
    spi_nor_read_sfdp() calls nor->read() to read the SFDP data.
    When the m25p80 driver is used (pretty common case), nor->read() is then
    implemented by the m25p80_read() function, which is likely to initialize a
    'struct spi_transfer' from its buf argument before appending this
    structure inside the 'struct spi_message' argument of spi_sync().
    
    Besides the SPI sub-system states that both .tx_buf and .rx_buf members of
    'struct spi_transfer' must point into dma-safe memory. However, two of the
    three calls of spi_nor_read_sfdp() were given pointers to stack allocated
    memory as buf argument, hence not in a dma-safe area.
    Hopefully, the third and last call of spi_nor_read_sfdp() was already
    given a kmalloc'ed buffer argument, hence dma-safe.
    
    So this patch fixes this issue by introducing a
    spi_nor_read_sfdp_dma_unsafe() function which simply wraps the existing
    spi_nor_read_sfdp() function and uses some kmalloc'ed memory as a bounce
    buffer.
    
    Fixes: f384b352 ("mtd: spi-nor: parse Serial Flash Discoverable Parameters (SFDP) tables")
    Reported-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
    Signed-off-by: default avatarCyrille Pitchen <cyrille.pitchen@wedev4u.fr>
    Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
    bfa41337
spi-nor.c 81.4 KB