2020-01-05 17:42:31

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH] gtp: simplify error handling code in 'gtp_encap_enable()'

'gtp_encap_disable_sock(sk)' handles the case where sk is NULL, so there
is no need to test it before calling the function.

This saves a few line of code.

Signed-off-by: Christophe JAILLET <[email protected]>
---
drivers/net/gtp.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
index ecfe26215935..1499b4a37758 100644
--- a/drivers/net/gtp.c
+++ b/drivers/net/gtp.c
@@ -849,8 +849,7 @@ static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[])

sk1u = gtp_encap_enable_socket(fd1, UDP_ENCAP_GTP1U, gtp);
if (IS_ERR(sk1u)) {
- if (sk0)
- gtp_encap_disable_sock(sk0);
+ gtp_encap_disable_sock(sk0);
return PTR_ERR(sk1u);
}
}
@@ -858,10 +857,8 @@ static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[])
if (data[IFLA_GTP_ROLE]) {
role = nla_get_u32(data[IFLA_GTP_ROLE]);
if (role > GTP_ROLE_SGSN) {
- if (sk0)
- gtp_encap_disable_sock(sk0);
- if (sk1u)
- gtp_encap_disable_sock(sk1u);
+ gtp_encap_disable_sock(sk0);
+ gtp_encap_disable_sock(sk1u);
return -EINVAL;
}
}
--
2.20.1


2020-01-06 09:00:40

by Simon Horman

[permalink] [raw]
Subject: Re: [PATCH] gtp: simplify error handling code in 'gtp_encap_enable()'

On Sun, Jan 05, 2020 at 06:36:07PM +0100, Christophe JAILLET wrote:
> 'gtp_encap_disable_sock(sk)' handles the case where sk is NULL, so there
> is no need to test it before calling the function.
>
> This saves a few line of code.
>
> Signed-off-by: Christophe JAILLET <[email protected]>

Reviewed-by: Simon Horman <[email protected]>

2020-01-06 21:40:55

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] gtp: simplify error handling code in 'gtp_encap_enable()'

From: Christophe JAILLET <[email protected]>
Date: Sun, 5 Jan 2020 18:36:07 +0100

> 'gtp_encap_disable_sock(sk)' handles the case where sk is NULL, so there
> is no need to test it before calling the function.
>
> This saves a few line of code.
>
> Signed-off-by: Christophe JAILLET <[email protected]>

Applied to net-next.