]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
habanalabs: cast to u64 before shift > 31 bits
authorOded Gabbay <oded.gabbay@gmail.com>
Sat, 29 Aug 2020 08:24:03 +0000 (11:24 +0300)
committerOded Gabbay <oded.gabbay@gmail.com>
Tue, 22 Sep 2020 15:49:51 +0000 (18:49 +0300)
When shifting a boolean variable by more than 31 bits and putting the
result into a u64 variable, we need to cast the boolean into unsigned 64
bits to prevent possible overflow.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
drivers/misc/habanalabs/gaudi/gaudi.c
drivers/misc/habanalabs/goya/goya.c

index 076a7697f85dadc175a29a3b1b061bfe59adbf06..084019788e11fe5f9cf5dc21b6381cd17e5f3098 100644 (file)
@@ -6114,7 +6114,7 @@ static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask,
                is_idle &= is_eng_idle;
 
                if (mask)
-                       *mask |= !is_eng_idle <<
+                       *mask |= ((u64) !is_eng_idle) <<
                                        (GAUDI_ENGINE_ID_DMA_0 + dma_id);
                if (s)
                        seq_printf(s, fmt, dma_id,
@@ -6137,7 +6137,8 @@ static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask,
                is_idle &= is_eng_idle;
 
                if (mask)
-                       *mask |= !is_eng_idle << (GAUDI_ENGINE_ID_TPC_0 + i);
+                       *mask |= ((u64) !is_eng_idle) <<
+                                               (GAUDI_ENGINE_ID_TPC_0 + i);
                if (s)
                        seq_printf(s, fmt, i,
                                is_eng_idle ? "Y" : "N",
@@ -6165,7 +6166,8 @@ static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask,
                is_idle &= is_eng_idle;
 
                if (mask)
-                       *mask |= !is_eng_idle << (GAUDI_ENGINE_ID_MME_0 + i);
+                       *mask |= ((u64) !is_eng_idle) <<
+                                               (GAUDI_ENGINE_ID_MME_0 + i);
                if (s) {
                        if (!is_slave)
                                seq_printf(s, fmt, i,
index c41f2917863bbc2bff15b1e5ce4346ff9433e97c..88847eb1b47244df02859ac3b197f534eb266093 100644 (file)
@@ -5173,7 +5173,8 @@ static bool goya_is_device_idle(struct hl_device *hdev, u64 *mask,
                is_idle &= is_eng_idle;
 
                if (mask)
-                       *mask |= !is_eng_idle << (GOYA_ENGINE_ID_DMA_0 + i);
+                       *mask |= ((u64) !is_eng_idle) <<
+                                               (GOYA_ENGINE_ID_DMA_0 + i);
                if (s)
                        seq_printf(s, dma_fmt, i, is_eng_idle ? "Y" : "N",
                                        qm_glbl_sts0, dma_core_sts0);
@@ -5196,7 +5197,8 @@ static bool goya_is_device_idle(struct hl_device *hdev, u64 *mask,
                is_idle &= is_eng_idle;
 
                if (mask)
-                       *mask |= !is_eng_idle << (GOYA_ENGINE_ID_TPC_0 + i);
+                       *mask |= ((u64) !is_eng_idle) <<
+                                               (GOYA_ENGINE_ID_TPC_0 + i);
                if (s)
                        seq_printf(s, fmt, i, is_eng_idle ? "Y" : "N",
                                qm_glbl_sts0, cmdq_glbl_sts0, tpc_cfg_sts);
@@ -5216,7 +5218,7 @@ static bool goya_is_device_idle(struct hl_device *hdev, u64 *mask,
        is_idle &= is_eng_idle;
 
        if (mask)
-               *mask |= !is_eng_idle << GOYA_ENGINE_ID_MME_0;
+               *mask |= ((u64) !is_eng_idle) << GOYA_ENGINE_ID_MME_0;
        if (s) {
                seq_printf(s, fmt, 0, is_eng_idle ? "Y" : "N", qm_glbl_sts0,
                                cmdq_glbl_sts0, mme_arch_sts);