[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALAqxLW5uEZCGHGk3rYoiOGzN5XMKb39JzoPB1iEX9k3UsiT-A@mail.gmail.com>
Date: Wed, 19 Jan 2022 19:48:55 -0800
From: John Stultz <john.stultz@...aro.org>
To: guangming.cao@...iatek.com
Cc: benjamin.gaignard@...aro.org, bo.song@...iatek.com,
christian.koenig@....com, dri-devel@...ts.freedesktop.org,
jianjiao.zeng@...iatek.com, labbott@...hat.com,
libo.kang@...iatek.com, linaro-mm-sig@...ts.linaro.org,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
linux-media@...r.kernel.org, linux-mediatek@...ts.infradead.org,
lmark@...eaurora.org, matthias.bgg@...il.com,
michael.j.ruhl@...el.com, mingyuan.ma@...iatek.com,
sumit.semwal@...aro.org, wsd_upstream@...iatek.com,
yf.wang@...iatek.com, caoguangming34@...il.com
Subject: Re: [PATCH v4] dma-buf: system_heap: Add a size check for allocation
On Wed, Jan 19, 2022 at 7:34 PM <guangming.cao@...iatek.com> wrote:
>
> From: Guangming <Guangming.Cao@...iatek.com>
>
> Add a size check for allocation since the allocation size should be
> always less than the total DRAM size on system heap.
> And it can prevent consuming too much time for invalid allocations.
>
> Signed-off-by: Guangming <Guangming.Cao@...iatek.com>
> ---
> drivers/dma-buf/heaps/system_heap.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
> index 23a7e74ef966..bd6f255620e2 100644
> --- a/drivers/dma-buf/heaps/system_heap.c
> +++ b/drivers/dma-buf/heaps/system_heap.c
> @@ -347,6 +347,13 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
> struct page *page, *tmp_page;
> int i, ret = -ENOMEM;
>
> + /*
> + * Size check. The "len" should be less than totalram since system_heap
> + * memory is comes from system. Adding check here can prevent consuming
> + * too much time for invalid allocations.
> + */
> + if (len >> PAGE_SHIFT > totalram_pages())
> + return -EINVAL;
Thanks so much for revising and sending this along! It looks good to me.
Acked-by: John Stultz <john.stultz@...aro.org>
thanks again
-john
Powered by blists - more mailing lists