[PATCH v2 1/3] drm: Tune up error message for incorrect plane/format combinations

Imre Deak imre.deak at intel.com
Thu May 12 15:28:16 UTC 2016


Returning 0 from these functions isn't ever valid. In many cases it can
also lead to a div-by-zero possibly at some later point in time, so make
sure we catch such errors as soon as possible via louder error
reporting.

v2:
- Print the same WARN whenever we check for the same condition (Ville)
- Don't change drm_fb_get_bpp_depth(), for non-RGB formats we return
  bpp=0, depth=0 normally. (Ville, Daniel)

CC: Dave Airlie <airlied at redhat.com>
CC: Ville Syrjälä <ville.syrjala at linux.intel.com>
CC: Daniel Vetter <daniel.vetter at ffwll.ch>
Signed-off-by: Imre Deak <imre.deak at intel.com>
---
 drivers/gpu/drm/drm_crtc.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 70f9c68..990a9de 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -5544,6 +5544,13 @@ int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
 	return dev->driver->dumb_destroy(file_priv, dev, args->handle);
 }
 
+static bool check_format_plane_valid(uint32_t format, int plane)
+{
+	return !WARN(plane >= drm_format_num_planes(format),
+		     "invalid plane %d for format %s\n",
+		     plane, drm_get_format_name(format));
+}
+
 /**
  * drm_fb_get_bpp_depth - get the bpp/depth values for format
  * @format: pixel format (DRM_FORMAT_*)
@@ -5666,7 +5673,7 @@ int drm_format_plane_cpp(uint32_t format, int plane)
 	unsigned int depth;
 	int bpp;
 
-	if (plane >= drm_format_num_planes(format))
+	if (!check_format_plane_valid(format, plane))
 		return 0;
 
 	switch (format) {
@@ -5771,7 +5778,7 @@ EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
  */
 int drm_format_plane_width(int width, uint32_t format, int plane)
 {
-	if (plane >= drm_format_num_planes(format))
+	if (!check_format_plane_valid(format, plane))
 		return 0;
 
 	if (plane == 0)
@@ -5792,7 +5799,7 @@ EXPORT_SYMBOL(drm_format_plane_width);
  */
 int drm_format_plane_height(int height, uint32_t format, int plane)
 {
-	if (plane >= drm_format_num_planes(format))
+	if (!check_format_plane_valid(format, plane))
 		return 0;
 
 	if (plane == 0)
-- 
2.5.0



More information about the dri-devel mailing list