diff mbox series

[v2,net-next] ice: Fix signedness bug in ice_init_interrupt_scheme()

Message ID b16e4f01-4c85-46e2-b602-fce529293559@stanley.mountain (mailing list archive)
State Accepted
Commit c2ddb619fa8d535af968965181656c20a6de3f81
Delegated to: Netdev Maintainers
Headers show
Series [v2,net-next] ice: Fix signedness bug in ice_init_interrupt_scheme() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 11 of 11 maintainers
netdev/build_clang success Errors and warnings before: 2 this patch: 2
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: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 4 this patch: 4
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-15--03-00 (tests: 891)

Commit Message

Dan Carpenter Feb. 13, 2025, 6:31 a.m. UTC
If pci_alloc_irq_vectors() can't allocate the minimum number of vectors
then it returns -ENOSPC so there is no need to check for that in the
caller.  In fact, because pf->msix.min is an unsigned int, it means that
any negative error codes are type promoted to high positive values and
treated as success.  So here, the "return -ENOMEM;" is unreachable code.
Check for negatives instead.

Now that we're only dealing with error codes, it's easier to propagate
the error code from pci_alloc_irq_vectors() instead of hardcoding
-ENOMEM.

Fixes: 79d97b8cf9a8 ("ice: remove splitting MSI-X between features")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
v2: Fix my scripts to say [PATCH net-next]
    Propagate the error code.

 drivers/net/ethernet/intel/ice/ice_irq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Michal Swiatkowski Feb. 13, 2025, 6:55 a.m. UTC | #1
On Thu, Feb 13, 2025 at 09:31:41AM +0300, Dan Carpenter wrote:
> If pci_alloc_irq_vectors() can't allocate the minimum number of vectors
> then it returns -ENOSPC so there is no need to check for that in the
> caller.  In fact, because pf->msix.min is an unsigned int, it means that
> any negative error codes are type promoted to high positive values and
> treated as success.  So here, the "return -ENOMEM;" is unreachable code.
> Check for negatives instead.
> 
> Now that we're only dealing with error codes, it's easier to propagate
> the error code from pci_alloc_irq_vectors() instead of hardcoding
> -ENOMEM.
> 
> Fixes: 79d97b8cf9a8 ("ice: remove splitting MSI-X between features")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> v2: Fix my scripts to say [PATCH net-next]
>     Propagate the error code.
> 
>  drivers/net/ethernet/intel/ice/ice_irq.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_irq.c b/drivers/net/ethernet/intel/ice/ice_irq.c
> index cbae3d81f0f1..30801fd375f0 100644
> --- a/drivers/net/ethernet/intel/ice/ice_irq.c
> +++ b/drivers/net/ethernet/intel/ice/ice_irq.c
> @@ -149,8 +149,8 @@ int ice_init_interrupt_scheme(struct ice_pf *pf)
>  
>  	vectors = pci_alloc_irq_vectors(pf->pdev, pf->msix.min, vectors,
>  					PCI_IRQ_MSIX);
> -	if (vectors < pf->msix.min)
> -		return -ENOMEM;
> +	if (vectors < 0)
> +		return vectors;
>  
>  	ice_init_irq_tracker(pf, pf->msix.max, vectors);
>  

Thanks,
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

> -- 
> 2.47.2
>
patchwork-bot+netdevbpf@kernel.org Feb. 15, 2025, 3:50 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 13 Feb 2025 09:31:41 +0300 you wrote:
> If pci_alloc_irq_vectors() can't allocate the minimum number of vectors
> then it returns -ENOSPC so there is no need to check for that in the
> caller.  In fact, because pf->msix.min is an unsigned int, it means that
> any negative error codes are type promoted to high positive values and
> treated as success.  So here, the "return -ENOMEM;" is unreachable code.
> Check for negatives instead.
> 
> [...]

Here is the summary with links:
  - [v2,net-next] ice: Fix signedness bug in ice_init_interrupt_scheme()
    https://git.kernel.org/netdev/net-next/c/c2ddb619fa8d

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/ice/ice_irq.c b/drivers/net/ethernet/intel/ice/ice_irq.c
index cbae3d81f0f1..30801fd375f0 100644
--- a/drivers/net/ethernet/intel/ice/ice_irq.c
+++ b/drivers/net/ethernet/intel/ice/ice_irq.c
@@ -149,8 +149,8 @@  int ice_init_interrupt_scheme(struct ice_pf *pf)
 
 	vectors = pci_alloc_irq_vectors(pf->pdev, pf->msix.min, vectors,
 					PCI_IRQ_MSIX);
-	if (vectors < pf->msix.min)
-		return -ENOMEM;
+	if (vectors < 0)
+		return vectors;
 
 	ice_init_irq_tracker(pf, pf->msix.max, vectors);