Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3c11ac2 authored by Eric Engestrom's avatar Eric Engestrom Committed by Daniel Vetter
Browse files

drm: move allocation out of drm_get_format_name()



The function's behaviour was changed in 90844f00, without changing
its signature, causing people to keep using it the old way without
realising they were now leaking memory.
Rob Clark also noticed it was also allocating GFP_KERNEL memory in
atomic contexts, breaking them.

Instead of having to allocate GFP_ATOMIC memory and fixing the callers
to make them cleanup the memory afterwards, let's change the function's
signature by having the caller take care of the memory and passing it to
the function.
The new parameter is a single-field struct in order to enforce the size
of its buffer and help callers to correctly manage their memory.

Fixes: 90844f00 ("drm: make drm_get_format_name thread-safe")
Cc: Rob Clark <robdclark@gmail.com>
Cc: Christian König <christian.koenig@amd.com>
Acked-by: default avatarChristian König <christian.koenig@amd.com>
Acked-by: default avatarRob Clark <robdclark@gmail.com>
Acked-by: Sinclair Yeh <syeh@vmware.com> (vmwgfx)
Reviewed-by: default avatarJani Nikula <jani.nikula@intel.com>
Suggested-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: default avatarEric Engestrom <eric@engestrom.ch>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20161112011309.9799-1-eric@engestrom.ch
parent f92e1ee5
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -2032,7 +2032,7 @@ static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc,
	u32 tmp, viewport_w, viewport_h;
	int r;
	bool bypass_lut = false;
	char *format_name;
	struct drm_format_name_buf format_name;

	/* no fb bound */
	if (!atomic && !crtc->primary->fb) {
@@ -2144,9 +2144,8 @@ static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc,
		bypass_lut = true;
		break;
	default:
		format_name = drm_get_format_name(target_fb->pixel_format);
		DRM_ERROR("Unsupported screen format %s\n", format_name);
		kfree(format_name);
		DRM_ERROR("Unsupported screen format %s\n",
		          drm_get_format_name(target_fb->pixel_format, &format_name));
		return -EINVAL;
	}

+3 −4
Original line number Diff line number Diff line
@@ -2013,7 +2013,7 @@ static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc,
	u32 tmp, viewport_w, viewport_h;
	int r;
	bool bypass_lut = false;
	char *format_name;
	struct drm_format_name_buf format_name;

	/* no fb bound */
	if (!atomic && !crtc->primary->fb) {
@@ -2125,9 +2125,8 @@ static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc,
		bypass_lut = true;
		break;
	default:
		format_name = drm_get_format_name(target_fb->pixel_format);
		DRM_ERROR("Unsupported screen format %s\n", format_name);
		kfree(format_name);
		DRM_ERROR("Unsupported screen format %s\n",
		          drm_get_format_name(target_fb->pixel_format, &format_name));
		return -EINVAL;
	}

+2 −1
Original line number Diff line number Diff line
@@ -1456,6 +1456,7 @@ static int dce_v6_0_crtc_do_set_base(struct drm_crtc *crtc,
	u32 viewport_w, viewport_h;
	int r;
	bool bypass_lut = false;
	struct drm_format_name_buf format_name;

	/* no fb bound */
	if (!atomic && !crtc->primary->fb) {
@@ -1559,7 +1560,7 @@ static int dce_v6_0_crtc_do_set_base(struct drm_crtc *crtc,
		break;
	default:
		DRM_ERROR("Unsupported screen format %s\n",
			  drm_get_format_name(target_fb->pixel_format));
		          drm_get_format_name(target_fb->pixel_format, &format_name));
		return -EINVAL;
	}

+3 −4
Original line number Diff line number Diff line
@@ -1910,7 +1910,7 @@ static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
	u32 viewport_w, viewport_h;
	int r;
	bool bypass_lut = false;
	char *format_name;
	struct drm_format_name_buf format_name;

	/* no fb bound */
	if (!atomic && !crtc->primary->fb) {
@@ -2015,9 +2015,8 @@ static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
		bypass_lut = true;
		break;
	default:
		format_name = drm_get_format_name(target_fb->pixel_format);
		DRM_ERROR("Unsupported screen format %s\n", format_name);
		kfree(format_name);
		DRM_ERROR("Unsupported screen format %s\n",
		          drm_get_format_name(target_fb->pixel_format, &format_name));
		return -EINVAL;
	}

+6 −4
Original line number Diff line number Diff line
@@ -861,9 +861,10 @@ static int drm_atomic_plane_check(struct drm_plane *plane,
	/* Check whether this plane supports the fb pixel format. */
	ret = drm_plane_check_pixel_format(plane, state->fb->pixel_format);
	if (ret) {
		char *format_name = drm_get_format_name(state->fb->pixel_format);
		DRM_DEBUG_ATOMIC("Invalid pixel format %s\n", format_name);
		kfree(format_name);
		struct drm_format_name_buf format_name;
		DRM_DEBUG_ATOMIC("Invalid pixel format %s\n",
		                 drm_get_format_name(state->fb->pixel_format,
		                                     &format_name));
		return ret;
	}

@@ -917,9 +918,10 @@ static void drm_atomic_plane_print_state(struct drm_printer *p,
	if (state->fb) {
		struct drm_framebuffer *fb = state->fb;
		int i, n = drm_format_num_planes(fb->pixel_format);
		struct drm_format_name_buf format_name;

		drm_printf(p, "\t\tformat=%s\n",
				drm_get_format_name(fb->pixel_format));
		              drm_get_format_name(fb->pixel_format, &format_name));
		drm_printf(p, "\t\tsize=%dx%d\n", fb->width, fb->height);
		drm_printf(p, "\t\tlayers:\n");
		for (i = 0; i < n; i++) {
Loading