diff mbox series

[iproute2] rdma: stat: initialize ret in stat_qp_show_parse_cb()

Message ID 2b6d2d8c4fdcf53baea43c9fbe9f929d99257809.1618350667.git.aclaudi@redhat.com (mailing list archive)
State Accepted
Delegated to: Stephen Hemminger
Headers show
Series [iproute2] rdma: stat: initialize ret in stat_qp_show_parse_cb() | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Andrea Claudi April 13, 2021, 10:50 p.m. UTC
In the unlikely case in which the mnl_attr_for_each_nested() cycle is
not executed, this function return an uninitialized value.

Fix this initializing ret to 0.

Fixes: 5937552b42e4 ("rdma: Add "stat qp show" support")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
---
 rdma/stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Leon Romanovsky April 18, 2021, 11:07 a.m. UTC | #1
On Wed, Apr 14, 2021 at 12:50:57AM +0200, Andrea Claudi wrote:
> In the unlikely case in which the mnl_attr_for_each_nested() cycle is
> not executed, this function return an uninitialized value.
> 
> Fix this initializing ret to 0.
> 
> Fixes: 5937552b42e4 ("rdma: Add "stat qp show" support")
> Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
> ---
>  rdma/stat.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/rdma/stat.c b/rdma/stat.c
> index 75d45288..3abedae7 100644
> --- a/rdma/stat.c
> +++ b/rdma/stat.c
> @@ -307,7 +307,7 @@ static int stat_qp_show_parse_cb(const struct nlmsghdr *nlh, void *data)
>  	struct rd *rd = data;
>  	const char *name;
>  	uint32_t idx;
> -	int ret;
> +	int ret = 0;

It should be MNL_CB_OK which is 1 and not 0.

Thanks.

>  
>  	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
>  	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
> -- 
> 2.30.2
>
Andrea Claudi April 18, 2021, noon UTC | #2
On Sun, Apr 18, 2021 at 1:07 PM Leon Romanovsky <leon@kernel.org> wrote:
>
> On Wed, Apr 14, 2021 at 12:50:57AM +0200, Andrea Claudi wrote:
> > In the unlikely case in which the mnl_attr_for_each_nested() cycle is
> > not executed, this function return an uninitialized value.
> >
> > Fix this initializing ret to 0.
> >
> > Fixes: 5937552b42e4 ("rdma: Add "stat qp show" support")
> > Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
> > ---
> >  rdma/stat.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/rdma/stat.c b/rdma/stat.c
> > index 75d45288..3abedae7 100644
> > --- a/rdma/stat.c
> > +++ b/rdma/stat.c
> > @@ -307,7 +307,7 @@ static int stat_qp_show_parse_cb(const struct nlmsghdr *nlh, void *data)
> >       struct rd *rd = data;
> >       const char *name;
> >       uint32_t idx;
> > -     int ret;
> > +     int ret = 0;
>
> It should be MNL_CB_OK which is 1 and not 0.
>
> Thanks.
>

Hi Leon, and thanks for pointing this out.
As this is already merged, I'll submit a fix.

Regards,
Andrea

> >
> >       mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
> >       if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
> > --
> > 2.30.2
> >
>
Leon Romanovsky April 18, 2021, 12:06 p.m. UTC | #3
On Sun, Apr 18, 2021 at 02:00:38PM +0200, Andrea Claudi wrote:
> On Sun, Apr 18, 2021 at 1:07 PM Leon Romanovsky <leon@kernel.org> wrote:
> >
> > On Wed, Apr 14, 2021 at 12:50:57AM +0200, Andrea Claudi wrote:
> > > In the unlikely case in which the mnl_attr_for_each_nested() cycle is
> > > not executed, this function return an uninitialized value.
> > >
> > > Fix this initializing ret to 0.
> > >
> > > Fixes: 5937552b42e4 ("rdma: Add "stat qp show" support")
> > > Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
> > > ---
> > >  rdma/stat.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/rdma/stat.c b/rdma/stat.c
> > > index 75d45288..3abedae7 100644
> > > --- a/rdma/stat.c
> > > +++ b/rdma/stat.c
> > > @@ -307,7 +307,7 @@ static int stat_qp_show_parse_cb(const struct nlmsghdr *nlh, void *data)
> > >       struct rd *rd = data;
> > >       const char *name;
> > >       uint32_t idx;
> > > -     int ret;
> > > +     int ret = 0;
> >
> > It should be MNL_CB_OK which is 1 and not 0.
> >
> > Thanks.
> >
> 
> Hi Leon, and thanks for pointing this out.
> As this is already merged, I'll submit a fix.

Thanks

> 
> Regards,
> Andrea
> 
> > >
> > >       mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
> > >       if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
> > > --
> > > 2.30.2
> > >
> >
>
diff mbox series

Patch

diff --git a/rdma/stat.c b/rdma/stat.c
index 75d45288..3abedae7 100644
--- a/rdma/stat.c
+++ b/rdma/stat.c
@@ -307,7 +307,7 @@  static int stat_qp_show_parse_cb(const struct nlmsghdr *nlh, void *data)
 	struct rd *rd = data;
 	const char *name;
 	uint32_t idx;
-	int ret;
+	int ret = 0;
 
 	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
 	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||