[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <366bad2d-ebb3-a2a5-330d-ff9019d18733@microchip.com>
Date: Tue, 1 Feb 2022 07:44:13 +0000
From: <Tudor.Ambarus@...rochip.com>
To: <p.yadav@...com>, <broonie@...nel.org>
CC: <michael@...le.cc>, <miquel.raynal@...tlin.com>,
<tkuw584924@...il.com>, <linux-spi@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] spi: spi-mem: check if data buffers are on stack
On 1/31/22 13:45, Pratyush Yadav wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> The buffers passed in the data phase must be DMA-able. Programmers often
> don't realise this requirement and pass in buffers that reside on the
> stack. This can be hard to spot when reviewing code. Reject ops if their
> data buffer is on the stack to avoid this.
>
> Signed-off-by: Pratyush Yadav <p.yadav@...com>
> ---
> drivers/spi/spi-mem.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index 37f4443ce9a0..b3793a2979ee 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
> @@ -207,6 +207,15 @@ static int spi_mem_check_op(const struct spi_mem_op *op)
> !spi_mem_buswidth_is_valid(op->data.buswidth))
> return -EINVAL;
>
> + /* Buffers must be DMA-able. */
> + if (op->data.dir == SPI_MEM_DATA_IN &&
> + object_is_on_stack(op->data.buf.in))
should we also check if the virt addr is valid?
if (object_is_on_stack(op->data.buf.in) || !virt_addr_valid(op->data.buf.in))
Powered by blists - more mailing lists