* [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop
@ 2023-04-14 18:07 Jakub Kicinski
2023-04-15 4:20 ` kernel test robot
2023-04-16 10:17 ` Leon Romanovsky
0 siblings, 2 replies; 7+ messages in thread
From: Jakub Kicinski @ 2023-04-14 18:07 UTC (permalink / raw)
To: davem; +Cc: netdev, edumazet, pabeni, Jakub Kicinski, saeedm, leon
Fix the following warning about risky iterator use:
drivers/net/ethernet/mellanox/mlx5/core/eq.c:1010 mlx5_comp_irq_get_affinity_mask() warn: iterator used outside loop: 'eq'
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: saeedm@nvidia.com
CC: leon@kernel.org
---
drivers/net/ethernet/mellanox/mlx5/core/eq.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
index eb41f0abf798..03c0165a8fd5 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
@@ -1070,10 +1070,11 @@ mlx5_comp_irq_get_affinity_mask(struct mlx5_core_dev *dev, int vector)
list_for_each_entry(eq, &table->comp_eqs_list, list) {
if (i++ == vector)
- break;
+ return mlx5_irq_get_affinity_mask(eq->core.irq);
}
- return mlx5_irq_get_affinity_mask(eq->core.irq);
+ WARN_ON_ONCE(1);
+ return 0;
}
EXPORT_SYMBOL(mlx5_comp_irq_get_affinity_mask);
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop
2023-04-14 18:07 [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop Jakub Kicinski
@ 2023-04-15 4:20 ` kernel test robot
2023-04-16 10:17 ` Leon Romanovsky
1 sibling, 0 replies; 7+ messages in thread
From: kernel test robot @ 2023-04-15 4:20 UTC (permalink / raw)
To: Jakub Kicinski, davem
Cc: oe-kbuild-all, netdev, edumazet, pabeni, Jakub Kicinski, saeedm,
leon
Hi Jakub,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Jakub-Kicinski/eth-mlx5-avoid-iterator-use-outside-of-a-loop/20230415-021112
patch link: https://lore.kernel.org/r/20230414180729.198284-1-kuba%40kernel.org
patch subject: [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop
config: arm64-randconfig-s052-20230413 (https://download.01.org/0day-ci/archive/20230415/202304151226.OgvGHiJI-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 12.1.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://github.com/intel-lab-lkp/linux/commit/1432c0a2b6d7ea977dad5de303481b1aae454ef4
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jakub-Kicinski/eth-mlx5-avoid-iterator-use-outside-of-a-loop/20230415-021112
git checkout 1432c0a2b6d7ea977dad5de303481b1aae454ef4
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arm64 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/net/ethernet/mellanox/mlx5/core/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304151226.OgvGHiJI-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
>> drivers/net/ethernet/mellanox/mlx5/core/eq.c:1077:16: sparse: sparse: Using plain integer as NULL pointer
vim +1077 drivers/net/ethernet/mellanox/mlx5/core/eq.c
1063
1064 struct cpumask *
1065 mlx5_comp_irq_get_affinity_mask(struct mlx5_core_dev *dev, int vector)
1066 {
1067 struct mlx5_eq_table *table = dev->priv.eq_table;
1068 struct mlx5_eq_comp *eq;
1069 int i = 0;
1070
1071 list_for_each_entry(eq, &table->comp_eqs_list, list) {
1072 if (i++ == vector)
1073 return mlx5_irq_get_affinity_mask(eq->core.irq);
1074 }
1075
1076 WARN_ON_ONCE(1);
> 1077 return 0;
1078 }
1079 EXPORT_SYMBOL(mlx5_comp_irq_get_affinity_mask);
1080
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop
2023-04-14 18:07 [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop Jakub Kicinski
2023-04-15 4:20 ` kernel test robot
@ 2023-04-16 10:17 ` Leon Romanovsky
2023-04-17 19:44 ` Jakub Kicinski
1 sibling, 1 reply; 7+ messages in thread
From: Leon Romanovsky @ 2023-04-16 10:17 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, saeedm
On Fri, Apr 14, 2023 at 11:07:29AM -0700, Jakub Kicinski wrote:
> Fix the following warning about risky iterator use:
>
> drivers/net/ethernet/mellanox/mlx5/core/eq.c:1010 mlx5_comp_irq_get_affinity_mask() warn: iterator used outside loop: 'eq'
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> CC: saeedm@nvidia.com
> CC: leon@kernel.org
> ---
> drivers/net/ethernet/mellanox/mlx5/core/eq.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
> index eb41f0abf798..03c0165a8fd5 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
> @@ -1070,10 +1070,11 @@ mlx5_comp_irq_get_affinity_mask(struct mlx5_core_dev *dev, int vector)
>
> list_for_each_entry(eq, &table->comp_eqs_list, list) {
> if (i++ == vector)
> - break;
> + return mlx5_irq_get_affinity_mask(eq->core.irq);
> }
>
> - return mlx5_irq_get_affinity_mask(eq->core.irq);
> + WARN_ON_ONCE(1);
> + return 0;
I would do it without changing last return, but "return ERR_PTR(0);"
will do the trick too.
Thanks
> }
> EXPORT_SYMBOL(mlx5_comp_irq_get_affinity_mask);
>
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop
2023-04-16 10:17 ` Leon Romanovsky
@ 2023-04-17 19:44 ` Jakub Kicinski
0 siblings, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2023-04-17 19:44 UTC (permalink / raw)
To: Leon Romanovsky; +Cc: davem, netdev, edumazet, pabeni, saeedm
On Sun, 16 Apr 2023 13:17:53 +0300 Leon Romanovsky wrote:
> > - return mlx5_irq_get_affinity_mask(eq->core.irq);
> > + WARN_ON_ONCE(1);
> > + return 0;
>
> I would do it without changing last return, but "return ERR_PTR(0);"
> will do the trick too.
Hm, I've not seen ERR_PTR(0) used before. I'll return NULL.
Looks like callers pass the value to cpumask_first() without checking
so either way the warning will be followed by a crash 🤷️
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop
@ 2023-04-20 1:58 Jakub Kicinski
2023-04-20 4:03 ` Saeed Mahameed
2023-04-21 2:50 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 7+ messages in thread
From: Jakub Kicinski @ 2023-04-20 1:58 UTC (permalink / raw)
To: davem; +Cc: netdev, edumazet, pabeni, Jakub Kicinski, saeedm, leon
Fix the following warning about risky iterator use:
drivers/net/ethernet/mellanox/mlx5/core/eq.c:1010 mlx5_comp_irq_get_affinity_mask() warn: iterator used outside loop: 'eq'
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2:
- return NULL rather than 0
v1: https://lore.kernel.org/all/20230416101753.GB15386@unreal/
CC: saeedm@nvidia.com
CC: leon@kernel.org
---
drivers/net/ethernet/mellanox/mlx5/core/eq.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
index eb41f0abf798..1c35d721a31d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
@@ -1070,10 +1070,11 @@ mlx5_comp_irq_get_affinity_mask(struct mlx5_core_dev *dev, int vector)
list_for_each_entry(eq, &table->comp_eqs_list, list) {
if (i++ == vector)
- break;
+ return mlx5_irq_get_affinity_mask(eq->core.irq);
}
- return mlx5_irq_get_affinity_mask(eq->core.irq);
+ WARN_ON_ONCE(1);
+ return NULL;
}
EXPORT_SYMBOL(mlx5_comp_irq_get_affinity_mask);
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop
2023-04-20 1:58 Jakub Kicinski
@ 2023-04-20 4:03 ` Saeed Mahameed
2023-04-21 2:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 7+ messages in thread
From: Saeed Mahameed @ 2023-04-20 4:03 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, saeedm, leon
On 19 Apr 18:58, Jakub Kicinski wrote:
>Fix the following warning about risky iterator use:
>
>drivers/net/ethernet/mellanox/mlx5/core/eq.c:1010 mlx5_comp_irq_get_affinity_mask() warn: iterator used outside loop: 'eq'
>
Acked-by: Saeed Mahameed <saeed@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop
2023-04-20 1:58 Jakub Kicinski
2023-04-20 4:03 ` Saeed Mahameed
@ 2023-04-21 2:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-04-21 2:50 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, saeedm, leon
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 19 Apr 2023 18:58:02 -0700 you wrote:
> Fix the following warning about risky iterator use:
>
> drivers/net/ethernet/mellanox/mlx5/core/eq.c:1010 mlx5_comp_irq_get_affinity_mask() warn: iterator used outside loop: 'eq'
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> v2:
> - return NULL rather than 0
> v1: https://lore.kernel.org/all/20230416101753.GB15386@unreal/
>
> [...]
Here is the summary with links:
- [net-next] eth: mlx5: avoid iterator use outside of a loop
https://git.kernel.org/netdev/net-next/c/61718206ee5d
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-04-21 2:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-14 18:07 [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop Jakub Kicinski
2023-04-15 4:20 ` kernel test robot
2023-04-16 10:17 ` Leon Romanovsky
2023-04-17 19:44 ` Jakub Kicinski
-- strict thread matches above, loose matches on Subject: below --
2023-04-20 1:58 Jakub Kicinski
2023-04-20 4:03 ` Saeed Mahameed
2023-04-21 2:50 ` patchwork-bot+netdevbpf
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).