netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] devlink: fix return of uninitialized variable err
@ 2021-01-08 13:21 wangyunjian
  2021-01-10  0:41 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: wangyunjian @ 2021-01-08 13:21 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, jerry.lilijun, xudingke, Yunjian Wang

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(-)

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)
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] devlink: fix return of uninitialized variable err
  2021-01-08 13:21 [PATCH net-next] devlink: fix return of uninitialized variable err wangyunjian
@ 2021-01-10  0:41 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2021-01-10  0:41 UTC (permalink / raw)
  To: wangyunjian; +Cc: netdev, davem, jerry.lilijun, xudingke

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)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-10  0:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-08 13:21 [PATCH net-next] devlink: fix return of uninitialized variable err wangyunjian
2021-01-10  0:41 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).