Commit 4760be48 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Dmitry Baryshkov

drm/msm/dpu: Fix bit-shifting UB in DPU_HW_VER() macro

With gcc-5 and CONFIG_UBSAN_SHIFT=y:

    drivers/gpu/drm/msm/msm_mdss.c: In function 'msm_mdss_enable':
    drivers/gpu/drm/msm/msm_mdss.c:296:2: error: case label does not reduce to an integer constant
      case DPU_HW_VER_800:
      ^
    drivers/gpu/drm/msm/msm_mdss.c:299:2: error: case label does not reduce to an integer constant
      case DPU_HW_VER_810:
      ^
    drivers/gpu/drm/msm/msm_mdss.c:300:2: error: case label does not reduce to an integer constant
      case DPU_HW_VER_900:
      ^

This happens because for major revisions 8 or greather, the non-sign bit
of the major revision number is shifted into bit 31 of a signed integer,
which is undefined behavior.

Fix this by casting the major revision number to unsigned int.

Fixes: efcd0107 ("drm/msm/dpu: add support for SM8550")
Fixes: 4a352c2f ("drm/msm/dpu: Introduce SC8280XP")
Fixes: 100d7ef6 ("drm/msm/dpu: add support for SM8450")
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Reviewed-by: default avatarRob Clark <robdclark@gmail.com>
Patchwork: https://patchwork.freedesktop.org/patch/525152/
Link: https://lore.kernel.org/r/20230306090633.65918-1-geert+renesas@glider.beSigned-off-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
parent 27cfd5d7
......@@ -19,8 +19,9 @@
*/
#define MAX_BLOCKS 12
#define DPU_HW_VER(MAJOR, MINOR, STEP) (((MAJOR & 0xF) << 28) |\
((MINOR & 0xFFF) << 16) |\
#define DPU_HW_VER(MAJOR, MINOR, STEP) \
((((unsigned int)MAJOR & 0xF) << 28) | \
((MINOR & 0xFFF) << 16) | \
(STEP & 0xFFFF))
#define DPU_HW_MAJOR(rev) ((rev) >> 28)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment