* [PATCH] drm: Prevent sign extension on hdisplay and vdisplay
@ 2025-10-07 15:36 Jonathan Cavitt
2025-10-09 14:44 ` Rodrigo Vivi
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Cavitt @ 2025-10-07 15:36 UTC (permalink / raw)
To: dri-devel
Cc: saurabhg.gupta, alex.zuo, jonathan.cavitt, matthew.auld,
himal.prasad.ghimiray, matthew.brost, ville.syrjala, jani.nikula,
rodrigo.vivi, krzysztof.karas, andi.shyti
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 <rodrigo.vivi@intel.com>
Signed-off-by: Krzystof Karas <krzysztof.karas@intel.com>
Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Andi Shyti <andi.shyti@intel.com>
---
drivers/gpu/drm/drm_gem_vram_helper.c | 2 +-
drivers/gpu/drm/drm_mipi_dbi.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index 90760d0ca071..0bec6f66682b 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -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)
diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c
index e33c78fc8fbd..b488c91c20a5 100644
--- a/drivers/gpu/drm/drm_mipi_dbi.c
+++ b/drivers/gpu/drm/drm_mipi_dbi.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] drm: Prevent sign extension on hdisplay and vdisplay
2025-10-07 15:36 [PATCH] drm: Prevent sign extension on hdisplay and vdisplay Jonathan Cavitt
@ 2025-10-09 14:44 ` Rodrigo Vivi
0 siblings, 0 replies; 2+ messages in thread
From: Rodrigo Vivi @ 2025-10-09 14:44 UTC (permalink / raw)
To: Jonathan Cavitt
Cc: dri-devel, saurabhg.gupta, alex.zuo, matthew.auld,
himal.prasad.ghimiray, matthew.brost, ville.syrjala, jani.nikula,
krzysztof.karas, andi.shyti
On Tue, Oct 07, 2025 at 03:36:46PM +0000, Jonathan Cavitt wrote:
> 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 <rodrigo.vivi@intel.com>
> Signed-off-by: Krzystof Karas <krzysztof.karas@intel.com>
> Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Andi Shyti <andi.shyti@intel.com>
> ---
> drivers/gpu/drm/drm_gem_vram_helper.c | 2 +-
> drivers/gpu/drm/drm_mipi_dbi.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
> index 90760d0ca071..0bec6f66682b 100644
> --- a/drivers/gpu/drm/drm_gem_vram_helper.c
> +++ b/drivers/gpu/drm/drm_gem_vram_helper.c
> @@ -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)
> diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c
> index e33c78fc8fbd..b488c91c20a5 100644
> --- a/drivers/gpu/drm/drm_mipi_dbi.c
> +++ b/drivers/gpu/drm/drm_mipi_dbi.c
> @@ -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 <rodrigo.vivi@intel.com>
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.
>
> dbidev->drm.mode_config.preferred_depth = 16;
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-09 14:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-07 15:36 [PATCH] drm: Prevent sign extension on hdisplay and vdisplay Jonathan Cavitt
2025-10-09 14:44 ` Rodrigo Vivi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.