drm: Prevent sign extension on hdisplay and vdisplay
Subsystems (2)
PATCH 1/1 drm: Prevent sign extension on hdisplay and vdisplay
Some functions in drm multiply hdisplay and vdisplay with a third factor, which can result in a sign extension according to static analysis due to an implicit s32 promotion. Use a cast to u32 to prevent this.
Suggested-by Rodrigo Vivi <[email protected]>
Signed-off-by Krzystof Karas <[email protected]>
Signed-off-by Jonathan Cavitt <[email protected]>
Cc Matthew Auld <[email protected]>
Cc Himal Prasad Ghimiray <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Andi Shyti <[email protected]>
--- drivers/gpu/drm/drm_gem_vram_helper.c | 2 +- drivers/gpu/drm/drm_mipi_dbi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_vram_helper.c +1 -1
@@ -967,7 +967,7 @@ drm_vram_helper_mode_valid_internal(struct drm_device *dev, max_fbpages = (vmm->vram_size /2 ) >>PAGE_SHIFT ; - fbsize = mode->hdisplay * mode->vdisplay * max_bpp; + fbsize = (u32 )mode->hdisplay * mode->vdisplay * max_bpp; fbpages =DIV_ROUND_UP (fbsize,PAGE_SIZE );if (fbpages > max_fbpages)
drivers/gpu/drm/drm_mipi_dbi.c +1 -1
@@ -691,7 +691,7 @@ int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,const struct drm_simple_display_pipe_funcs *funcs, const struct drm_display_mode *mode, unsigned int rotation) { - size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16); + size_t bufsize = (u32)mode->vdisplay * mode->hdisplay * sizeof(u16); dbidev->drm.mode_config.preferred_depth =16 ;
Signature · 1 line
2.43.0
Quoted 37 lines · Jonathan Cavitt
Some functions in drm multiply hdisplay and vdisplay with a third factor, which can result in a sign extension according to static analysis due to an implicit s32 promotion. Use a cast to u32 to prevent this.
Suggested-by Rodrigo Vivi <[email protected]>Signed-off-by Krzystof Karas <[email protected]>Signed-off-by Jonathan Cavitt <[email protected]>Cc Matthew Auld <[email protected]>Cc Himal Prasad Ghimiray <[email protected]>Cc Matthew Brost <[email protected]>Cc Ville Syrjälä <[email protected]>Cc Jani Nikula <[email protected]>Cc Andi Shyti <[email protected]>--- drivers/gpu/drm/drm_gem_vram_helper.c | 2 +- drivers/gpu/drm/drm_mipi_dbi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_gem_vram_helper.c +1
-1@@ -967,7 +967,7 @@ drm_vram_helper_mode_valid_internal(struct drm_device *dev, max_fbpages = (vmm->vram_size /2 ) >>PAGE_SHIFT ; - fbsize = mode->hdisplay * mode->vdisplay * max_bpp; + fbsize = (u32 )mode->hdisplay * mode->vdisplay * max_bpp; fbpages =DIV_ROUND_UP (fbsize,PAGE_SIZE );if (fbpages > max_fbpages)drivers/gpu/drm/drm_mipi_dbi.c +0
-0
drivers/gpu/drm/drm_mipi_dbi.c int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev, · line 694
Quoted 5 lines
drivers/gpu/drm/drm_mipi_dbi.c +1
-1@@ -691,7 +691,7 @@ int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,const struct drm_simple_display_pipe_funcs *funcs, const struct drm_display_mode *mode, unsigned int rotation) { - size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16); + size_t bufsize = (u32)mode->vdisplay * mode->hdisplay * sizeof(u16);
Reviewed-by Rodrigo Vivi <[email protected]>
and pushed to drm-misc-next. No, I didn't considered to push it to -fixes because it is a theoretical case that doesn't occur with real world pixels size.
Quoted 6 lines
drivers/gpu/drm/drm_mipi_dbi.c +0
-0dbidev->drm.mode_config.preferred_depth =16 ;Signature · 1 line
2.43.0