lkml.org 
[lkml]   [2022]   [Jul]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] mm/dmapool.c: avoid duplicate memset within dma_pool_alloc
On Thu, 14 Jul 2022 11:25:00 +0800 Liu Song <liusong@linux.alibaba.com> wrote:

> From: Liu Song <liusong@linux.alibaba.com>
>
> In "dma_direct_alloc", the allocated memory is explicitly set to 0.
> If use direct alloc, we need to avoid possible duplicate memset in
> dma_pool_alloc.

I'm having trouble seeing how this change is safe and correct and
maintainable. Please describe the code flow more completely?

> --- a/mm/dmapool.c
> +++ b/mm/dmapool.c
> @@ -21,6 +21,7 @@
>
> #include <linux/device.h>
> #include <linux/dma-mapping.h>
> +#include <linux/dma-map-ops.h>
> #include <linux/dmapool.h>
> #include <linux/kernel.h>
> #include <linux/list.h>
> @@ -372,7 +373,7 @@ void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
> #endif
> spin_unlock_irqrestore(&pool->lock, flags);
>
> - if (want_init_on_alloc(mem_flags))
> + if (want_init_on_alloc(mem_flags) && get_dma_ops(pool->dev))
> memset(retval, 0, pool->size);

That DMAPOOL_DEBUG memset a couple of lines earlier could/should be
testing the same condition - there's no point in poisoning an area
which we're about to zero out.

\
 
 \ /
  Last update: 2022-07-17 03:01    [W:0.058 / U:0.180 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site