Commit 8e093ea4 authored by Tudor Ambarus's avatar Tudor Ambarus Committed by Mark Brown

spi: atmel-quadspi: fix possible MMIO window size overrun

The QSPI controller memory space is limited to 128MB:
0x9000_00000-0x9800_00000/0XD000_0000--0XD800_0000.

There are nor flashes that are bigger in size than the memory size
supported by the controller: Micron MT25QL02G (256 MB).

Check if the address exceeds the MMIO window size. An improvement
would be to add support for regular SPI mode and fall back to it
when the flash memories overrun the controller's memory space.

Fixes: 0e6aae08 ("spi: Add QuadSPI driver for Atmel SAMA5D2")
Signed-off-by: default avatarTudor Ambarus <tudor.ambarus@microchip.com>
Link: https://lore.kernel.org/r/20200228155437.1558219-1-tudor.ambarus@microchip.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 5dd83049
...@@ -149,6 +149,7 @@ struct atmel_qspi { ...@@ -149,6 +149,7 @@ struct atmel_qspi {
struct clk *qspick; struct clk *qspick;
struct platform_device *pdev; struct platform_device *pdev;
const struct atmel_qspi_caps *caps; const struct atmel_qspi_caps *caps;
resource_size_t mmap_size;
u32 pending; u32 pending;
u32 mr; u32 mr;
u32 scr; u32 scr;
...@@ -329,6 +330,14 @@ static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) ...@@ -329,6 +330,14 @@ static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
u32 sr, offset; u32 sr, offset;
int err; int err;
/*
* Check if the address exceeds the MMIO window size. An improvement
* would be to add support for regular SPI mode and fall back to it
* when the flash memories overrun the controller's memory space.
*/
if (op->addr.val + op->data.nbytes > aq->mmap_size)
return -ENOTSUPP;
err = atmel_qspi_set_cfg(aq, op, &offset); err = atmel_qspi_set_cfg(aq, op, &offset);
if (err) if (err)
return err; return err;
...@@ -480,6 +489,8 @@ static int atmel_qspi_probe(struct platform_device *pdev) ...@@ -480,6 +489,8 @@ static int atmel_qspi_probe(struct platform_device *pdev)
goto exit; goto exit;
} }
aq->mmap_size = resource_size(res);
/* Get the peripheral clock */ /* Get the peripheral clock */
aq->pclk = devm_clk_get(&pdev->dev, "pclk"); aq->pclk = devm_clk_get(&pdev->dev, "pclk");
if (IS_ERR(aq->pclk)) if (IS_ERR(aq->pclk))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment