]> git.baikalelectronics.ru Git - kernel.git/commitdiff
habanalabs/gaudi: fix shift out of bounds
authorOfir Bitton <obitton@habana.ai>
Wed, 15 Jun 2022 13:11:31 +0000 (16:11 +0300)
committerOded Gabbay <ogabbay@kernel.org>
Tue, 12 Jul 2022 06:09:23 +0000 (09:09 +0300)
When validating NIC queues, queue offset calculation must be
performed only for NIC queues.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/misc/habanalabs/gaudi/gaudi.c

index 8b9ff7fa51ea67bd3116d4e81882c209a581a712..31e702846f7a63c5ccd23f8169706ba5fc12e737 100644 (file)
@@ -5692,15 +5692,17 @@ static int gaudi_parse_cb_no_ext_queue(struct hl_device *hdev,
 {
        struct asic_fixed_properties *asic_prop = &hdev->asic_prop;
        struct gaudi_device *gaudi = hdev->asic_specific;
-       u32 nic_mask_q_id = 1 << (HW_CAP_NIC_SHIFT +
-               ((parser->hw_queue_id - GAUDI_QUEUE_ID_NIC_0_0) >> 2));
+       u32 nic_queue_offset, nic_mask_q_id;
 
        if ((parser->hw_queue_id >= GAUDI_QUEUE_ID_NIC_0_0) &&
-                       (parser->hw_queue_id <= GAUDI_QUEUE_ID_NIC_9_3) &&
-                       (!(gaudi->hw_cap_initialized & nic_mask_q_id))) {
-               dev_err(hdev->dev, "h/w queue %d is disabled\n",
-                               parser->hw_queue_id);
-               return -EINVAL;
+                       (parser->hw_queue_id <= GAUDI_QUEUE_ID_NIC_9_3)) {
+               nic_queue_offset = parser->hw_queue_id - GAUDI_QUEUE_ID_NIC_0_0;
+               nic_mask_q_id = 1 << (HW_CAP_NIC_SHIFT + (nic_queue_offset >> 2));
+
+               if (!(gaudi->hw_cap_initialized & nic_mask_q_id)) {
+                       dev_err(hdev->dev, "h/w queue %d is disabled\n", parser->hw_queue_id);
+                       return -EINVAL;
+               }
        }
 
        /* For internal queue jobs just check if CB address is valid */