From: Eric Engestrom <eric.engestrom@imgtec.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v5 04/13] drm: WARN when calling drm_format_info() for an unsupported format
Date: Tue, 18 Oct 2016 16:14:27 +0100 [thread overview]
Message-ID: <20161018151426.GE3759@imgtec.com> (raw)
In-Reply-To: <1476744081-24485-5-git-send-email-laurent.pinchart@ideasonboard.com>
On Tuesday, 2016-10-18 01:41:12 +0300, Laurent Pinchart wrote:
> 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: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
> ---
> drivers/gpu/drm/drm_fourcc.c | 32 ++++++++++++++++++++++++--------
> drivers/gpu/drm/drm_framebuffer.c | 2 +-
> include/drm/drm_fourcc.h | 1 +
> 3 files changed, 26 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index 23d4b82ec17c..523ed916a1c0 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -102,15 +102,11 @@ char *drm_get_format_name(uint32_t format)
> }
> EXPORT_SYMBOL(drm_get_format_name);
>
> -/**
> - * drm_format_info - query information for a given format
> - * @format: pixel format (DRM_FORMAT_*)
> - *
> - * Returns:
> - * The instance of struct drm_format_info that describes the pixel format, or
> - * NULL if the format is unsupported.
> +/*
> + * Internal function to query information for a given format. See
> + * drm_format_info() for the public API.
> */
> -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[] = {
> { .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)
>
> 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);
>
> /**
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 386977df72ce..49fd7db758e0 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -131,7 +131,7 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
> const struct drm_format_info *info;
> 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) {
> char *format_name = drm_get_format_name(r->pixel_format);
> DRM_DEBUG_KMS("bad framebuffer format %s\n", format_name);
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index 135fef050ee6..f73f97afd1e2 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -45,6 +45,7 @@ struct drm_format_info {
> u8 vsub;
> };
>
> +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);
> void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
> --
> Regards,
>
> Laurent Pinchart
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2016-10-18 15:14 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-17 22:41 [PATCH v5 00/13] Centralize format information Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 01/13] drm: " Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 02/13] drm: Implement the drm_format_*() helpers as drm_format_info() wrappers Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 03/13] drm: Use drm_format_info() in DRM core code Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 04/13] drm: WARN when calling drm_format_info() for an unsupported format Laurent Pinchart
2016-10-18 15:14 ` Eric Engestrom [this message]
2016-10-17 22:41 ` [PATCH v5 05/13] drm: hdlcd: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp() Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 06/13] drm: tilcdc: " Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 07/13] drm: cirrus: " Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 08/13] drm: gma500: Replace drm_fb_get_bpp_depth() with drm_format_info() Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 09/13] drm: amdgpu: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp() Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 10/13] drm: radeon: " Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 11/13] drm: vmwgfx: Replace drm_fb_get_bpp_depth() with drm_format_info() Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 12/13] drm/arm: mali-dp: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp() Laurent Pinchart
2016-10-17 22:41 ` [PATCH v5 13/13] drm: Don't export the drm_fb_get_bpp_depth() function Laurent Pinchart
2016-10-18 15:14 ` Eric Engestrom
2016-10-18 10:33 ` [PATCH v5 00/13] Centralize format information Archit Taneja
2016-10-18 11:43 ` Ville Syrjälä
2016-10-18 12:33 ` Laurent Pinchart
2016-10-18 12:45 ` Ville Syrjälä
2016-10-18 12:49 ` Laurent Pinchart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161018151426.GE3759@imgtec.com \
--to=eric.engestrom@imgtec.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=tomi.valkeinen@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox