๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24918

Re: [PATCH net v2] net/mlx4: fix error propagation in mlx4_load_one()

#24918
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 02:52
132 lines
12459 bytes
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
Technical Details
Message-ID: <179609356279.3146.3334572665888004070@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374644-linux-kernel-netdev=dewy.ru
References: <20261130024959.13483-1-mdshahid03@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374644-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] net/mlx4: fix error propagation in mlx4_load_one()
Date: Tue, 01 Dec 2026 02:52:42 +0000
Organization: Usenet Network
Message-ID: <179609356279.3146.3334572665888004070@kernel.org>
References: <20261130024959.13483-1-mdshahid03@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1595177"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:24nq3OCU0t3B/jElkjX64NpOg24= sha256:7G9Ft77xAR9mtlivw05/dMKyGsbRi1jX/O7KRicM6hI=
	sha1:ioeYgdxDouNw1yg0yhPJrbf4V94= sha256:gwsvCU2UqmUiAX7kB/Vr9fajBv9VG/XQ+cBo6VdO8a4=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 6A4D4117203; Tue,  1 Dec 2026 05:53:11 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id SQ_RCvHwgnX4;
	Tue,  1 Dec 2026 05:53:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374644-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 4F7F311801F; Tue,  1 Dec 2026 05:52:56 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 15CDA278DD; Tue,  1 Dec 2026 02:52:55 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796093575;
	b=RSmDVwXCyyJmGNoy5lyD9+Ou8Mh43XyQYjEwfuKiA2+HaFg+ykDAkarxnyFFMhiPITOt
	 GQDDkRrCN0LP/zYYpRn2CLJnuitcVFMc38Y4Ljx8AOoAOmCPf6YlV1DFAFjHtLOtnQbui
	 IH5lOYWI/iJNX0grq2lbmvCnktdfUaIh6syYq0MHaQ0hIkrZX2MZQtEi5kxdTByKVcA67
	 A4/cDB3GiMkOfTfDfHTR7hORA5rhOdphP5tmvBkwWOIV3ZoDoERbjys+nELr+Em2ccC8b
	 2Br5glzY4moCqx/gDXXd/XL7f1i6mfNXLm+Sooo6oFjVV8cG9M7tBjgefGYdejEIfhQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796093575;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=b604eSCxKyZo+/uXsyzYjI1+g5W1EePHR2yJRUx8Njc=;
	b=5DDRn3b/VZJw0wI5+r7mEdMfg8Km2QfgvKEpI5LZX7RMkuMOl6oErdzsT/Dt74iic0kD
	 HZu5TUJcd12svAA63JayODnWMQHjg5SAdEGal33JOPYFhHmHuE3yEu15d0V7HgCYfZb7c
	 QVUl2KUsjxAt0WXcFqYnFySyUIJO6KBomegF7zC3sWt3EzBzUwZUtAWWJuMJlOUxf/qhC
	 mErQxrNfxWmBvYfSw3835EEgkNiZNMpqDCdxfPMBBpFBcaziZ8DB66wDPKjQut0lbhdEj
	 c42cjNit1RZZkbodLvLcCJ71nHPOE1Yj0bO01V/335yJInXKQtP7bcpyAwiteN+ObPg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="hKqbSeh/";
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id E1642606A32E;
	Tue,  1 Dec 2026 02:52:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hKqbSeh/
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796093564;
	b=ATV5QAiuzCqJOZNREsee/+awh27YhGgaJ2kh8mncpfZpBtDepSZrB3V8h07Eu6Vn+9T3
	 fttGf6GyReeUT7iOqI1lFY/AAUxmuyIy30yHIXUdQqC9NpUGelDRQ6GwVp1BttNR80wx7
	 17DVUZ2d1iDvqZeSkwMIgOKXBu0z+zgz9e0LmkGZTgeL4usoPJtsSy+cmrKRlmxORbKEI
	 8ImM+o0PgFfRaVWkJp0UR++xOKAYlIBgpGyVPev/2jmHSeyn8Wd8H5O3+Ir4MYu1jgjTX
	 /ziTyq3Du0kIgd6JwshsWpiVFHPrBWHmftFUbBJNSIz6PBcllknmg3ctopsEWh+HqEw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796093564;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=b604eSCxKyZo+/uXsyzYjI1+g5W1EePHR2yJRUx8Njc=;
	b=iw/2/pYqhoDc86rQqvd9jTv7+LKJ4yCEClfdndQkeeRhtpH/kUqOkmmOKK7nvlY2WeX7
	 3SzRrNd60s0cxSbBLMgTtPhweCpCOZJ2nK7jmx4L+PBvJr6n4ABLZCSXqhdKGQXRtUxfp
	 pFsbQp+laKYgdFaJN70g9CT457J/7G6MMDa8dWJ7to02DoEVq0rKw5b2dcnINzhBJ8Fpl
	 yoW6gV4/py44ihPL3UH5GHQzMr7Q8Psj/ucbNQ6cwrAYUZiRviMr74HUVw01ve08jvNNG
	 Of812YD5/HMVmxnjHfWxmW/a5kAs0zKxI7s2A/WcPQiW0GNryWFQvvWWukt8KNTenTw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="hKqbSeh/";
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 091D7606A320;
	Tue,  1 Dec 2026 02:52:44 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45C171F00899;
	Tue,  1 Dec 2026 02:52:43 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796093563;
	bh=b604eSCxKyZo+/uXsyzYjI1+g5W1EePHR2yJRUx8Njc=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=hKqbSeh/8p1DFXcRmnIZv5Y2C8K9OxV8G0ubRhkPSqK/kd9JEPF0vd5XyFuElqOf1
	 7+/xqz0F5kpx+8IkeU8DN3uhVUCP04tKQ70AlptAXuxXEgVQaanGNOA0UkBSEUBaQX
	 2w2J6dtBZ8kZMfYI2MRRMDnvCKwetLc/96seFq3zNbSsPr1CZISBw5wBpuPaNDGGgO
	 A1vDHXkgUyZM6syrER7VVKtapprlgOasIY3dKraSMP93oDd6qGF/UHw/5nX2ti5z34
	 wYj1N7Lp58o8ALGuLGhdtDFZ+mYEew6F6vdL0bTyQN+IlJEvR/yT3nmk8wrQcLPMgY
	 zPsdMcgv/ms+Q==
X-Cc: tariqt@nvidia.com, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 netdev@vger.kernel.org, linux-rdma@vger.kernel.org
X-In-Reply-To: <20261130024959.13483-1-mdshahid03@gmail.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list