[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240701232634.0bddb542ddea123b48dcabdf@linux-foundation.org>
Date: Mon, 1 Jul 2024 23:26:34 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Thorsten Blum <thorsten.blum@...lux.com>
Cc: jack@...e.cz, surenb@...gle.com, linux-kernel@...r.kernel.org, Christoph
Hellwig <hch@....de>
Subject: Re: [PATCH] dma-buf: Remove unnecessary kmalloc() cast
On Sun, 30 Jun 2024 03:12:16 +0200 Thorsten Blum <thorsten.blum@...lux.com> wrote:
> Casting the return value of kmalloc() is unnecessary and can be
> removed. Remove it and fix the following Coccinelle/coccicheck warning
> reported by alloc_cast.cocci:
>
> WARNING: casting value returned by memory allocation function to (struct dma_fence_chain *) is useless.
>
> Compile-tested only.
>
> ...
>
> --- a/include/linux/dma-fence-chain.h
> +++ b/include/linux/dma-fence-chain.h
> @@ -87,7 +87,7 @@ dma_fence_chain_contained(struct dma_fence *fence)
> * Returns a new struct dma_fence_chain object or NULL on failure.
> */
> #define dma_fence_chain_alloc() \
> - ((struct dma_fence_chain *)kmalloc(sizeof(struct dma_fence_chain), GFP_KERNEL))
> + kmalloc(sizeof(struct dma_fence_chain), GFP_KERNEL)
>
> /**
> * dma_fence_chain_free
No, I do think the cast is useful:
struct page *page = dma_fence_chain_alloc();
will presently generate a warning. We want this. Your change will
remove that useful warning.
Unrelatedly: there is no earthly reason why this is implemented as a
macro. A static inline function would be so much better. Why do we
keep doing this.
Powered by blists - more mailing lists