netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: Kangmin Park <l4stpr0gr4m@gmail.com>,
	"David S. Miller" <davem@davemloft.net>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
	David Ahern <dsahern@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 net] ipv4: fix error path in fou_create()
Date: Sun, 8 Aug 2021 14:05:31 -0600	[thread overview]
Message-ID: <751fe234-21cd-3a56-dff7-6768bbbfaaad@gmail.com> (raw)
In-Reply-To: <20210808070557.17858-1-l4stpr0gr4m@gmail.com>

On 8/8/21 1:05 AM, Kangmin Park wrote:
> sock is always NULL when udp_sock_create() is failed and fou is
> always NULL when kzalloc() is failed in error label.
> 
> So, add error_sock and error_alloc label and fix the error path
> in those cases.
> 
> Signed-off-by: Kangmin Park <l4stpr0gr4m@gmail.com>
> ---
> v3:
>  - change commit message
>  - fix error path
> ---
>  net/ipv4/fou.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/net/ipv4/fou.c b/net/ipv4/fou.c
> index e5f69b0bf3df..f1d99e776bb8 100644
> --- a/net/ipv4/fou.c
> +++ b/net/ipv4/fou.c
> @@ -572,13 +572,13 @@ static int fou_create(struct net *net, struct fou_cfg *cfg,
>  	/* Open UDP socket */
>  	err = udp_sock_create(net, &cfg->udp_config, &sock);
>  	if (err < 0)
> -		goto error;
> +		goto error_sock;
>  
>  	/* Allocate FOU port structure */
>  	fou = kzalloc(sizeof(*fou), GFP_KERNEL);
>  	if (!fou) {
>  		err = -ENOMEM;
> -		goto error;
> +		goto error_alloc;
>  	}
>  
>  	sk = sock->sk;
> @@ -627,9 +627,10 @@ static int fou_create(struct net *net, struct fou_cfg *cfg,
>  
>  error:
>  	kfree(fou);
> +error_alloc:
>  	if (sock)
>  		udp_tunnel_sock_release(sock);
> -
> +error_sock:
>  	return err;
>  }
>  
> 

since sock and fou are initialized to NULL, kfree(NULL) is allowed and
there is an 'if (sock)' check before the release, no fix is really needed.

      reply	other threads:[~2021-08-08 20:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-08  7:05 [PATCH v3 net] ipv4: fix error path in fou_create() Kangmin Park
2021-08-08 20:05 ` David Ahern [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=751fe234-21cd-3a56-dff7-6768bbbfaaad@gmail.com \
    --to=dsahern@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=kuba@kernel.org \
    --cc=l4stpr0gr4m@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=yoshfuji@linux-ipv6.org \
    /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;
as well as URLs for NNTP newsgroup(s).