diff mbox series

[5/5,RFC] devlink: Fix uninitialized error code in devlink_fmsg_prepare_skb()

Message ID 20190528142424.19626-6-geert@linux-m68k.org (mailing list archive)
State New, archived
Headers show
Series Assorted fixes discovered with gcc 4.1 | expand

Commit Message

Geert Uytterhoeven May 28, 2019, 2:24 p.m. UTC
With gcc 4.1:

    net/core/devlink.c: In function ‘devlink_fmsg_prepare_skb’:
    net/core/devlink.c:4325: warning: ‘err’ may be used uninitialized in this function

Indeed, if the list has less than *start entries, an uninitialized error
code will be returned.

Fix this by preinitializing err to zero.

Fixes: 1db64e8733f65381 ("devlink: Add devlink formatted message (fmsg) API")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
I don't know if this can really happen, and if this is the right fix.
Perhaps err should be initialized to some valid error code instead?
---
 net/core/devlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Eran Ben Elisha May 28, 2019, 2:40 p.m. UTC | #1
On 5/28/2019 5:24 PM, Geert Uytterhoeven wrote:
> With gcc 4.1:
> 
>      net/core/devlink.c: In function ‘devlink_fmsg_prepare_skb’:
>      net/core/devlink.c:4325: warning: ‘err’ may be used uninitialized in this function
> 
> Indeed, if the list has less than *start entries, an uninitialized error
> code will be returned.

The logic guarantees that start is smaller than the length of the list.
but I guess that the compiler can't detect that.

Reviewed-by: Eran Ben Elisha <eranbe@mellanox.com>

> 
> Fix this by preinitializing err to zero.
> 
> Fixes: 1db64e8733f65381 ("devlink: Add devlink formatted message (fmsg) API")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> I don't know if this can really happen, and if this is the right fix.
> Perhaps err should be initialized to some valid error code instead?
> ---
>   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 d43bc52b8840d76b..91377e4eae9a43c1 100644
> --- a/net/core/devlink.c
> +++ b/net/core/devlink.c
> @@ -4321,8 +4321,8 @@ devlink_fmsg_prepare_skb(struct devlink_fmsg *fmsg, struct sk_buff *skb,
>   {
>   	struct devlink_fmsg_item *item;
>   	struct nlattr *fmsg_nlattr;
> +	int err = 0;
>   	int i = 0;
> -	int err;
>   
>   	fmsg_nlattr = nla_nest_start_noflag(skb, DEVLINK_ATTR_FMSG);
>   	if (!fmsg_nlattr)
>
Jiri Pirko May 29, 2019, 8:04 a.m. UTC | #2
Tue, May 28, 2019 at 04:24:24PM CEST, geert@linux-m68k.org wrote:
>With gcc 4.1:
>
>    net/core/devlink.c: In function ‘devlink_fmsg_prepare_skb’:
>    net/core/devlink.c:4325: warning: ‘err’ may be used uninitialized in this function
>
>Indeed, if the list has less than *start entries, an uninitialized error
>code will be returned.
>
>Fix this by preinitializing err to zero.
>
>Fixes: 1db64e8733f65381 ("devlink: Add devlink formatted message (fmsg) API")
>Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
>---
>I don't know if this can really happen, and if this is the right fix.
>Perhaps err should be initialized to some valid error code instead?

0 is correct here.
Acked-by: Jiri Pirko <jiri@mellanox.com>

Thanks!

>---
> 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 d43bc52b8840d76b..91377e4eae9a43c1 100644
>--- a/net/core/devlink.c
>+++ b/net/core/devlink.c
>@@ -4321,8 +4321,8 @@ devlink_fmsg_prepare_skb(struct devlink_fmsg *fmsg, struct sk_buff *skb,
> {
> 	struct devlink_fmsg_item *item;
> 	struct nlattr *fmsg_nlattr;
>+	int err = 0;
> 	int i = 0;
>-	int err;
> 
> 	fmsg_nlattr = nla_nest_start_noflag(skb, DEVLINK_ATTR_FMSG);
> 	if (!fmsg_nlattr)
>-- 
>2.17.1
>
diff mbox series

Patch

diff --git a/net/core/devlink.c b/net/core/devlink.c
index d43bc52b8840d76b..91377e4eae9a43c1 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -4321,8 +4321,8 @@  devlink_fmsg_prepare_skb(struct devlink_fmsg *fmsg, struct sk_buff *skb,
 {
 	struct devlink_fmsg_item *item;
 	struct nlattr *fmsg_nlattr;
+	int err = 0;
 	int i = 0;
-	int err;
 
 	fmsg_nlattr = nla_nest_start_noflag(skb, DEVLINK_ATTR_FMSG);
 	if (!fmsg_nlattr)