* [PATCH v2] drm: Add drm_mode_num_active_pixels helper function
@ 2025-10-01 16:29 Jonathan Cavitt
0 siblings, 0 replies; only message in thread
From: Jonathan Cavitt @ 2025-10-01 16:29 UTC (permalink / raw)
To: dri-devel
Cc: saurabhg.gupta, alex.zuo, jonathan.cavitt, matthew.auld,
himal.prasad.ghimiray, matthew.brost, ville.syrjala, jani.nikula
Add a helper function that computes the product of hdisplay and
vdisplay. This is necessary to prevent a potential sign extension
issue.
v2:
- Clarify purpose of helper function (Jonathan)
- s/drm_mode_display_size/drm_mode_num_active_pixels (Ville)
- Add kernel docs (Jani)
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>
---
drivers/gpu/drm/drm_gem_vram_helper.c | 2 +-
drivers/gpu/drm/drm_mipi_dbi.c | 2 +-
include/drm/drm_modes.h | 14 ++++++++++++++
3 files changed, 16 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..a345dc8caa3b 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 = drm_mode_num_active_pixels(mode) * 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..08da48bfff36 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 = drm_mode_num_active_pixels(mode) * sizeof(u16);
dbidev->drm.mode_config.preferred_depth = 16;
diff --git a/include/drm/drm_modes.h b/include/drm/drm_modes.h
index b9bb92e4b029..c0e8d6c4d43c 100644
--- a/include/drm/drm_modes.h
+++ b/include/drm/drm_modes.h
@@ -572,4 +572,18 @@ struct drm_display_mode *
drm_mode_create_from_cmdline_mode(struct drm_device *dev,
struct drm_cmdline_mode *cmd);
+/**
+ * drm_mode_num_active_pixels - Computes the number of pixels in the
+ * drm display mode
+ *
+ * @mode - The target drm_display_mode
+ *
+ * Returns the product of hdisplay and vdisplay
+ */
+static inline u32
+drm_mode_num_active_pixels(const struct drm_display_mode *mode)
+{
+ return mode->hdisplay * mode->vdisplay;
+}
+
#endif /* __DRM_MODES_H__ */
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-10-01 16:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-01 16:29 [PATCH v2] drm: Add drm_mode_num_active_pixels helper function Jonathan Cavitt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox