Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2] net/mlx4: fix error propagation in mlx4_load_one()
@ 2026-11-30  2:49 mdshahid03
  2026-11-30  2:53 ` netdev-bot+sinfo
  2026-12-01  2:52 ` netdev-bot+sashiko
  0 siblings, 2 replies; 3+ messages in thread
From: mdshahid03 @ 2026-11-30  2:49 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 returns 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.

Also, return -EINVAL from mlx4_check_dev_cap() instead of using a
private error value for an invalid VF configuration.

Fixes: de966c592802 ("net/mlx4_core: Support more than 64 VFs")
Signed-off-by: Mohammad Shahid <mdshahid03@gmail.com>
---
 drivers/net/ethernet/mellanox/mlx4/main.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 036135df23bf..96d1e7b58fb7 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -3331,10 +3331,6 @@ static u64 mlx4_enable_sriov(struct mlx4_dev *dev, struct pci_dev *pdev,
 	return dev_flags & ~MLX4_FLAG_MASTER;
 }
 
-enum {
-	MLX4_DEV_CAP_CHECK_NUM_VFS_ABOVE_64 = -1,
-};
-
 static int mlx4_check_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap,
 			      int *nvfs)
 {
@@ -3344,7 +3340,7 @@ static int mlx4_check_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap
 	    requested_vfs >= 64) {
 		mlx4_err(dev, "Requested %d VFs, but FW does not support more than 64\n",
 			 requested_vfs);
-		return MLX4_DEV_CAP_CHECK_NUM_VFS_ABOVE_64;
+		return -EINVAL;
 	}
 	return 0;
 }
@@ -3505,7 +3501,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 +3537,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] 3+ messages in thread

* Re: [PATCH net v2] net/mlx4: fix error propagation in mlx4_load_one()
  2026-11-30  2:49 [PATCH net v2] net/mlx4: fix error propagation in mlx4_load_one() mdshahid03
@ 2026-11-30  2:53 ` netdev-bot+sinfo
  2026-12-01  2:52 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-30  2:53 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] 3+ messages in thread

* Re: [PATCH net v2] net/mlx4: fix error propagation in mlx4_load_one()
  2026-11-30  2:49 [PATCH net v2] net/mlx4: fix error propagation in mlx4_load_one() mdshahid03
  2026-11-30  2:53 ` netdev-bot+sinfo
@ 2026-12-01  2:52 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01  2:52 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 2 potential
issue(s) to consider.

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

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 is incomplete.
- [Low] The commit message understates the impact of the bug it fixes.

--

net/mlx4: fix error propagation in mlx4_load_one()

This commit assigns the return value of mlx4_check_dev_cap() to err at
both call sites in mlx4_load_one(). A failed VF count check is now
propagated instead of returning 0. It also changes mlx4_check_dev_cap()
to return -EINVAL instead of a private enum value.

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

[Severity: Low]
This isn't a bug, but is "may" accurate here? On both patched paths the
preceding mlx4_QUERY_DEV_CAP() call has just succeeded:

    err = mlx4_QUERY_DEV_CAP(dev, dev_cap);
    if (err) {
        mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
        goto err_fw;
    }

So err is always 0 when the old check jumped to err_fw.

Could the changelog also describe the user-visible effect? Suppose the FW
lacks MLX4_DEV_CAP_FLAG2_80_VFS and 64 or more VFs are requested. Then
mlx4_load_one() runs the full err_fw ... err_adev teardown and returns 0.

__mlx4_init_one() then reports a successful probe, and devlink gets
registered for a torn-down device. The reset_flow callers (devlink reload,
catas restart, PCI resume/slot_reset) also report success.

A later devlink reload goes through mlx4_unload_one() with priv->removed
still 0 and repeats the teardown. That includes a second kfree(priv->adev)
in mlx4_adev_cleanup(). mlx4_remove_one() is protected by the
MLX4_INTERFACE_STATE_UP check, but the devlink reload path is not.

This patch has a Fixes: tag. Could the changelog state this consequence?

> diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
> index 036135df23bf1..96d1e7b58fb77 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/main.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/main.c

[ ... ]

> @@ -3505,7 +3501,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)) {

[Severity: High]
Is there one more exit in this same block that still returns 0? After
mlx4_check_dev_cap() succeeds here, err is 0. The legacy path then does
this:

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

The err_sriov ... err_adev chain tears everything down and ends with
"return err;", which returns 0 here.

Can this state be reached? mlx4_enable_sriov() returns
"dev_flags & ~MLX4_FLAG_MASTER" with MLX4_FLAG_SRIOV still set when the
dev_vfs allocation fails. That can happen in the reset_flow branch
(goto free_mem). It can also happen on a probe where SR-IOV was already
enabled (goto disable_sriov).

The callers then treat the device as loaded:

- __mlx4_init_one() returns 0 and devlink gets registered.
- mlx4_restart_one_up() and mlx4_pci_resume() call
  restore_current_port_types() on a device whose FW and command interface
  are closed.

A later devlink reload would go through this chain:

mlx4_devlink_reload_down()
  mlx4_restart_one_down()
    mlx4_unload_one()

mlx4_unload_one() checks only priv->removed, so it repeats the teardown:

- mlx4_close_fw() and mlx4_cmd_cleanup() run a second time.
- mlx4_uar_free() runs on an uninitialized bitmap.
- mlx4_adev_cleanup() runs a second time. It does kfree(priv->adev)
  without clearing the pointer, so priv->adev is freed twice.

The SYS_EQS path has the same check, and it sets err first:

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

Should the legacy path also set err = -EINVAL before goto err_sriov?

[ ... ]

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

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

end of thread, other threads:[~2026-12-01  2:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  2:49 [PATCH net v2] net/mlx4: fix error propagation in mlx4_load_one() mdshahid03
2026-11-30  2:53 ` netdev-bot+sinfo
2026-12-01  2:52 ` netdev-bot+sashiko

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