mtd: spi_nor: pass DMA-able buffer to spi_nor_read_raw()
authorTudor.Ambarus@microchip.com <Tudor.Ambarus@microchip.com>
Fri, 9 Nov 2018 16:56:54 +0000 (16:56 +0000)
committerBoris Brezillon <boris.brezillon@bootlin.com>
Tue, 13 Nov 2018 19:37:34 +0000 (20:37 +0100)
spi_nor_read_raw() calls nor->read() which might be implemented
by the m25p80 driver. m25p80 uses the spi-mem layer which requires
DMA-able in/out buffers. Pass kmalloc'ed dma buffer to spi_nor_read_raw().

Fixes: b038e8e3be72 ("mtd: spi-nor: parse SFDP Sector Map Parameter Table")
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
drivers/mtd/spi-nor/spi-nor.c

index 7f03be9b54bcf22bbc13d0bc1441683649976cef..eb7bb596416b037e7e2b5d3de4c9722c48ae9b6c 100644 (file)
@@ -2156,7 +2156,7 @@ spi_nor_set_pp_settings(struct spi_nor_pp_command *pp,
  * @nor:       pointer to a 'struct spi_nor'
  * @addr:      offset in the serial flash memory
  * @len:       number of bytes to read
- * @buf:       buffer where the data is copied into
+ * @buf:       buffer where the data is copied into (dma-safe memory)
  *
  * Return: 0 on success, -errno otherwise.
  */
@@ -2863,11 +2863,17 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
                                         u8 smpt_len)
 {
        const u32 *ret;
+       u8 *buf;
        u32 addr;
        int err;
        u8 i;
        u8 addr_width, read_opcode, read_dummy;
-       u8 read_data_mask, data_byte, map_id;
+       u8 read_data_mask, map_id;
+
+       /* Use a kmalloc'ed bounce buffer to guarantee it is DMA-able. */
+       buf = kmalloc(sizeof(*buf), GFP_KERNEL);
+       if (!buf)
+               return ERR_PTR(-ENOMEM);
 
        addr_width = nor->addr_width;
        read_dummy = nor->read_dummy;
@@ -2885,7 +2891,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
                nor->read_opcode = SMPT_CMD_OPCODE(smpt[i]);
                addr = smpt[i + 1];
 
-               err = spi_nor_read_raw(nor, addr, 1, &data_byte);
+               err = spi_nor_read_raw(nor, addr, 1, buf);
                if (err) {
                        ret = ERR_PTR(err);
                        goto out;
@@ -2895,7 +2901,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
                 * Build an index value that is used to select the Sector Map
                 * Configuration that is currently in use.
                 */
-               map_id = map_id << 1 | !!(data_byte & read_data_mask);
+               map_id = map_id << 1 | !!(*buf & read_data_mask);
        }
 
        /*
@@ -2926,6 +2932,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
 
        /* fall through */
 out:
+       kfree(buf);
        nor->addr_width = addr_width;
        nor->read_dummy = read_dummy;
        nor->read_opcode = read_opcode;