Commit 333d2da5 authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Archit Taneja

drm: WARN when calling drm_format_info() for an unsupported format

The format helpers have historically treated unsupported formats as part
of the default case, returning values that are likely wrong. We can't
change this behaviour now without risking breaking drivers in difficult
to detect ways, but we can WARN on unsupported formats to catch faulty
callers.

The only exception is the framebuffer_check() function that calls
drm_format_info() to validate the format passed from userspace. This is
a valid use case that shouldn't generate a warning.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: default avatarTomi Valkeinen <tomi.valkeinen@ti.com>
Signed-off-by: default avatarArchit Taneja <architt@codeaurora.org>
Link: http://patchwork.freedesktop.org/patch/msgid/1476744081-24485-5-git-send-email-laurent.pinchart@ideasonboard.com
parent d5493490
...@@ -102,15 +102,11 @@ char *drm_get_format_name(uint32_t format) ...@@ -102,15 +102,11 @@ char *drm_get_format_name(uint32_t format)
} }
EXPORT_SYMBOL(drm_get_format_name); EXPORT_SYMBOL(drm_get_format_name);
/** /*
* drm_format_info - query information for a given format * Internal function to query information for a given format. See
* @format: pixel format (DRM_FORMAT_*) * drm_format_info() for the public API.
*
* Returns:
* The instance of struct drm_format_info that describes the pixel format, or
* NULL if the format is unsupported.
*/ */
const struct drm_format_info *drm_format_info(u32 format) const struct drm_format_info *__drm_format_info(u32 format)
{ {
static const struct drm_format_info formats[] = { static const struct drm_format_info formats[] = {
{ .format = DRM_FORMAT_C8, .depth = 8, .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 }, { .format = DRM_FORMAT_C8, .depth = 8, .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
...@@ -184,6 +180,26 @@ const struct drm_format_info *drm_format_info(u32 format) ...@@ -184,6 +180,26 @@ const struct drm_format_info *drm_format_info(u32 format)
return NULL; return NULL;
} }
/**
* drm_format_info - query information for a given format
* @format: pixel format (DRM_FORMAT_*)
*
* The caller should only pass a supported pixel format to this function.
* Unsupported pixel formats will generate a warning in the kernel log.
*
* Returns:
* The instance of struct drm_format_info that describes the pixel format, or
* NULL if the format is unsupported.
*/
const struct drm_format_info *drm_format_info(u32 format)
{
const struct drm_format_info *info;
info = __drm_format_info(format);
WARN_ON(!info);
return info;
}
EXPORT_SYMBOL(drm_format_info); EXPORT_SYMBOL(drm_format_info);
/** /**
......
...@@ -131,7 +131,7 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r) ...@@ -131,7 +131,7 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
const struct drm_format_info *info; const struct drm_format_info *info;
int i; int i;
info = drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN); info = __drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN);
if (!info) { if (!info) {
char *format_name = drm_get_format_name(r->pixel_format); char *format_name = drm_get_format_name(r->pixel_format);
DRM_DEBUG_KMS("bad framebuffer format %s\n", format_name); DRM_DEBUG_KMS("bad framebuffer format %s\n", format_name);
......
...@@ -45,6 +45,7 @@ struct drm_format_info { ...@@ -45,6 +45,7 @@ struct drm_format_info {
u8 vsub; u8 vsub;
}; };
const struct drm_format_info *__drm_format_info(u32 format);
const struct drm_format_info *drm_format_info(u32 format); const struct drm_format_info *drm_format_info(u32 format);
uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp); void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
......
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