[PATCH] drm: make drm_get_format_name atomic/irq safe again

Rob Clark robdclark at gmail.com
Fri Nov 4 15:45:45 UTC 2016


On Fri, Nov 4, 2016 at 11:32 AM, Rob Clark <robdclark at gmail.com> wrote:
> Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07
>
>     drm: make drm_get_format_name thread-safe
>
>     Signed-off-by: Eric Engestrom <eric at engestrom.ch>
>     [danvet: Clarify that the returned pointer must be freed with
>     kfree().]
>     Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
>
> Note: I think we need to be a bit careful about follow-up audits of
> callers of this..  now that you need to kfree the return value I think
> it is fairly easy for new patches to introduce new callers which leak
> the return value.  We probably should have left the function as-is and
> introduce a new variant, or something like that.

btw, the new kfree the result approach moves the snprintf stuff
outside the 'if (drm_debug & FOO)' check.. which is perhaps also a bit
unfortunate..

I wonder how much the rest of the kernel would hate it if we pimped
out vsprintf.c to give us a special fmt string for fourcc formats?  I
guess it would also be useful for v4l..

It's too bad the kernel doesn't have something like register_printf_function()..


BR,
-R

> Signed-off-by: Rob Clark <robdclark at gmail.com>
> ---
>  drivers/gpu/drm/drm_fourcc.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index cbb8b77..2be9ea8 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -87,7 +87,10 @@ EXPORT_SYMBOL(drm_mode_legacy_fb_format);
>   */
>  char *drm_get_format_name(uint32_t format)
>  {
> -       char *buf = kmalloc(32, GFP_KERNEL);
> +       char *buf = kmalloc(32, GFP_ATOMIC);
> +
> +       if (!buf)
> +               return NULL;
>
>         snprintf(buf, 32,
>                  "%c%c%c%c %s-endian (0x%08x)",
> --
> 2.7.4
>


More information about the dri-devel mailing list