From nobody Mon Feb 9 05:44:40 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 77EFE1E1DFC; Wed, 28 Jan 2026 15:44:53 +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=1769615097; cv=none; b=ioNTouabNx9HFtposB048MCO+9hRoPonQiUPgYToYTYRgNZuw/m6/g2WwyCfV8eyBRXTrvhB1/7GMSAzXFLkWT0VAnAFPufH6v26JEu+LodB63qPBeVJKAJFhqbTZJmtCu1mqztw+/8yvuBgvIOvX6HwZbX66BUjtjO7dy+2FKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769615097; c=relaxed/simple; bh=ZAaWOVRM/vFfGE1SFvnAeMmUQRw30b+62j4qN/VRGY4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=k/hfNJQVF1TFrgNs5cFNE02PqeMS9BTlsgPKq1NCWv5YU33sCAr7Xm3B+pTGXBL3YLxED/3JnvASwYrLN4bm4tttu9rdb6JXcPLyD1OBC96lJooHIPpoQq15abEI2E+lDDFBGmMQCPadvMIjmsw11P+NEXy5N9Y6VhDieFdDFZo= 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=M4v/krlb; 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="M4v/krlb" Received: from LAPTOP-N070L597.localdomain (unknown [58.215.202.202]) by smtp.qiye.163.com (Hmail) with ESMTP id 324da1fd6; Wed, 28 Jan 2026 23:44:44 +0800 (GMT+08:00) From: Zilin Guan To: andrew+netdev@lunn.ch Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kory.maincent@bootlin.com, horms@kernel.org, jianhao.xu@seu.edu.cn, marco.crivellari@suse.com, vadim.fedorenko@linux.dev, Zilin Guan Subject: [PATCH net v4 1/3] net: liquidio: Initialize netdev pointer before queue setup Date: Wed, 28 Jan 2026 15:44:38 +0000 Message-Id: <20260128154440.278369-2-zilin@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260128154440.278369-1-zilin@seu.edu.cn> References: <20260128154440.278369-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: 0a9c05474d9d03a1kunm1b02b57ddb3d8 X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkaT09MVk9MTRgYQ0tLGR9IGlYeHw5VEwETFhoSFy QUDg9ZV1kYEgtZQVlOQ1VJSk5VSUtJVUlLSVlXWRYaDxIVHRRZQVlPS0hVSktJSE5DQ1VKS0tVS1 kG DKIM-Signature: a=rsa-sha256; b=M4v/krlbZ97k3k/0xK05uAW6SJosdZO84L6+GKfUsQ8TXqewfekDQpZqhEIOuz/ZsY+kZTn68zplu7nEZOcRbpp2qEIpzc2GO7B/YK1eFCPK5FwVZV2WRBQ6VUZmi/goluScP8PXFEhgNuakE5h/lKpE8BVRYrALqHaL/Z2NxyE=; s=default; c=relaxed/relaxed; d=seu.edu.cn; v=1; bh=2Gvu7Cs6MUOs7Uj2POOLbf2vbtFZCfImjtAFkNUxkoU=; 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 0732440eeacd..1f10b1b22a1e 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 From nobody Mon Feb 9 05:44:40 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 3937F2FDC5D; Wed, 28 Jan 2026 15:44:54 +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=1769615097; cv=none; b=FMcShTiPJKlWUJhy156+HL4UWo6r1DbQ9XyKI8vkNBWEWUkKIEGLm5QUIncyVfY5oFp3mCRkZyJnoTWiHwqZxYUGeQJthM9QsMeJpGsFE5XmTkp4yrPo/7j+uddGStcm4xxZk5YfBXN7jo0vTalxvdI1pOvoBHE/oNsgdeJXR9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769615097; c=relaxed/simple; bh=BNA6sYQOOdQsqSnhMCDqfVazxL+/ZZHxiug34VfsfH4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Kq/SNZqbG680v5UiGKrLSmRb3zmRSxpBovq0O0shaAGuuUx6boQ7tS2rCFVENvYfvSQ2xPBiEOGB5Degs1We6gtqbAB/zP20Z0hTlSs3nXgFg2mDp3SA75Hp050QHZX/CxkFLa/IhJ2iv7RNWGmvuo1IZllYl9tYWqVj5KROapk= 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=je4YNfC1; 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="je4YNfC1" Received: from LAPTOP-N070L597.localdomain (unknown [58.215.202.202]) by smtp.qiye.163.com (Hmail) with ESMTP id 324da1fd7; Wed, 28 Jan 2026 23:44:46 +0800 (GMT+08:00) From: Zilin Guan To: andrew+netdev@lunn.ch Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kory.maincent@bootlin.com, horms@kernel.org, jianhao.xu@seu.edu.cn, marco.crivellari@suse.com, vadim.fedorenko@linux.dev, Zilin Guan Subject: [PATCH net v4 2/3] net: liquidio: Fix off-by-one error in PF setup_nic_devices() cleanup Date: Wed, 28 Jan 2026 15:44:39 +0000 Message-Id: <20260128154440.278369-3-zilin@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260128154440.278369-1-zilin@seu.edu.cn> References: <20260128154440.278369-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: 0a9c054753f103a1kunm1b02b57ddb3dd X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlDTk0ZVh5OGE5CS0gdTRlIQlYeHw5VEwETFhoSFy QUDg9ZV1kYEgtZQVlOQ1VJSk5VSUtJVUlLSVlXWRYaDxIVHRRZQVlPS0hVSktJSE5DQ1VKS0tVS1 kG DKIM-Signature: a=rsa-sha256; b=je4YNfC1Q37MZePL/pcjQvBAPmGVEN0iUudefxZB2+bgQPF63eMZQ0WBCL/c3B5WjWTuWPWbTqSOAjCXPz8GGxnaH7129Mdqjpp18wfVhGu9GOKh4+j2b8RWW+2CKn+/vXOuxSlbL8I2s4mMBqOs2rSqMF3OBVMpP23KjIcfQDY=; s=default; c=relaxed/relaxed; d=seu.edu.cn; v=1; bh=WeRSizaK9Z097KPactBI95E8mOed7Xbc57TUxOtP6l8=; 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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/= ethernet/cavium/liquidio/lio_main.c index 1f10b1b22a1e..c1a3df225254 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,11 +3766,11 @@ static int setup_nic_devices(struct octeon_device *= octeon_dev) =20 setup_nic_dev_free: =20 - while (i--) { + do { dev_err(&octeon_dev->pci_dev->dev, "NIC ifidx:%d Setup failed\n", i); liquidio_destroy_nic_device(octeon_dev, i); - } + } while (i--); =20 setup_nic_dev_done: =20 --=20 2.34.1 From nobody Mon Feb 9 05:44:40 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 41C6830F555; Wed, 28 Jan 2026 15:44:56 +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=1769615099; cv=none; b=YTg5nx+HwTc4LIlnCzY5zwGm7ULgJnf4Jbpq+7zwTyj1jUx3/6EFRw1XSeVdzqkF7ADSWbavauXgkl4tlwbP+b/NlspFMBFxp0Y3Ov3IdbuLDuZtqusAARuqDd0lbvfa8qc1Bn8M3LHff06tleYd4u0Q1mO2DQotcbiepleSmHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769615099; c=relaxed/simple; bh=4ohvm5fhYBh6VZdJuEVdOpHMU7B4aefcxRQthZ1EpU8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ggk65Zzk7etleefKhPTRkvxB/krhkiTlvXskbpOeS0vzbOHUydQBF3DUtbykI4scaQVta4kGGGHr5QT2a+iTUJLvYaV9i3CbLFwX8CgskuozCe9B+F79JrLkHHXwm4QONJ0C+wN5aFbDxv5tdn+gHkU1f3AjwTaIhQDsL1tPbms= 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=K+iLZ2zq; 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="K+iLZ2zq" Received: from LAPTOP-N070L597.localdomain (unknown [58.215.202.202]) by smtp.qiye.163.com (Hmail) with ESMTP id 324da1fd9; Wed, 28 Jan 2026 23:44:48 +0800 (GMT+08:00) From: Zilin Guan To: andrew+netdev@lunn.ch Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kory.maincent@bootlin.com, horms@kernel.org, jianhao.xu@seu.edu.cn, marco.crivellari@suse.com, vadim.fedorenko@linux.dev, Zilin Guan Subject: [PATCH net v4 3/3] net: liquidio: Fix off-by-one error in VF setup_nic_devices() cleanup Date: Wed, 28 Jan 2026 15:44:40 +0000 Message-Id: <20260128154440.278369-4-zilin@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260128154440.278369-1-zilin@seu.edu.cn> References: <20260128154440.278369-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: 0a9c054759fa03a1kunm1b02b57ddb3e5 X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlDSEIeVh5LHU9OGRpJTU8dTlYeHw5VEwETFhoSFy QUDg9ZV1kYEgtZQVlOQ1VJSk5VSUtJVUlLSVlXWRYaDxIVHRRZQVlPS0hVSktJSE5DQ1VKS0tVS1 kG DKIM-Signature: a=rsa-sha256; b=K+iLZ2zq+W/jQd+hyYK8k3Nm7/eBuO+AT41YW+pX3UYqMLCyy2bfKC+oBCm4AuDpRefN+7j9CJ+D+0VQHyDyXlJMBjvWC1HaX3j5biclLp1A6iTR/YryHD44HXQO9m12EuSwRukht119UzFZXBSPkNSsjAbs2VCs0Oxd3G0wCDc=; s=default; c=relaxed/relaxed; d=seu.edu.cn; v=1; bh=CBdMc180N7C4v3ADEW9t7d40OZ9GfRgKpYtOHjIS0Ys=; 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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..43c595f3b84e 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c @@ -2212,11 +2212,11 @@ static int setup_nic_devices(struct octeon_device *= octeon_dev) =20 setup_nic_dev_free: =20 - while (i--) { + do { dev_err(&octeon_dev->pci_dev->dev, "NIC ifidx:%d Setup failed\n", i); liquidio_destroy_nic_device(octeon_dev, i); - } + } while (i--); =20 setup_nic_dev_done: =20 --=20 2.34.1