All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iwl-net v1] idpf: fix lan_regs leak on core init failure
@ 2026-07-03 10:41 ` xuanqiang.luo
  0 siblings, 0 replies; 5+ messages in thread
From: xuanqiang.luo @ 2026-07-03 10:41 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: netdev, linux-kernel, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	Joshua Hay, Tatyana Nikolova, Xuanqiang Luo

From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>

idpf_vc_core_init() gets the LAN memory region layout before mapping the
regions and allocating vport resources. Both layout paths allocate
hw->lan_regs, but later error paths return without freeing it.

idpf_vc_core_deinit() does not cover these paths because it returns unless
IDPF_VC_CORE_INIT is set, and that bit is set only after core init
succeeds.

Free hw->lan_regs on the post-allocation error paths and clear the
pointer and region count.

Fixes: 6aa53e861c1a ("idpf: implement get LAN MMIO memory regions")
Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
---
 drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
index be66f9b2e101c..da49bb7b7e671 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
@@ -3479,6 +3479,7 @@ static int idpf_vport_params_buf_alloc(struct idpf_adapter *adapter)
  */
 int idpf_vc_core_init(struct idpf_adapter *adapter)
 {
+	struct idpf_hw *hw = &adapter->hw;
 	int task_delay = 30;
 	u16 num_max_vports;
 	int err = 0;
@@ -3550,15 +3551,18 @@ int idpf_vc_core_init(struct idpf_adapter *adapter)
 	if (err) {
 		dev_err(&adapter->pdev->dev, "Failed to map BAR0 region(s): %d\n",
 			err);
-		return -ENOMEM;
+		err = -ENOMEM;
+		goto err_lan_regs;
 	}
 
 	pci_sriov_set_totalvfs(adapter->pdev, idpf_get_max_vfs(adapter));
 	num_max_vports = idpf_get_max_vports(adapter);
 	adapter->max_vports = num_max_vports;
 	adapter->vports = kzalloc_objs(*adapter->vports, num_max_vports);
-	if (!adapter->vports)
-		return -ENOMEM;
+	if (!adapter->vports) {
+		err = -ENOMEM;
+		goto err_lan_regs;
+	}
 
 	if (!adapter->netdevs) {
 		adapter->netdevs = kzalloc_objs(struct net_device *,
@@ -3624,6 +3628,10 @@ int idpf_vc_core_init(struct idpf_adapter *adapter)
 err_netdev_alloc:
 	kfree(adapter->vports);
 	adapter->vports = NULL;
+err_lan_regs:
+	kfree(hw->lan_regs);
+	hw->lan_regs = NULL;
+	hw->num_lan_regs = 0;
 	return err;
 
 init_failed:
-- 
2.43.0


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

* [Intel-wired-lan] [PATCH iwl-net v1] idpf: fix lan_regs leak on core init failure
@ 2026-07-03 10:41 ` xuanqiang.luo
  0 siblings, 0 replies; 5+ messages in thread
From: xuanqiang.luo @ 2026-07-03 10:41 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: netdev, linux-kernel, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	Joshua Hay, Tatyana Nikolova, Xuanqiang Luo

From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>

idpf_vc_core_init() gets the LAN memory region layout before mapping the
regions and allocating vport resources. Both layout paths allocate
hw->lan_regs, but later error paths return without freeing it.

idpf_vc_core_deinit() does not cover these paths because it returns unless
IDPF_VC_CORE_INIT is set, and that bit is set only after core init
succeeds.

Free hw->lan_regs on the post-allocation error paths and clear the
pointer and region count.

Fixes: 6aa53e861c1a ("idpf: implement get LAN MMIO memory regions")
Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
---
 drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
index be66f9b2e101c..da49bb7b7e671 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
@@ -3479,6 +3479,7 @@ static int idpf_vport_params_buf_alloc(struct idpf_adapter *adapter)
  */
 int idpf_vc_core_init(struct idpf_adapter *adapter)
 {
+	struct idpf_hw *hw = &adapter->hw;
 	int task_delay = 30;
 	u16 num_max_vports;
 	int err = 0;
@@ -3550,15 +3551,18 @@ int idpf_vc_core_init(struct idpf_adapter *adapter)
 	if (err) {
 		dev_err(&adapter->pdev->dev, "Failed to map BAR0 region(s): %d\n",
 			err);
-		return -ENOMEM;
+		err = -ENOMEM;
+		goto err_lan_regs;
 	}
 
 	pci_sriov_set_totalvfs(adapter->pdev, idpf_get_max_vfs(adapter));
 	num_max_vports = idpf_get_max_vports(adapter);
 	adapter->max_vports = num_max_vports;
 	adapter->vports = kzalloc_objs(*adapter->vports, num_max_vports);
-	if (!adapter->vports)
-		return -ENOMEM;
+	if (!adapter->vports) {
+		err = -ENOMEM;
+		goto err_lan_regs;
+	}
 
 	if (!adapter->netdevs) {
 		adapter->netdevs = kzalloc_objs(struct net_device *,
@@ -3624,6 +3628,10 @@ int idpf_vc_core_init(struct idpf_adapter *adapter)
 err_netdev_alloc:
 	kfree(adapter->vports);
 	adapter->vports = NULL;
+err_lan_regs:
+	kfree(hw->lan_regs);
+	hw->lan_regs = NULL;
+	hw->num_lan_regs = 0;
 	return err;
 
 init_failed:
-- 
2.43.0


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

* RE: [PATCH iwl-net v1] idpf: fix lan_regs leak on core init failure
  2026-07-03 10:41 ` [Intel-wired-lan] " xuanqiang.luo
@ 2026-07-06  9:12   ` Jagielski, Jedrzej
  -1 siblings, 0 replies; 5+ messages in thread
From: Jagielski, Jedrzej @ 2026-07-06  9:12 UTC (permalink / raw)
  To: xuanqiang.luo@linux.dev, intel-wired-lan@lists.osuosl.org
  Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nguyen, Anthony L, Kitszel, Przemyslaw, Andrew Lunn,
	Hay, Joshua A, Nikolova, Tatyana E, Xuanqiang Luo

From: xuanqiang.luo@linux.dev <xuanqiang.luo@linux.dev> 
Sent: Friday, July 3, 2026 12:42 PM

>From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
>
>idpf_vc_core_init() gets the LAN memory region layout before mapping the
>regions and allocating vport resources. Both layout paths allocate
>hw->lan_regs, but later error paths return without freeing it.
>
>idpf_vc_core_deinit() does not cover these paths because it returns unless
>IDPF_VC_CORE_INIT is set, and that bit is set only after core init
>succeeds.
>
>Free hw->lan_regs on the post-allocation error paths and clear the
>pointer and region count.
>
>Fixes: 6aa53e861c1a ("idpf: implement get LAN MMIO memory regions")
>Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>


Looks fine, thanks for the patch!

Reviewed-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>

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

* Re: [Intel-wired-lan] [PATCH iwl-net v1] idpf: fix lan_regs leak on core init failure
@ 2026-07-06  9:12   ` Jagielski, Jedrzej
  0 siblings, 0 replies; 5+ messages in thread
From: Jagielski, Jedrzej @ 2026-07-06  9:12 UTC (permalink / raw)
  To: xuanqiang.luo@linux.dev, intel-wired-lan@lists.osuosl.org
  Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nguyen, Anthony L, Kitszel, Przemyslaw, Andrew Lunn,
	Hay, Joshua A, Nikolova, Tatyana E, Xuanqiang Luo

From: xuanqiang.luo@linux.dev <xuanqiang.luo@linux.dev> 
Sent: Friday, July 3, 2026 12:42 PM

>From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
>
>idpf_vc_core_init() gets the LAN memory region layout before mapping the
>regions and allocating vport resources. Both layout paths allocate
>hw->lan_regs, but later error paths return without freeing it.
>
>idpf_vc_core_deinit() does not cover these paths because it returns unless
>IDPF_VC_CORE_INIT is set, and that bit is set only after core init
>succeeds.
>
>Free hw->lan_regs on the post-allocation error paths and clear the
>pointer and region count.
>
>Fixes: 6aa53e861c1a ("idpf: implement get LAN MMIO memory regions")
>Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>


Looks fine, thanks for the patch!

Reviewed-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>

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

* Re: [Intel-wired-lan] [PATCH iwl-net v1] idpf: fix lan_regs leak on core init failure
  2026-07-03 10:41 ` [Intel-wired-lan] " xuanqiang.luo
  (?)
  (?)
@ 2026-07-06  9:51 ` Marcin Szycik
  -1 siblings, 0 replies; 5+ messages in thread
From: Marcin Szycik @ 2026-07-06  9:51 UTC (permalink / raw)
  To: xuanqiang.luo, intel-wired-lan
  Cc: netdev, linux-kernel, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	Joshua Hay, Tatyana Nikolova, Xuanqiang Luo



On 03/07/2026 12:41, xuanqiang.luo@linux.dev wrote:
> From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
> 
> idpf_vc_core_init() gets the LAN memory region layout before mapping the
> regions and allocating vport resources. Both layout paths allocate
> hw->lan_regs, but later error paths return without freeing it.
> 
> idpf_vc_core_deinit() does not cover these paths because it returns unless
> IDPF_VC_CORE_INIT is set, and that bit is set only after core init
> succeeds.
> 
> Free hw->lan_regs on the post-allocation error paths and clear the
> pointer and region count.
> 
> Fixes: 6aa53e861c1a ("idpf: implement get LAN MMIO memory regions")
> Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
> ---
>  drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> index be66f9b2e101c..da49bb7b7e671 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> @@ -3479,6 +3479,7 @@ static int idpf_vport_params_buf_alloc(struct idpf_adapter *adapter)
>   */
>  int idpf_vc_core_init(struct idpf_adapter *adapter)
>  {
> +	struct idpf_hw *hw = &adapter->hw;
>  	int task_delay = 30;
>  	u16 num_max_vports;
>  	int err = 0;
> @@ -3550,15 +3551,18 @@ int idpf_vc_core_init(struct idpf_adapter *adapter)
>  	if (err) {
>  		dev_err(&adapter->pdev->dev, "Failed to map BAR0 region(s): %d\n",
>  			err);
> -		return -ENOMEM;
> +		err = -ENOMEM;
> +		goto err_lan_regs;
>  	}
>  
>  	pci_sriov_set_totalvfs(adapter->pdev, idpf_get_max_vfs(adapter));
>  	num_max_vports = idpf_get_max_vports(adapter);
>  	adapter->max_vports = num_max_vports;
>  	adapter->vports = kzalloc_objs(*adapter->vports, num_max_vports);
> -	if (!adapter->vports)
> -		return -ENOMEM;
> +	if (!adapter->vports) {
> +		err = -ENOMEM;
> +		goto err_lan_regs;
> +	}
>  
>  	if (!adapter->netdevs) {
>  		adapter->netdevs = kzalloc_objs(struct net_device *,
> @@ -3624,6 +3628,10 @@ int idpf_vc_core_init(struct idpf_adapter *adapter)
>  err_netdev_alloc:
>  	kfree(adapter->vports);
>  	adapter->vports = NULL;
> +err_lan_regs:
> +	kfree(hw->lan_regs);
> +	hw->lan_regs = NULL;
> +	hw->num_lan_regs = 0;
>  	return err;
>  
>  init_failed:

Does this apply? struct idpf_hw was removed in 9f4334ac4a5a ("idpf: refactor
idpf to use libie control queues") [1].

[1] https://lore.kernel.org/intel-wired-lan/20260608144127.2751230-10-larysa.zaremba@intel.com/

Thanks,
Marcin

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

end of thread, other threads:[~2026-07-06  9:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-03 10:41 [PATCH iwl-net v1] idpf: fix lan_regs leak on core init failure xuanqiang.luo
2026-07-03 10:41 ` [Intel-wired-lan] " xuanqiang.luo
2026-07-06  9:12 ` Jagielski, Jedrzej
2026-07-06  9:12   ` [Intel-wired-lan] " Jagielski, Jedrzej
2026-07-06  9:51 ` Marcin Szycik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.