]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 09:08:23 +0000 (10:08 +0100)
[ Upstream commit f763946aefe67b3ea58696b75a930ba1ed886a83 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/misc/habanalabs/gaudi/gaudi.c
drivers/misc/habanalabs/goya/goya.c

index ca183733847b6eb8f24de6785e7119907467d78e..bcc45bf7af2c8fad7b5d568867c08d36f66c5142 100644 (file)
@@ -6285,7 +6285,7 @@ static bool gaudi_is_device_idle(struct hl_device *hdev, u32 *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,
@@ -6308,7 +6308,8 @@ static bool gaudi_is_device_idle(struct hl_device *hdev, u32 *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",
@@ -6336,7 +6337,8 @@ static bool gaudi_is_device_idle(struct hl_device *hdev, u32 *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 c179085ced7b89902121d25b22ec955fc7475035..a8041a39fae3136f8395a7da7f375f580dbc5907 100644 (file)
@@ -5098,7 +5098,8 @@ static bool goya_is_device_idle(struct hl_device *hdev, u32 *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);
@@ -5121,7 +5122,8 @@ static bool goya_is_device_idle(struct hl_device *hdev, u32 *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);
@@ -5141,7 +5143,7 @@ static bool goya_is_device_idle(struct hl_device *hdev, u32 *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);