diff mbox series

[net-next] netlink: let core handle error cases in dump operations

Message ID 20240306102426.245689-1-edumazet@google.com (mailing list archive)
State Accepted
Commit 02e24903e5a46b7a7fca44bcfe0cd6fa5b240c34
Delegated to: Netdev Maintainers
Headers show
Series [net-next] netlink: let core handle error cases in dump operations | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 942 this patch: 942
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 2 maintainers not CCed: idosch@nvidia.com dsahern@kernel.org
netdev/build_clang success Errors and warnings before: 957 this patch: 957
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 958 this patch: 958
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 68 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-03-06--21-00 (tests: 892)

Commit Message

Eric Dumazet March 6, 2024, 10:24 a.m. UTC
After commit b5a899154aa9 ("netlink: handle EMSGSIZE errors
in the core"), we can remove some code that was not 100 % correct
anyway.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/core/rtnetlink.c    | 5 +----
 net/ipv4/devinet.c      | 4 ----
 net/ipv4/fib_frontend.c | 7 +------
 net/ipv6/addrconf.c     | 7 +------
 4 files changed, 3 insertions(+), 20 deletions(-)

Comments

Simon Horman March 7, 2024, 9:35 a.m. UTC | #1
+ Ido Schimmel, David Ahern

On Wed, Mar 06, 2024 at 10:24:26AM +0000, Eric Dumazet wrote:
> After commit b5a899154aa9 ("netlink: handle EMSGSIZE errors
> in the core"), we can remove some code that was not 100 % correct
> anyway.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Thanks Eric,

this looks like a nice clean-up in combination with the cited commit.

Reviewed-by: Simon Horman <horms@kernel.org>

> ---
>  net/core/rtnetlink.c    | 5 +----
>  net/ipv4/devinet.c      | 4 ----
>  net/ipv4/fib_frontend.c | 7 +------
>  net/ipv6/addrconf.c     | 7 +------
>  4 files changed, 3 insertions(+), 20 deletions(-)
> 
> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> index 780b330f8ef9fa4881b9d51570d1a65f5171ee5d..7eac6765df098fd685937ace63dfb5add9c77731 100644
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -2267,11 +2267,8 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
>  				       nlh->nlmsg_seq, 0, flags,
>  				       ext_filter_mask, 0, NULL, 0,
>  				       netnsid, GFP_KERNEL);
> -		if (err < 0) {
> -			if (likely(skb->len))
> -				err = skb->len;
> +		if (err < 0)
>  			break;
> -		}
>  	}
>  	cb->seq = tgt_net->dev_base_seq;
>  	nl_dump_check_consistent(cb, nlmsg_hdr(skb));
> diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
> index 4daa8124f247c256c4f8c1ff29ac621570af0755..7a437f0d41905e6acfdc35743afba3a7abfd0dd5 100644
> --- a/net/ipv4/devinet.c
> +++ b/net/ipv4/devinet.c
> @@ -1900,8 +1900,6 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
>  			goto done;
>  	}
>  done:
> -	if (err < 0 && likely(skb->len))
> -		err = skb->len;
>  	if (fillargs.netnsid >= 0)
>  		put_net(tgt_net);
>  	rcu_read_unlock();
> @@ -2312,8 +2310,6 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
>  		ctx->all_default++;
>  	}
>  done:
> -	if (err < 0 && likely(skb->len))
> -		err = skb->len;
>  	rcu_read_unlock();
>  	return err;
>  }
> diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
> index bf3a2214fe29b6f9b494581b293259e6c5ce6f8c..48741352a88a72e0232977cc9f2cf172f45df89b 100644
> --- a/net/ipv4/fib_frontend.c
> +++ b/net/ipv4/fib_frontend.c
> @@ -1026,8 +1026,6 @@ static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
>  			goto unlock;
>  		}
>  		err = fib_table_dump(tb, skb, cb, &filter);
> -		if (err < 0 && skb->len)
> -			err = skb->len;
>  		goto unlock;
>  	}
>  
> @@ -1045,11 +1043,8 @@ static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
>  				memset(&cb->args[2], 0, sizeof(cb->args) -
>  						 2 * sizeof(cb->args[0]));
>  			err = fib_table_dump(tb, skb, cb, &filter);
> -			if (err < 0) {
> -				if (likely(skb->len))
> -					err = skb->len;
> +			if (err < 0)
>  				goto out;
> -			}
>  			dumped = 1;
>  next:
>  			e++;
> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index 2f84e6ecf19f48602cadb47bc378c9b5a1cdbf65..f786b65d12e43c53ed36535880f6e6d35879a44e 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ -793,8 +793,6 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
>  		ctx->all_default++;
>  	}
>  done:
> -	if (err < 0 && likely(skb->len))
> -		err = skb->len;
>  	rcu_read_unlock();
>  	return err;
>  }
> @@ -6158,11 +6156,8 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
>  					NETLINK_CB(cb->skb).portid,
>  					cb->nlh->nlmsg_seq,
>  					RTM_NEWLINK, NLM_F_MULTI);
> -		if (err < 0) {
> -			if (likely(skb->len))
> -				err = skb->len;
> +		if (err < 0)
>  			break;
> -		}
>  	}
>  	rcu_read_unlock();
>  
> -- 
> 2.44.0.278.ge034bb2e1d-goog
> 
>
Ido Schimmel March 7, 2024, 2:45 p.m. UTC | #2
On Thu, Mar 07, 2024 at 09:35:30AM +0000, Simon Horman wrote:
> + Ido Schimmel, David Ahern
> 
> On Wed, Mar 06, 2024 at 10:24:26AM +0000, Eric Dumazet wrote:
> > After commit b5a899154aa9 ("netlink: handle EMSGSIZE errors
> > in the core"), we can remove some code that was not 100 % correct
> > anyway.
> > 
> > Signed-off-by: Eric Dumazet <edumazet@google.com>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
David Ahern March 7, 2024, 7:32 p.m. UTC | #3
On 3/7/24 2:35 AM, Simon Horman wrote:
> + Ido Schimmel, David Ahern
> 
> On Wed, Mar 06, 2024 at 10:24:26AM +0000, Eric Dumazet wrote:
>> After commit b5a899154aa9 ("netlink: handle EMSGSIZE errors
>> in the core"), we can remove some code that was not 100 % correct
>> anyway.
>>
>> Signed-off-by: Eric Dumazet <edumazet@google.com>
> 
> Thanks Eric,
> 
> this looks like a nice clean-up in combination with the cited commit.

+1

> 
> Reviewed-by: Simon Horman <horms@kernel.org>
> 

Reviewed-by: David Ahern <dsahern@kernel.org>
patchwork-bot+netdevbpf@kernel.org March 8, 2024, 5 a.m. UTC | #4
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  6 Mar 2024 10:24:26 +0000 you wrote:
> After commit b5a899154aa9 ("netlink: handle EMSGSIZE errors
> in the core"), we can remove some code that was not 100 % correct
> anyway.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
>  net/core/rtnetlink.c    | 5 +----
>  net/ipv4/devinet.c      | 4 ----
>  net/ipv4/fib_frontend.c | 7 +------
>  net/ipv6/addrconf.c     | 7 +------
>  4 files changed, 3 insertions(+), 20 deletions(-)

Here is the summary with links:
  - [net-next] netlink: let core handle error cases in dump operations
    https://git.kernel.org/netdev/net-next/c/02e24903e5a4

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 780b330f8ef9fa4881b9d51570d1a65f5171ee5d..7eac6765df098fd685937ace63dfb5add9c77731 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2267,11 +2267,8 @@  static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
 				       nlh->nlmsg_seq, 0, flags,
 				       ext_filter_mask, 0, NULL, 0,
 				       netnsid, GFP_KERNEL);
-		if (err < 0) {
-			if (likely(skb->len))
-				err = skb->len;
+		if (err < 0)
 			break;
-		}
 	}
 	cb->seq = tgt_net->dev_base_seq;
 	nl_dump_check_consistent(cb, nlmsg_hdr(skb));
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 4daa8124f247c256c4f8c1ff29ac621570af0755..7a437f0d41905e6acfdc35743afba3a7abfd0dd5 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1900,8 +1900,6 @@  static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
 			goto done;
 	}
 done:
-	if (err < 0 && likely(skb->len))
-		err = skb->len;
 	if (fillargs.netnsid >= 0)
 		put_net(tgt_net);
 	rcu_read_unlock();
@@ -2312,8 +2310,6 @@  static int inet_netconf_dump_devconf(struct sk_buff *skb,
 		ctx->all_default++;
 	}
 done:
-	if (err < 0 && likely(skb->len))
-		err = skb->len;
 	rcu_read_unlock();
 	return err;
 }
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index bf3a2214fe29b6f9b494581b293259e6c5ce6f8c..48741352a88a72e0232977cc9f2cf172f45df89b 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -1026,8 +1026,6 @@  static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
 			goto unlock;
 		}
 		err = fib_table_dump(tb, skb, cb, &filter);
-		if (err < 0 && skb->len)
-			err = skb->len;
 		goto unlock;
 	}
 
@@ -1045,11 +1043,8 @@  static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
 				memset(&cb->args[2], 0, sizeof(cb->args) -
 						 2 * sizeof(cb->args[0]));
 			err = fib_table_dump(tb, skb, cb, &filter);
-			if (err < 0) {
-				if (likely(skb->len))
-					err = skb->len;
+			if (err < 0)
 				goto out;
-			}
 			dumped = 1;
 next:
 			e++;
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 2f84e6ecf19f48602cadb47bc378c9b5a1cdbf65..f786b65d12e43c53ed36535880f6e6d35879a44e 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -793,8 +793,6 @@  static int inet6_netconf_dump_devconf(struct sk_buff *skb,
 		ctx->all_default++;
 	}
 done:
-	if (err < 0 && likely(skb->len))
-		err = skb->len;
 	rcu_read_unlock();
 	return err;
 }
@@ -6158,11 +6156,8 @@  static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
 					NETLINK_CB(cb->skb).portid,
 					cb->nlh->nlmsg_seq,
 					RTM_NEWLINK, NLM_F_MULTI);
-		if (err < 0) {
-			if (likely(skb->len))
-				err = skb->len;
+		if (err < 0)
 			break;
-		}
 	}
 	rcu_read_unlock();