diff mbox series

[net,2/8] net/mlx5: Fix error handling in irq_pool_request_irq

Message ID 20240730061638.1831002-3-tariqt@nvidia.com (mailing list archive)
State Accepted
Commit a4557b0b57c40871ff00da4f623cf79211e052f3
Delegated to: Netdev Maintainers
Headers show
Series mlx5 misc fixes 2024-07-30 | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 42 this patch: 42
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: linux-rdma@vger.kernel.org
netdev/build_clang success Errors and warnings before: 43 this patch: 43
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 43 this patch: 43
netdev/checkpatch warning WARNING: line length of 83 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 1 this patch: 1
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-07-31--12-00 (tests: 707)

Commit Message

Tariq Toukan July 30, 2024, 6:16 a.m. UTC
From: Shay Drory <shayd@nvidia.com>

In case mlx5_irq_alloc fails, the previously allocated index remains
in the XArray, which could lead to inconsistencies.

Fix it by adding error handling that erases the allocated index
from the XArray if mlx5_irq_alloc returns an error.

Fixes: c36326d38d93 ("net/mlx5: Round-Robin EQs over IRQs")
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Maher Sanalla <msanalla@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/irq_affinity.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Wojciech Drewek July 30, 2024, 9:34 a.m. UTC | #1
On 30.07.2024 08:16, Tariq Toukan wrote:
> From: Shay Drory <shayd@nvidia.com>
> 
> In case mlx5_irq_alloc fails, the previously allocated index remains
> in the XArray, which could lead to inconsistencies.
> 
> Fix it by adding error handling that erases the allocated index
> from the XArray if mlx5_irq_alloc returns an error.
> 
> Fixes: c36326d38d93 ("net/mlx5: Round-Robin EQs over IRQs")
> Signed-off-by: Shay Drory <shayd@nvidia.com>
> Reviewed-by: Maher Sanalla <msanalla@nvidia.com>
> Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
> ---

Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com>

>  drivers/net/ethernet/mellanox/mlx5/core/irq_affinity.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/irq_affinity.c b/drivers/net/ethernet/mellanox/mlx5/core/irq_affinity.c
> index f7b01b3f0cba..1477db7f5307 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/irq_affinity.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/irq_affinity.c
> @@ -48,6 +48,7 @@ static struct mlx5_irq *
>  irq_pool_request_irq(struct mlx5_irq_pool *pool, struct irq_affinity_desc *af_desc)
>  {
>  	struct irq_affinity_desc auto_desc = {};
> +	struct mlx5_irq *irq;
>  	u32 irq_index;
>  	int err;
>  
> @@ -64,9 +65,12 @@ irq_pool_request_irq(struct mlx5_irq_pool *pool, struct irq_affinity_desc *af_de
>  		else
>  			cpu_get(pool, cpumask_first(&af_desc->mask));
>  	}
> -	return mlx5_irq_alloc(pool, irq_index,
> -			      cpumask_empty(&auto_desc.mask) ? af_desc : &auto_desc,
> -			      NULL);
> +	irq = mlx5_irq_alloc(pool, irq_index,
> +			     cpumask_empty(&auto_desc.mask) ? af_desc : &auto_desc,
> +			     NULL);
> +	if (IS_ERR(irq))
> +		xa_erase(&pool->irqs, irq_index);
> +	return irq;
>  }
>  
>  /* Looking for the IRQ with the smallest refcount that fits req_mask.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/irq_affinity.c b/drivers/net/ethernet/mellanox/mlx5/core/irq_affinity.c
index f7b01b3f0cba..1477db7f5307 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/irq_affinity.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/irq_affinity.c
@@ -48,6 +48,7 @@  static struct mlx5_irq *
 irq_pool_request_irq(struct mlx5_irq_pool *pool, struct irq_affinity_desc *af_desc)
 {
 	struct irq_affinity_desc auto_desc = {};
+	struct mlx5_irq *irq;
 	u32 irq_index;
 	int err;
 
@@ -64,9 +65,12 @@  irq_pool_request_irq(struct mlx5_irq_pool *pool, struct irq_affinity_desc *af_de
 		else
 			cpu_get(pool, cpumask_first(&af_desc->mask));
 	}
-	return mlx5_irq_alloc(pool, irq_index,
-			      cpumask_empty(&auto_desc.mask) ? af_desc : &auto_desc,
-			      NULL);
+	irq = mlx5_irq_alloc(pool, irq_index,
+			     cpumask_empty(&auto_desc.mask) ? af_desc : &auto_desc,
+			     NULL);
+	if (IS_ERR(irq))
+		xa_erase(&pool->irqs, irq_index);
+	return irq;
 }
 
 /* Looking for the IRQ with the smallest refcount that fits req_mask.