Netdev List
 help / color / mirror / Atom feed
* [PATCH] net/mlx4: fix error propagation in mlx4_load_one()
@ 2026-11-25  2:29 mdshahid03
  2026-11-25  2:33 ` netdev-bot+sinfo
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: mdshahid03 @ 2026-11-25  2:29 UTC (permalink / raw)
  To: tariqt
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, netdev, linux-rdma,
	Mohammad Shahid

From: Mohammad Shahid <mdshahid03@gmail.com>

The return value of mlx4_check_dev_cap() is not assigned to err at
two places in mlx4_load_one().

If the helper return an error ,execution jumps to err_fw,but err may
still contain zero from the previous successful operation.

Assigning the helper's return value to err ensures that the error is
correctly propagated.

Signed-off-by: Mohammad Shahid <mdshahid03@gmail.com>
---
 drivers/net/ethernet/mellanox/mlx4/main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 036135df23bf..9d89721077c9 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -3505,7 +3505,8 @@ static int mlx4_load_one(struct pci_dev *pdev, int pci_dev_data,
 				goto err_fw;
 			}
 
-			if (mlx4_check_dev_cap(dev, dev_cap, nvfs))
+			err = mlx4_check_dev_cap(dev, dev_cap, nvfs);
+			if (err)
 				goto err_fw;
 
 			if (!(dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS)) {
@@ -3540,7 +3541,8 @@ static int mlx4_load_one(struct pci_dev *pdev, int pci_dev_data,
 				goto err_fw;
 			}
 
-			if (mlx4_check_dev_cap(dev, dev_cap, nvfs))
+			err = mlx4_check_dev_cap(dev, dev_cap, nvfs);
+			if (err)
 				goto err_fw;
 		}
 	}
-- 
2.43.0


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

* Re: [PATCH] net/mlx4: fix error propagation in mlx4_load_one()
  2026-11-25  2:29 [PATCH] net/mlx4: fix error propagation in mlx4_load_one() mdshahid03
@ 2026-11-25  2:33 ` netdev-bot+sinfo
  2026-11-25 18:12 ` Joe Damato
  2026-11-29  2:38 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sinfo @ 2026-11-25  2:33 UTC (permalink / raw)
  To: mdshahid03
  Cc: tariqt, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	linux-rdma

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

 - What hardware the change was tested on. For driver fixes please
   mention the device (and if relevant firmware version) used for
   testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

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

* Re: [PATCH] net/mlx4: fix error propagation in mlx4_load_one()
  2026-11-25  2:29 [PATCH] net/mlx4: fix error propagation in mlx4_load_one() mdshahid03
  2026-11-25  2:33 ` netdev-bot+sinfo
@ 2026-11-25 18:12 ` Joe Damato
  2026-11-29  2:38 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: Joe Damato @ 2026-11-25 18:12 UTC (permalink / raw)
  To: mdshahid03
  Cc: tariqt, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	linux-rdma

On Wed, Nov 25, 2026 at 07:59:13AM +0530, mdshahid03@gmail.com wrote:
> From: Mohammad Shahid <mdshahid03@gmail.com>
> 
> The return value of mlx4_check_dev_cap() is not assigned to err at
> two places in mlx4_load_one().
> 
> If the helper return an error ,execution jumps to err_fw,but err may
> still contain zero from the previous successful operation.
> 
> Assigning the helper's return value to err ensures that the error is
> correctly propagated.
> 
> Signed-off-by: Mohammad Shahid <mdshahid03@gmail.com>
> ---
>  drivers/net/ethernet/mellanox/mlx4/main.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>

Looks right to me

Reviewed-by: Joe Damato <joe@dama.to>

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

* Re: [PATCH] net/mlx4: fix error propagation in mlx4_load_one()
  2026-11-25  2:29 [PATCH] net/mlx4: fix error propagation in mlx4_load_one() mdshahid03
  2026-11-25  2:33 ` netdev-bot+sinfo
  2026-11-25 18:12 ` Joe Damato
@ 2026-11-29  2:38 ` netdev-bot+sashiko
  2026-11-29  9:16   ` Tariq Toukan
  2 siblings, 1 reply; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-29  2:38 UTC (permalink / raw)
  To: mdshahid03
  Cc: tariqt, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	linux-rdma

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The fix leaves the same bug in place a few lines further down
  the same block of mlx4_load_one()…
- [Low] The commit fixes a real, user-triggerable bug, but the message
  does not describe its impact and has no Fixes: tag.
- [Low] mlx4_load_one() now passes on the raw return value of
  mlx4_check_dev_cap(), which is the private enum sentinel…

--

net/mlx4: fix error propagation in mlx4_load_one()

This patch assigns the return value of mlx4_check_dev_cap() to err at both
call sites in mlx4_load_one(). Before this, the goto err_fw paths could
return 0 left over from the previous successful command.

> If the helper return an error ,execution jumps to err_fw,but err may
> still contain zero from the previous successful operation.

[Severity: Low]
Could the commit message describe the user-visible impact, and could it
carry a Fixes: tag?

Before this patch, the failure happens when the num_vfs module parameter
requests 64 or more VFs in total on firmware without
MLX4_DEV_CAP_FLAG2_80_VFS (for example CX2). mlx4_check_dev_cap() fails
while err is still 0 from mlx4_QUERY_DEV_CAP().

mlx4_load_one() then runs the full err_fw unwind and returns 0, and
__mlx4_init_one() and mlx4_restart_one_up() treat the device as loaded.

The unchecked call appears to come from:

Fixes: de966c592802 ("net/mlx4_core: Support more than 64 VFs")

> diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
> index 036135df23bf1..9d89721077c94 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/main.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
> @@ -3505,7 +3505,8 @@ static int mlx4_load_one(struct pci_dev *pdev, int pci_dev_data,
>  				goto err_fw;
>  			}
>  
> -			if (mlx4_check_dev_cap(dev, dev_cap, nvfs))
> +			err = mlx4_check_dev_cap(dev, dev_cap, nvfs);
> +			if (err)
>  				goto err_fw;

[Severity: Low]
Which value gets propagated here? mlx4_check_dev_cap() returns a private
enum sentinel, not an errno:

enum {
	MLX4_DEV_CAP_CHECK_NUM_VFS_ABOVE_64 = -1,
};

With this change mlx4_load_one() returns -1. __mlx4_init_one() passes that
to the PCI core as the probe result, and mlx4_restart_one_up() returns it
up the devlink reload path. Both will report -EPERM ("Operation not
permitted") for what is really an invalid VF configuration. The same
applies to the second call site in the legacy-mode branch.

Other configuration errors in mlx4_load_one() use -EINVAL, such as the
"Trying to configure VFs on port 2" check.

Would it be better for mlx4_check_dev_cap() to return -EINVAL, or for the
call sites to set err = -EINVAL?

>  
>  			if (!(dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS)) {

[Severity: High]
Is the same problem still present a few lines further down in this block?
Once mlx4_check_dev_cap() succeeds, err is 0. The invalid SRIOV state
check then jumps to err_sriov without setting err:

drivers/net/ethernet/mellanox/mlx4/main.c:mlx4_load_one() {
    ...
				dev->flags = dev_flags;
				if (!SRIOV_VALID_STATE(dev->flags)) {
					mlx4_err(dev, "Invalid SRIOV state\n");
					goto err_sriov;
				}
    ...
}

This state looks reachable. mlx4_enable_sriov() starts from
dev_flags = dev->flags. If kzalloc_objs() for dev->dev_vfs fails, it
exits through:

disable_sriov:
	atomic_dec(&pf_loading);
free_mem:
	dev->persist->num_vfs = 0;
	kfree(dev->dev_vfs);
	dev->dev_vfs = NULL;
	return dev_flags & ~MLX4_FLAG_MASTER;

Suppose dev->flags already had MLX4_FLAG_SRIOV (existing_vfs != 0, or the
reset_flow path). Then this returns SRIOV set and MASTER cleared, so
SRIOV_VALID_STATE() is false.

The err_sriov unwind then tears everything down, including
mlx4_adev_cleanup(), and mlx4_load_one() returns 0. __mlx4_init_one()
takes its success path:

	err = mlx4_load_one(pdev, pci_dev_data, total_vfs, nvfs, priv, 0);
	if (err)
		goto err_catas;

	return 0;

On the reload path, mlx4_restart_one_up() would also continue into
restore_current_port_types() on the torn-down device.

priv->removed stays 0. Can a later mlx4_unload_one() then run the teardown
a second time, including a second kfree(priv->adev) and ida_free() in
mlx4_adev_cleanup()?

The matching check in the SYS_EQS path already sets err:

		if (!SRIOV_VALID_STATE(dev->flags)) {
			mlx4_err(dev, "Invalid SRIOV state\n");
			err = -EINVAL;
			goto err_close;
		}

Should the non-SYS_EQS check also set err = -EINVAL before the
goto err_sriov?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125022913.205366-1-mdshahid03%40gmail.com

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

* Re: [PATCH] net/mlx4: fix error propagation in mlx4_load_one()
  2026-11-29  2:38 ` netdev-bot+sashiko
@ 2026-11-29  9:16   ` Tariq Toukan
  0 siblings, 0 replies; 5+ messages in thread
From: Tariq Toukan @ 2026-11-29  9:16 UTC (permalink / raw)
  To: netdev-bot+sashiko, mdshahid03
  Cc: tariqt, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	linux-rdma



On 29/11/2026 4:38, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issue(s) to consider.
> 
> Critical: 0 · High: 1 · Medium: 0 · Low: 2
> 
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
> 
> - [High] The fix leaves the same bug in place a few lines further down
>    the same block of mlx4_load_one()…
> - [Low] The commit fixes a real, user-triggerable bug, but the message
>    does not describe its impact and has no Fixes: tag.
> - [Low] mlx4_load_one() now passes on the raw return value of
>    mlx4_check_dev_cap(), which is the private enum sentinel…
> 
> --
> 
> net/mlx4: fix error propagation in mlx4_load_one()
> 
> This patch assigns the return value of mlx4_check_dev_cap() to err at both
> call sites in mlx4_load_one(). Before this, the goto err_fw paths could
> return 0 left over from the previous successful command.
> 
>> If the helper return an error ,execution jumps to err_fw,but err may
>> still contain zero from the previous successful operation.
> 
> [Severity: Low]
> Could the commit message describe the user-visible impact, and could it
> carry a Fixes: tag?
> 
> Before this patch, the failure happens when the num_vfs module parameter
> requests 64 or more VFs in total on firmware without
> MLX4_DEV_CAP_FLAG2_80_VFS (for example CX2). mlx4_check_dev_cap() fails
> while err is still 0 from mlx4_QUERY_DEV_CAP().
> 
> mlx4_load_one() then runs the full err_fw unwind and returns 0, and
> __mlx4_init_one() and mlx4_restart_one_up() treat the device as loaded.
> 
> The unchecked call appears to come from:
> 
> Fixes: de966c592802 ("net/mlx4_core: Support more than 64 VFs")
> 

Please address.

>> diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
>> index 036135df23bf1..9d89721077c94 100644
>> --- a/drivers/net/ethernet/mellanox/mlx4/main.c
>> +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
>> @@ -3505,7 +3505,8 @@ static int mlx4_load_one(struct pci_dev *pdev, int pci_dev_data,
>>   				goto err_fw;
>>   			}
>>   
>> -			if (mlx4_check_dev_cap(dev, dev_cap, nvfs))
>> +			err = mlx4_check_dev_cap(dev, dev_cap, nvfs);
>> +			if (err)
>>   				goto err_fw;
> 
> [Severity: Low]
> Which value gets propagated here? mlx4_check_dev_cap() returns a private
> enum sentinel, not an errno:
> 
> enum {
> 	MLX4_DEV_CAP_CHECK_NUM_VFS_ABOVE_64 = -1,
> };
> 
> With this change mlx4_load_one() returns -1. __mlx4_init_one() passes that
> to the PCI core as the probe result, and mlx4_restart_one_up() returns it
> up the devlink reload path. Both will report -EPERM ("Operation not
> permitted") for what is really an invalid VF configuration. The same
> applies to the second call site in the legacy-mode branch.
> 
> Other configuration errors in mlx4_load_one() use -EINVAL, such as the
> "Trying to configure VFs on port 2" check.
> 
> Would it be better for mlx4_check_dev_cap() to return -EINVAL, or for the
> call sites to set err = -EINVAL?
> 

Please address.

>>   
>>   			if (!(dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS)) {
> 
> [Severity: High]
> Is the same problem still present a few lines further down in this block?
> Once mlx4_check_dev_cap() succeeds, err is 0. The invalid SRIOV state
> check then jumps to err_sriov without setting err:
> 
> drivers/net/ethernet/mellanox/mlx4/main.c:mlx4_load_one() {
>      ...
> 				dev->flags = dev_flags;
> 				if (!SRIOV_VALID_STATE(dev->flags)) {
> 					mlx4_err(dev, "Invalid SRIOV state\n");
> 					goto err_sriov;
> 				}
>      ...
> }
> 
> This state looks reachable. mlx4_enable_sriov() starts from
> dev_flags = dev->flags. If kzalloc_objs() for dev->dev_vfs fails, it
> exits through:
> 
> disable_sriov:
> 	atomic_dec(&pf_loading);
> free_mem:
> 	dev->persist->num_vfs = 0;
> 	kfree(dev->dev_vfs);
> 	dev->dev_vfs = NULL;
> 	return dev_flags & ~MLX4_FLAG_MASTER;
> 
> Suppose dev->flags already had MLX4_FLAG_SRIOV (existing_vfs != 0, or the
> reset_flow path). Then this returns SRIOV set and MASTER cleared, so
> SRIOV_VALID_STATE() is false.
> 
> The err_sriov unwind then tears everything down, including
> mlx4_adev_cleanup(), and mlx4_load_one() returns 0. __mlx4_init_one()
> takes its success path:
> 
> 	err = mlx4_load_one(pdev, pci_dev_data, total_vfs, nvfs, priv, 0);
> 	if (err)
> 		goto err_catas;
> 
> 	return 0;
> 
> On the reload path, mlx4_restart_one_up() would also continue into
> restore_current_port_types() on the torn-down device.
> 
> priv->removed stays 0. Can a later mlx4_unload_one() then run the teardown
> a second time, including a second kfree(priv->adev) and ida_free() in
> mlx4_adev_cleanup()?
> 
> The matching check in the SYS_EQS path already sets err:
> 
> 		if (!SRIOV_VALID_STATE(dev->flags)) {
> 			mlx4_err(dev, "Invalid SRIOV state\n");
> 			err = -EINVAL;
> 			goto err_close;
> 		}
> 
> Should the non-SYS_EQS check also set err = -EINVAL before the
> goto err_sriov?
> 
> [ ... ]
> 

It can be a separate patch, as it has a different Fixes tag:

Fixes: 7ae0e400cd93 ("net/mlx4_core: Flexible (asymmetric) allocation of 
EQs and MSI-X vectors for PF/VFs")

Please target net branch in your V2.


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

end of thread, other threads:[~2026-11-29  9:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  2:29 [PATCH] net/mlx4: fix error propagation in mlx4_load_one() mdshahid03
2026-11-25  2:33 ` netdev-bot+sinfo
2026-11-25 18:12 ` Joe Damato
2026-11-29  2:38 ` netdev-bot+sashiko
2026-11-29  9:16   ` Tariq Toukan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox