public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Thorsten Blum <thorsten.blum@toblux.com>
Cc: jack@suse.cz, surenb@google.com, linux-kernel@vger.kernel.org,
	Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH] dma-buf: Remove unnecessary kmalloc() cast
Date: Mon, 1 Jul 2024 23:26:34 -0700	[thread overview]
Message-ID: <20240701232634.0bddb542ddea123b48dcabdf@linux-foundation.org> (raw)
In-Reply-To: <20240630011215.42525-1-thorsten.blum@toblux.com>

On Sun, 30 Jun 2024 03:12:16 +0200 Thorsten Blum <thorsten.blum@toblux.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.

  reply	other threads:[~2024-07-02  6:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-30  1:12 [PATCH] dma-buf: Remove unnecessary kmalloc() cast Thorsten Blum
2024-07-02  6:26 ` Andrew Morton [this message]
2024-07-02  6:40   ` Christoph Hellwig
2024-07-02  7:13     ` Christian König
2024-07-02  7:33       ` Andrew Morton
2024-07-02  7:35         ` Christoph Hellwig
2024-07-02 15:15         ` Suren Baghdasaryan
2024-07-03 17:45           ` Suren Baghdasaryan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240701232634.0bddb542ddea123b48dcabdf@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=thorsten.blum@toblux.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox