All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 net] ipv4: fix error path in fou_create()
@ 2021-08-08  7:05 Kangmin Park
  2021-08-08 20:05 ` David Ahern
  0 siblings, 1 reply; 2+ messages in thread
From: Kangmin Park @ 2021-08-08  7:05 UTC (permalink / raw)
  To: David S. Miller
  Cc: Hideaki YOSHIFUJI, David Ahern, Jakub Kicinski, netdev, linux-kernel

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;
 }
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3 net] ipv4: fix error path in fou_create()
  2021-08-08  7:05 [PATCH v3 net] ipv4: fix error path in fou_create() Kangmin Park
@ 2021-08-08 20:05 ` David Ahern
  0 siblings, 0 replies; 2+ messages in thread
From: David Ahern @ 2021-08-08 20:05 UTC (permalink / raw)
  To: Kangmin Park, David S. Miller
  Cc: Hideaki YOSHIFUJI, David Ahern, Jakub Kicinski, netdev, linux-kernel

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-08 20:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.