mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: kernel-janitors@vger.kernel.org,
	"Ahelenia Ziemiańska" <nabijaczleweli@nabijaczleweli.xyz>,
	"Li kunyu" <kunyu@nfschina.com>, "Michal Hocko" <mhocko@suse.com>,
	"Sebastian Reichel" <sebastian.reichel@collabora.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Zhang Zhengming" <zhang.zhengming@h3c.com>,
	"Zhou Kete" <zhou.kete@h3c.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kernel: relay: Improve exception handling in relay_create_buf()
Date: Tue, 2 Jan 2024 11:31:17 -0800	[thread overview]
Message-ID: <20240102113117.b2b4ffa2998eb51b674b0304@linux-foundation.org> (raw)
In-Reply-To: <ef8b36bf-d9d7-46a4-9648-7cc8aaa8a980@web.de>

On Sun, 31 Dec 2023 10:38:10 +0100 Markus Elfring <Markus.Elfring@web.de> wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 31 Dec 2023 10:26:25 +0100
> 
> The kfree() function was called in one case by
> the relay_create_buf() function during error handling
> even if the passed data structure member contained a null pointer.
> This issue was detected by using the Coccinelle software.
> 
> Thus use another label.
> 
> ...
>
> --- a/kernel/relay.c
> +++ b/kernel/relay.c
> @@ -161,14 +161,15 @@ static struct rchan_buf *relay_create_buf(struct rchan *chan)
> 
>  	buf->start = relay_alloc_buf(buf, &chan->alloc_size);
>  	if (!buf->start)
> -		goto free_buf;
> +		goto free_padding;
> 
>  	buf->chan = chan;
>  	kref_get(&buf->chan->kref);
>  	return buf;
> 
> -free_buf:
> +free_padding:
>  	kfree(buf->padding);
> +free_buf:
>  	kfree(buf);
>  	return NULL;
>  }

kfree(NULL) is an OK thing to do, and is a well-known pattern.  Can we
arrange for Coccinelle to understand this?

      reply	other threads:[~2024-01-02 19:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-31  9:38 Markus Elfring
2024-01-02 19:31 ` Andrew Morton [this message]

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=20240102113117.b2b4ffa2998eb51b674b0304@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=Markus.Elfring@web.de \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kunyu@nfschina.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.com \
    --cc=nabijaczleweli@nabijaczleweli.xyz \
    --cc=sebastian.reichel@collabora.com \
    --cc=surenb@google.com \
    --cc=zhang.zhengming@h3c.com \
    --cc=zhou.kete@h3c.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

all inboxes | Powered by JetHome®