diff mbox series

[v3,net] ipv4: fix error path in fou_create()

Message ID 20210808070557.17858-1-l4stpr0gr4m@gmail.com (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series [v3,net] ipv4: fix error path in fou_create() | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/header_inline success Link

Commit Message

Kangmin Park Aug. 8, 2021, 7:05 a.m. UTC
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(-)

Comments

David Ahern Aug. 8, 2021, 8:05 p.m. UTC | #1
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.
diff mbox series

Patch

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