Skip to content

Commit 75d2a97

Browse files
committed
mtd: spi_nor: pass DMA-able buffer to spi_nor_read_raw()
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: b038e8e ("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> (cherry picked from commit 1d5ceff) Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
1 parent f387ab1 commit 75d2a97

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

drivers/mtd/spi-nor/spi-nor.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ spi_nor_set_pp_settings(struct spi_nor_pp_command *pp,
21042104
* @nor: pointer to a 'struct spi_nor'
21052105
* @addr: offset in the serial flash memory
21062106
* @len: number of bytes to read
2107-
* @buf: buffer where the data is copied into
2107+
* @buf: buffer where the data is copied into (dma-safe memory)
21082108
*
21092109
* Return: 0 on success, -errno otherwise.
21102110
*/
@@ -2811,11 +2811,17 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
28112811
u8 smpt_len)
28122812
{
28132813
const u32 *ret;
2814+
u8 *buf;
28142815
u32 addr;
28152816
int err;
28162817
u8 i;
28172818
u8 addr_width, read_opcode, read_dummy;
2818-
u8 read_data_mask, data_byte, map_id;
2819+
u8 read_data_mask, map_id;
2820+
2821+
/* Use a kmalloc'ed bounce buffer to guarantee it is DMA-able. */
2822+
buf = kmalloc(sizeof(*buf), GFP_KERNEL);
2823+
if (!buf)
2824+
return ERR_PTR(-ENOMEM);
28192825

28202826
addr_width = nor->addr_width;
28212827
read_dummy = nor->read_dummy;
@@ -2833,7 +2839,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
28332839
nor->read_opcode = SMPT_CMD_OPCODE(smpt[i]);
28342840
addr = smpt[i + 1];
28352841

2836-
err = spi_nor_read_raw(nor, addr, 1, &data_byte);
2842+
err = spi_nor_read_raw(nor, addr, 1, buf);
28372843
if (err) {
28382844
ret = ERR_PTR(err);
28392845
goto out;
@@ -2843,7 +2849,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
28432849
* Build an index value that is used to select the Sector Map
28442850
* Configuration that is currently in use.
28452851
*/
2846-
map_id = map_id << 1 | !!(data_byte & read_data_mask);
2852+
map_id = map_id << 1 | !!(*buf & read_data_mask);
28472853
}
28482854

28492855
/*
@@ -2874,6 +2880,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
28742880

28752881
/* fall through */
28762882
out:
2883+
kfree(buf);
28772884
nor->addr_width = addr_width;
28782885
nor->read_dummy = read_dummy;
28792886
nor->read_opcode = read_opcode;

0 commit comments

Comments
 (0)