From nobody Mon Feb 9 05:29:45 2026 Received: from mail-m49197.qiye.163.com (mail-m49197.qiye.163.com [45.254.49.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75656366051; Tue, 27 Jan 2026 15:13:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.254.49.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769526783; cv=none; b=DEi46EPImIdSZkWLN6GPvVVB4YZ5iMlZWKiSCUFdb4D2KGDfmmlducHsa9BjxeaMq8zEByJUG8jqpXq++s/pTRFQhTQ7YJ6bUfNOlTsPbnHGdAKz3joCicZm/fS04G7oYnZkVo8ue/LgaFNBJ3g38AvEuqEb0WO+bkwQEHie43w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769526783; c=relaxed/simple; bh=cIXqT5FnicbiGpytwx5r3gF/Cd0q8kd1fuH3bp8cggg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FdSFEcJbtgUyv1X0+q7iaCbZuJBmMakFeXsjZMDXZGrvNVEniB0vKeLrkM/f3EfX3uPkJNW7evgkmaM+IPTArTOPKsSIlz/UBqixlvLjGzn8RD7J9WEYOj+EowbCD2u7nX4YWhyIUDD0YVBO2+FViH/yaSInUu8VevYF6SCMNmg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=cBTbtAk0; arc=none smtp.client-ip=45.254.49.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="cBTbtAk0" Received: from LAPTOP-N070L597.localdomain (unknown [58.241.16.34]) by smtp.qiye.163.com (Hmail) with ESMTP id 32272e8ee; Tue, 27 Jan 2026 23:12:52 +0800 (GMT+08:00) From: Zilin Guan To: horms@kernel.org Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, jianhao.xu@seu.edu.cn, kory.maincent@bootlin.com, kuba@kernel.org, linux-kernel@vger.kernel.org, marco.crivellari@suse.com, netdev@vger.kernel.org, pabeni@redhat.com, vadim.fedorenko@linux.dev, Zilin Guan Subject: [PATCH net v3 1/3] net: liquidio: Fix off-by-one error in PF setup_nic_devices() cleanup Date: Tue, 27 Jan 2026 15:12:39 +0000 Message-Id: <20260127151241.1144039-2-zilin@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260127151241.1144039-1-zilin@seu.edu.cn> References: <20260127151241.1144039-1-zilin@seu.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0a9c0003c22203a1kunmaea0ca6058ce6 X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlDHR4eVh0dH0hCHUNLHxkaHVYeHw5VEwETFhoSFy QUDg9ZV1kYEgtZQVlOQ1VJT0pVSk1VSE9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhOQ0NVSktLVUtZBg ++ DKIM-Signature: a=rsa-sha256; b=cBTbtAk0xhLj12HmCc3DtgaA7hCTolYl+2ZHbuavgHEYXHF6o1r3fo6W+tETmU4ecnhAbVcAMebjkXnwiRH9K9N2uHDwqP4qu1sds10pp8MUm9/nazJ5muohN6uJoJDSNy7yBbSDmsUlwJU/Ar1f+bYQ/OsEFtGSQl3WAuLa4jc=; s=default; c=relaxed/relaxed; d=seu.edu.cn; v=1; bh=0sd9aewjv4fvCJ9HVyUnkC7myYx922OsGGV1uHmx4Ww=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" In setup_nic_devices(), the initialization loop jumps to the label setup_nic_dev_free on failure. The current cleanup loop while(i--) skip the failing index i, causing a memory leak. Fix this by changing the loop to iterate from the current index i down to 0. Also, decrement i in the devlink_alloc failure path to point to the last successfully allocated index. Compile tested only. Issue found using code review. Fixes: f21fb3ed364b ("Add support of Cavium Liquidio ethernet adapters") Suggested-by: Simon Horman Signed-off-by: Zilin Guan Reviewed-by: Kory Maincent --- drivers/net/ethernet/cavium/liquidio/lio_main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/= ethernet/cavium/liquidio/lio_main.c index 0732440eeacd..e9a728997689 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_main.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_main.c @@ -3750,6 +3750,7 @@ static int setup_nic_devices(struct octeon_device *oc= teon_dev) if (!devlink) { device_unlock(&octeon_dev->pci_dev->dev); dev_err(&octeon_dev->pci_dev->dev, "devlink alloc failed\n"); + i--; goto setup_nic_dev_free; } =20 @@ -3765,10 +3766,11 @@ static int setup_nic_devices(struct octeon_device *= octeon_dev) =20 setup_nic_dev_free: =20 - while (i--) { + while (i >=3D 0) { dev_err(&octeon_dev->pci_dev->dev, "NIC ifidx:%d Setup failed\n", i); liquidio_destroy_nic_device(octeon_dev, i); + i--; } =20 setup_nic_dev_done: --=20 2.34.1 From nobody Mon Feb 9 05:29:45 2026 Received: from mail-m49198.qiye.163.com (mail-m49198.qiye.163.com [45.254.49.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 071C135F8B1; Tue, 27 Jan 2026 15:12:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.254.49.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769526779; cv=none; b=loF8JQ5XUzoyqDLN3nc9Ib+CaT+Yg1rhJhuL8NsegYcZT++PxfQif7IcLlOM8QnJGYj03togNO11nGHKHwr+ljza53qBsqCS3g6+acKp/zgtCrhIPE9UQkI4UEMfJUbrhHqy+S4LE9IbDdxetZLgdtUkK3+dqYunQrAfNNsfGSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769526779; c=relaxed/simple; bh=dMB145a7yMhOOQBd500anVWAgo8E3r+vL2gn4Qbd7ao=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Kg8Qnk0s5Gs1nIxI7QbG3tOulh7mWD838AW/rTfE9Wz4d0jyGTbKMvm9uz92ZWbNkXUvt8TcuvMqe47CCtnPBsRh0GTW8yNvUztfUM05sBVGDhWYGL9apLnNnfc1XuWxT7wDoyeP+7xw73jIn0npkI7rNQWJ2MoBveDxyBLVN5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=HEQ1Qa3D; arc=none smtp.client-ip=45.254.49.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="HEQ1Qa3D" Received: from LAPTOP-N070L597.localdomain (unknown [58.241.16.34]) by smtp.qiye.163.com (Hmail) with ESMTP id 32272e8f0; Tue, 27 Jan 2026 23:12:53 +0800 (GMT+08:00) From: Zilin Guan To: horms@kernel.org Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, jianhao.xu@seu.edu.cn, kory.maincent@bootlin.com, kuba@kernel.org, linux-kernel@vger.kernel.org, marco.crivellari@suse.com, netdev@vger.kernel.org, pabeni@redhat.com, vadim.fedorenko@linux.dev, Zilin Guan Subject: [PATCH net v3 2/3] net: liquidio: Fix off-by-one error in VF setup_nic_devices() cleanup Date: Tue, 27 Jan 2026 15:12:40 +0000 Message-Id: <20260127151241.1144039-3-zilin@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260127151241.1144039-1-zilin@seu.edu.cn> References: <20260127151241.1144039-1-zilin@seu.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0a9c0003c87803a1kunmaea0ca6058ce9 X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkZQ0oZVkpOTUNLQ0oYShpPQlYeHw5VEwETFhoSFy QUDg9ZV1kYEgtZQVlOQ1VJT0pVSk1VSE9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhOQ0NVSktLVUtZBg ++ DKIM-Signature: a=rsa-sha256; b=HEQ1Qa3DA+mhBv/ToqIpSeJ1qwbAuFXgYzEFwzJAHOU6Bw3Xs9jnKmERtV0l7L7BLBeD+Kjv4yChF9Dy2ol7l3ZdWvWqPOnyKBwRr7SHfQaEnahzDQiObLB31IOnfbGeIDsERWKNUJmfxsBhnk4AK1m2HDAk8yKVYVhHGpcXHGM=; s=default; c=relaxed/relaxed; d=seu.edu.cn; v=1; bh=p4sgQiaqSyqHzCtFus3lKv0CQYdeiD7QQJX5j8ux/Rw=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" In setup_nic_devices(), the initialization loop jumps to the label setup_nic_dev_free on failure. The current cleanup loop while(i--) skip the failing index i, causing a memory leak. Fix this by changing the loop to iterate from the current index i down to 0. Compile tested only. Issue found using code review. Fixes: 846b46873eeb ("liquidio CN23XX: VF offload features") Suggested-by: Simon Horman Signed-off-by: Zilin Guan Reviewed-by: Kory Maincent --- drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c b/drivers/n= et/ethernet/cavium/liquidio/lio_vf_main.c index e02942dbbcce..050f9feb0b4a 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c @@ -2212,10 +2212,11 @@ static int setup_nic_devices(struct octeon_device *= octeon_dev) =20 setup_nic_dev_free: =20 - while (i--) { + while (i >=3D 0) { dev_err(&octeon_dev->pci_dev->dev, "NIC ifidx:%d Setup failed\n", i); liquidio_destroy_nic_device(octeon_dev, i); + i--; } =20 setup_nic_dev_done: --=20 2.34.1 From nobody Mon Feb 9 05:29:45 2026 Received: from mail-m155101.qiye.163.com (mail-m155101.qiye.163.com [101.71.155.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72382364E89; Tue, 27 Jan 2026 15:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=101.71.155.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769526782; cv=none; b=CcYWi1CYt4lY99ZlLSwRhInW1/2ICts1Qw9YpTvvCfTOsscyBwxvKFvy9iu90YuyDK82/pcQMlKPapqigU7kRWQMQA5D2j/Xyha6h6VrdpeBrQDngnV0YSl8BFyZvGr7uABsNJ1vOTYMfUokG0rZKF+Vb0Tl63y7lAl3ezq4f+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769526782; c=relaxed/simple; bh=GScpE5X4WSCtkNfJghc+nlOFRzvsz8znYxwPNi0Lu3s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ut0Rmss2yDwvLybnpAtlwMjNG4RpQ3SdOqCoolvi3O0eLQfbGbkQKR4NoTWhRnancjuwnk0o8H0YhJk58wD5tN9kYChH/XNcDYW0OJAnnVVMo+95gJAp5Kjf8bZA5ZYnG2LO+0LnmwzVZCycqp8UIp95MNTaWpJKhRG5gj7J2sw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=Iq7OlBM2; arc=none smtp.client-ip=101.71.155.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="Iq7OlBM2" Received: from LAPTOP-N070L597.localdomain (unknown [58.241.16.34]) by smtp.qiye.163.com (Hmail) with ESMTP id 32272e8f2; Tue, 27 Jan 2026 23:12:55 +0800 (GMT+08:00) From: Zilin Guan To: horms@kernel.org Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, jianhao.xu@seu.edu.cn, kory.maincent@bootlin.com, kuba@kernel.org, linux-kernel@vger.kernel.org, marco.crivellari@suse.com, netdev@vger.kernel.org, pabeni@redhat.com, vadim.fedorenko@linux.dev, Zilin Guan Subject: [PATCH net v3 3/3] net: liquidio: Initialize netdev pointer before queue setup Date: Tue, 27 Jan 2026 15:12:41 +0000 Message-Id: <20260127151241.1144039-4-zilin@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260127151241.1144039-1-zilin@seu.edu.cn> References: <20260127151241.1144039-1-zilin@seu.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0a9c0003ce7f03a1kunmaea0ca6058cec X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkZThpLVksfQkpOSUkeGB0YTFYeHw5VEwETFhoSFy QUDg9ZV1kYEgtZQVlOQ1VJT0pVSk1VSE9ZV1kWGg8SFR0UWUFZT0tIVUpLSUhOQ0NVSktLVUtZBg ++ DKIM-Signature: a=rsa-sha256; b=Iq7OlBM2BDpBqRiyTrqm3m4Gb3pwPCjjaO/KqWjSa/pnLJB5mxdWkUjjmOhvHZEzh0AsiVFlWlx0mUdPAlXOqxcXoVj2YPd6OVmYtM5l7hUgrB848t/L5iNeK1Q30o5xzCABBm4LVViLErMAbvhUFK4c9WcpnOKHphv5rJ0Tyqw=; s=default; c=relaxed/relaxed; d=seu.edu.cn; v=1; bh=7a1FD7qC5YrmC7wGvX/av9a2xAd5jgzjymv1/iYwGRw=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" In setup_nic_devices(), the netdev is allocated using alloc_etherdev_mq(). However, the pointer to this structure is stored in oct->props[i].netdev only after the calls to netif_set_real_num_rx_queues() and netif_set_real_num_tx_queues(). If either of these functions fails, setup_nic_devices() returns an error without freeing the allocated netdev. Since oct->props[i].netdev is still NULL at this point, the cleanup function liquidio_destroy_nic_device() will fail to find and free the netdev, resulting in a memory leak. Fix this by initializing oct->props[i].netdev before calling the queue setup functions. This ensures that the netdev is properly accessible for cleanup in case of errors. Compile tested only. Issue found using a prototype static analysis tool and code review. Fixes: c33c997346c3 ("liquidio: enhanced ethtool --set-channels feature") Signed-off-by: Zilin Guan Reviewed-by: Kory Maincent --- .../net/ethernet/cavium/liquidio/lio_main.c | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/= ethernet/cavium/liquidio/lio_main.c index e9a728997689..6c954f740073 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_main.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_main.c @@ -3505,6 +3505,23 @@ static int setup_nic_devices(struct octeon_device *o= cteon_dev) */ netdev->netdev_ops =3D &lionetdevops; =20 + lio =3D GET_LIO(netdev); + + memset(lio, 0, sizeof(struct lio)); + + lio->ifidx =3D ifidx_or_pfnum; + + props =3D &octeon_dev->props[i]; + props->gmxport =3D resp->cfg_info.linfo.gmxport; + props->netdev =3D netdev; + + /* Point to the properties for octeon device to which this + * interface belongs. + */ + lio->oct_dev =3D octeon_dev; + lio->octprops =3D props; + lio->netdev =3D netdev; + retval =3D netif_set_real_num_rx_queues(netdev, num_oqueues); if (retval) { dev_err(&octeon_dev->pci_dev->dev, @@ -3521,16 +3538,6 @@ static int setup_nic_devices(struct octeon_device *o= cteon_dev) goto setup_nic_dev_free; } =20 - lio =3D GET_LIO(netdev); - - memset(lio, 0, sizeof(struct lio)); - - lio->ifidx =3D ifidx_or_pfnum; - - props =3D &octeon_dev->props[i]; - props->gmxport =3D resp->cfg_info.linfo.gmxport; - props->netdev =3D netdev; - lio->linfo.num_rxpciq =3D num_oqueues; lio->linfo.num_txpciq =3D num_iqueues; for (j =3D 0; j < num_oqueues; j++) { @@ -3596,13 +3603,6 @@ static int setup_nic_devices(struct octeon_device *o= cteon_dev) netdev->min_mtu =3D LIO_MIN_MTU_SIZE; netdev->max_mtu =3D LIO_MAX_MTU_SIZE; =20 - /* Point to the properties for octeon device to which this - * interface belongs. - */ - lio->oct_dev =3D octeon_dev; - lio->octprops =3D props; - lio->netdev =3D netdev; - dev_dbg(&octeon_dev->pci_dev->dev, "if%d gmx: %d hw_addr: 0x%llx\n", i, lio->linfo.gmxport, CVM_CAST64(lio->linfo.hw_addr)); --=20 2.34.1