diff mbox series

[net] nexthop: fix uninitialized variable in nla_put_nh_group_stats()

Message ID b2578acd-9838-45b6-a50d-96a86171b20e@moroto.mountain (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] nexthop: fix uninitialized variable in nla_put_nh_group_stats() | 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: 942 this patch: 942
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 957 this patch: 957
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: 959 this patch: 959
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 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-03-20--03-00 (tests: 908)

Commit Message

Dan Carpenter March 16, 2024, 9:46 a.m. UTC
The nh_grp_hw_stats_update() function doesn't always set "hw_stats_used"
so it could be used without being initialized.  Set it to false.

Fixes: 5072ae00aea4 ("net: nexthop: Expose nexthop group HW stats to user space")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 net/ipv4/nexthop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Ahern March 16, 2024, 4:29 p.m. UTC | #1
On 3/16/24 3:46 AM, Dan Carpenter wrote:
> The nh_grp_hw_stats_update() function doesn't always set "hw_stats_used"
> so it could be used without being initialized.  Set it to false.
> 
> Fixes: 5072ae00aea4 ("net: nexthop: Expose nexthop group HW stats to user space")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  net/ipv4/nexthop.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
> index 74928a9d1aa4..c25bfdf4e25f 100644
> --- a/net/ipv4/nexthop.c
> +++ b/net/ipv4/nexthop.c
> @@ -824,8 +824,8 @@ static int nla_put_nh_group_stats(struct sk_buff *skb, struct nexthop *nh,
>  				  u32 op_flags)
>  {
>  	struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
> +	bool hw_stats_used = false;
>  	struct nlattr *nest;
> -	bool hw_stats_used;
>  	int err;
>  	int i;
>  

Reviewed-by: David Ahern <dsahern@kernel.org>

The flag could be moved under
	`if (op_flags & NHA_OP_FLAG_DUMP_HW_STATS ...`
as well.
Ido Schimmel March 17, 2024, 7:56 a.m. UTC | #2
On Sat, Mar 16, 2024 at 12:46:03PM +0300, Dan Carpenter wrote:
> The nh_grp_hw_stats_update() function doesn't always set "hw_stats_used"
> so it could be used without being initialized.  Set it to false.
> 
> Fixes: 5072ae00aea4 ("net: nexthop: Expose nexthop group HW stats to user space")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Jiri Pirko March 18, 2024, 8:02 a.m. UTC | #3
Sat, Mar 16, 2024 at 10:46:03AM CET, dan.carpenter@linaro.org wrote:
>The nh_grp_hw_stats_update() function doesn't always set "hw_stats_used"
>so it could be used without being initialized.  Set it to false.
>
>Fixes: 5072ae00aea4 ("net: nexthop: Expose nexthop group HW stats to user space")
>Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
>---
> net/ipv4/nexthop.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
>index 74928a9d1aa4..c25bfdf4e25f 100644
>--- a/net/ipv4/nexthop.c
>+++ b/net/ipv4/nexthop.c
>@@ -824,8 +824,8 @@ static int nla_put_nh_group_stats(struct sk_buff *skb, struct nexthop *nh,
> 				  u32 op_flags)
> {
> 	struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
>+	bool hw_stats_used = false;
> 	struct nlattr *nest;
>-	bool hw_stats_used;


Probably better to set this in one place and have:
       if (nexthop_notifiers_is_empty(net)) {
	       *hw_stats_used = false;
               return 0;
       }
in nh_grp_hw_stats_update().




> 	int err;
> 	int i;
> 
>-- 
>2.43.0
>
>
Dan Carpenter March 18, 2024, 8:11 a.m. UTC | #4
On Mon, Mar 18, 2024 at 09:02:54AM +0100, Jiri Pirko wrote:
> Sat, Mar 16, 2024 at 10:46:03AM CET, dan.carpenter@linaro.org wrote:
> >The nh_grp_hw_stats_update() function doesn't always set "hw_stats_used"
> >so it could be used without being initialized.  Set it to false.
> >
> >Fixes: 5072ae00aea4 ("net: nexthop: Expose nexthop group HW stats to user space")
> >Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> >---
> > net/ipv4/nexthop.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
> >index 74928a9d1aa4..c25bfdf4e25f 100644
> >--- a/net/ipv4/nexthop.c
> >+++ b/net/ipv4/nexthop.c
> >@@ -824,8 +824,8 @@ static int nla_put_nh_group_stats(struct sk_buff *skb, struct nexthop *nh,
> > 				  u32 op_flags)
> > {
> > 	struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
> >+	bool hw_stats_used = false;
> > 	struct nlattr *nest;
> >-	bool hw_stats_used;
> 
> 
> Probably better to set this in one place and have:
>        if (nexthop_notifiers_is_empty(net)) {
> 	       *hw_stats_used = false;
>                return 0;
>        }
> in nh_grp_hw_stats_update().
> 

Sure.  Will do.

regards,
dan carpenter
diff mbox series

Patch

diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 74928a9d1aa4..c25bfdf4e25f 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -824,8 +824,8 @@  static int nla_put_nh_group_stats(struct sk_buff *skb, struct nexthop *nh,
 				  u32 op_flags)
 {
 	struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
+	bool hw_stats_used = false;
 	struct nlattr *nest;
-	bool hw_stats_used;
 	int err;
 	int i;