diff mbox series

[net-next] devlink: fix return of uninitialized variable err

Message ID 1610112073-23424-1-git-send-email-wangyunjian@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] devlink: fix return of uninitialized variable err | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 3 maintainers not CCed: eranbe@mellanox.com jiri@nvidia.com moshe@mellanox.com
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: 1 this patch: 1
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, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

wangyunjian Jan. 8, 2021, 1:21 p.m. UTC
From: Yunjian Wang <wangyunjian@huawei.com>

There is a potential execution path in which variable err is
returned without being properly initialized previously. Fix
this by initializing variable err to 0.

Addresses-Coverity: ("Uninitialized scalar variable")
Fixes: 1db64e8733f6 ("devlink: Add devlink formatted message (fmsg) API")
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 net/core/devlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jakub Kicinski Jan. 10, 2021, 12:41 a.m. UTC | #1
On Fri, 8 Jan 2021 21:21:13 +0800 wangyunjian wrote:
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> There is a potential execution path in which variable err is
> returned without being properly initialized previously. Fix
> this by initializing variable err to 0.
> 
> Addresses-Coverity: ("Uninitialized scalar variable")
> Fixes: 1db64e8733f6 ("devlink: Add devlink formatted message (fmsg) API")
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>

Fixes should generally be targeting net, not net-next.

I don't think this can trigger. 

Only devlink_nl_cmd_health_reporter_diagnose_doit() can call here, and
before it does it calls devlink_fmsg_obj_nest_start() and end(), so
there will at least be DEVLINK_ATTR_FMSG_OBJ_NEST_START to iterate over.

Please double check this analysis, and resend the patch with the commit
message updated to reflect this is not a bug fix and without the fixes
tag.

> diff --git a/net/core/devlink.c b/net/core/devlink.c
> index ee828e4b1007..470215cd60b5 100644
> --- a/net/core/devlink.c
> +++ b/net/core/devlink.c
> @@ -5699,7 +5699,7 @@ devlink_fmsg_prepare_skb(struct devlink_fmsg *fmsg, struct sk_buff *skb,
>  	struct devlink_fmsg_item *item;
>  	struct nlattr *fmsg_nlattr;
>  	int i = 0;
> -	int err;
> +	int err = 0;

Please order variable declaration lines longest to shortest.
err should be before i.

>  	fmsg_nlattr = nla_nest_start_noflag(skb, DEVLINK_ATTR_FMSG);
>  	if (!fmsg_nlattr)
diff mbox series

Patch

diff --git a/net/core/devlink.c b/net/core/devlink.c
index ee828e4b1007..470215cd60b5 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -5699,7 +5699,7 @@  devlink_fmsg_prepare_skb(struct devlink_fmsg *fmsg, struct sk_buff *skb,
 	struct devlink_fmsg_item *item;
 	struct nlattr *fmsg_nlattr;
 	int i = 0;
-	int err;
+	int err = 0;
 
 	fmsg_nlattr = nla_nest_start_noflag(skb, DEVLINK_ATTR_FMSG);
 	if (!fmsg_nlattr)