drm: make drm_get_format_name thread-safe

Signed-off-by: Eric Engestrom <eric@engestrom.ch>
[danvet: Clarify that the returned pointer must be freed with
kfree().]
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Eric Engestrom
2016-08-15 01:02:38 +01:00
committed by Daniel Vetter
parent fc93ff608b
commit 90844f0004
12 changed files with 89 additions and 48 deletions

View File

@@ -39,16 +39,14 @@ static char printable_char(int c)
* drm_get_format_name - return a string for drm fourcc format
* @format: format to compute name of
*
* Note that the buffer used by this function is globally shared and owned by
* the function itself.
*
* FIXME: This isn't really multithreading safe.
* Note that the buffer returned by this function is owned by the caller
* and will need to be freed using kfree().
*/
const char *drm_get_format_name(uint32_t format)
{
static char buf[32];
char *buf = kmalloc(32, GFP_KERNEL);
snprintf(buf, sizeof(buf),
snprintf(buf, 32,
"%c%c%c%c %s-endian (0x%08x)",
printable_char(format & 0xff),
printable_char((format >> 8) & 0xff),
@@ -73,6 +71,8 @@ EXPORT_SYMBOL(drm_get_format_name);
void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
int *bpp)
{
const char *format_name;
switch (format) {
case DRM_FORMAT_C8:
case DRM_FORMAT_RGB332:
@@ -127,8 +127,9 @@ void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
*bpp = 32;
break;
default:
DRM_DEBUG_KMS("unsupported pixel format %s\n",
drm_get_format_name(format));
format_name = drm_get_format_name(format);
DRM_DEBUG_KMS("unsupported pixel format %s\n", format_name);
kfree(format_name);
*depth = 0;
*bpp = 0;
break;