diff mbox series

[net] netdev-genl: Set extack and fix error on napi-get

Message ID 20240831121707.17562-1-jdamato@fastly.com (mailing list archive)
State Accepted
Commit 4e3a024b437ec0aee82550cc66a0f4e1a7a88a67
Delegated to: Netdev Maintainers
Headers show
Series [net] netdev-genl: Set extack and fix error on napi-get | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
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 Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 15 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-08-31--15-00 (tests: 714)

Commit Message

Joe Damato Aug. 31, 2024, 12:17 p.m. UTC
In commit 27f91aaf49b3 ("netdev-genl: Add netlink framework functions
for napi"), when an invalid NAPI ID is specified the return value
-EINVAL is used and no extack is set.

Change the return value to -ENOENT and set the extack.

Before this commit:

$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
                          --do napi-get --json='{"id": 451}'
Netlink error: Invalid argument
nl_len = 36 (20) nl_flags = 0x100 nl_type = 2
	error: -22

After this commit:

$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
                         --do napi-get --json='{"id": 451}'
Netlink error: No such file or directory
nl_len = 44 (28) nl_flags = 0x300 nl_type = 2
	error: -2
	extack: {'bad-attr': '.id'}

Cc: Amritha Nambiar <amritha.nambiar@intel.com>
Cc: stable@kernel.org
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Fixes: 27f91aaf49b3 ("netdev-genl: Add netlink framework functions for napi")
Signed-off-by: Joe Damato <jdamato@fastly.com>
---
 net/core/netdev-genl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Joe Damato Sept. 2, 2024, 6:52 p.m. UTC | #1
On Sat, Aug 31, 2024 at 12:17:04PM +0000, Joe Damato wrote:
> In commit 27f91aaf49b3 ("netdev-genl: Add netlink framework functions
> for napi"), when an invalid NAPI ID is specified the return value
> -EINVAL is used and no extack is set.
> 
> Change the return value to -ENOENT and set the extack.
> 
> Before this commit:
> 
> $ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
>                           --do napi-get --json='{"id": 451}'
> Netlink error: Invalid argument
> nl_len = 36 (20) nl_flags = 0x100 nl_type = 2
> 	error: -22
> 
> After this commit:
> 
> $ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
>                          --do napi-get --json='{"id": 451}'
> Netlink error: No such file or directory
> nl_len = 44 (28) nl_flags = 0x300 nl_type = 2
> 	error: -2
> 	extack: {'bad-attr': '.id'}
> 
> Cc: Amritha Nambiar <amritha.nambiar@intel.com>
> Cc: stable@kernel.org
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> Fixes: 27f91aaf49b3 ("netdev-genl: Add netlink framework functions for napi")
> Signed-off-by: Joe Damato <jdamato@fastly.com>
> ---
>  net/core/netdev-genl.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
> index 05f9515d2c05..a17d7eaeb001 100644
> --- a/net/core/netdev-genl.c
> +++ b/net/core/netdev-genl.c
> @@ -216,10 +216,12 @@ int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info)
>  	rtnl_lock();
>  
>  	napi = napi_by_id(napi_id);
> -	if (napi)
> +	if (napi) {
>  		err = netdev_nl_napi_fill_one(rsp, napi, info);
> -	else
> -		err = -EINVAL;
> +	} else {
> +		NL_SET_BAD_ATTR(info->extack, info->attrs[NETDEV_A_NAPI_ID]);
> +		err = -ENOENT;
> +	}
>  
>  	rtnl_unlock();
>  
> -- 
> 2.25.1

Based on Eric's comment regarding my other patch [1], I should
probably re-submit this against net-next instead of net.

It's been over 48 hours, but I'll wait a bit longer before
resubmitting.

[1]: https://lore.kernel.org/all/CANn89iLhrKyFKf9DpJSSM9CZ9sgoRo7jovg2GhjsJABoqzzVsQ@mail.gmail.com/
Jakub Kicinski Sept. 3, 2024, 1:28 a.m. UTC | #2
On Mon, 2 Sep 2024 20:52:15 +0200 Joe Damato wrote:
> Based on Eric's comment regarding my other patch [1], I should
> probably re-submit this against net-next instead of net.
> 
> It's been over 48 hours, but I'll wait a bit longer before
> resubmitting.

Change is simple enough, I'll strip the tags and apply to net-next.
Thanks!
patchwork-bot+netdevbpf@kernel.org Sept. 3, 2024, 1:40 a.m. UTC | #3
Hello:

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

On Sat, 31 Aug 2024 12:17:04 +0000 you wrote:
> In commit 27f91aaf49b3 ("netdev-genl: Add netlink framework functions
> for napi"), when an invalid NAPI ID is specified the return value
> -EINVAL is used and no extack is set.
> 
> Change the return value to -ENOENT and set the extack.
> 
> Before this commit:
> 
> [...]

Here is the summary with links:
  - [net] netdev-genl: Set extack and fix error on napi-get
    https://git.kernel.org/netdev/net-next/c/4e3a024b437e

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index 05f9515d2c05..a17d7eaeb001 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -216,10 +216,12 @@  int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info)
 	rtnl_lock();
 
 	napi = napi_by_id(napi_id);
-	if (napi)
+	if (napi) {
 		err = netdev_nl_napi_fill_one(rsp, napi, info);
-	else
-		err = -EINVAL;
+	} else {
+		NL_SET_BAD_ATTR(info->extack, info->attrs[NETDEV_A_NAPI_ID]);
+		err = -ENOENT;
+	}
 
 	rtnl_unlock();