The Rx interrupt enable and disable callbacks store the result of
`rte_intr_vec_list_index_get()` in a `uint16_t`. If the lookup fails,
the negative error code becomes a large vector index, and the driver
writes to the wrong register instead of reporting the failure.

Keep the result signed and return the lookup error before accessing
the hardware.

Fixes: d61138d4f0e2 ("drivers: remove direct access to interrupt handle")
Cc: [email protected]

Signed-off-by: Bruce Richardson <[email protected]>
---
 drivers/net/intel/i40e/i40e_ethdev.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/intel/i40e/i40e_ethdev.c 
b/drivers/net/intel/i40e/i40e_ethdev.c
index 5ea26c3348..0f3295fb3c 100644
--- a/drivers/net/intel/i40e/i40e_ethdev.c
+++ b/drivers/net/intel/i40e/i40e_ethdev.c
@@ -10346,9 +10346,11 @@ i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, 
uint16_t queue_id)
        struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
        struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       uint16_t msix_intr;
+       const int msix_intr = rte_intr_vec_list_index_get(intr_handle, 
queue_id);
+
+       if (msix_intr < 0)
+               return msix_intr;
 
-       msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
        if (msix_intr == I40E_MISC_VEC_ID)
                I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
                               I40E_PFINT_DYN_CTL0_INTENA_MASK |
@@ -10374,9 +10376,11 @@ i40e_dev_rx_queue_intr_disable(struct rte_eth_dev 
*dev, uint16_t queue_id)
        struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
        struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       uint16_t msix_intr;
+       const int msix_intr = rte_intr_vec_list_index_get(intr_handle, 
queue_id);
+
+       if (msix_intr < 0)
+               return msix_intr;
 
-       msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
        if (msix_intr == I40E_MISC_VEC_ID)
                I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
                               I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
-- 
2.55.0

Reply via email to