linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm: move allocation out of drm_get_format_name()
       [not found] <20161105012344.GA28349@engestrom.ch>
@ 2016-11-05  1:33 ` Eric Engestrom
  2016-11-05  6:56   ` Thomas Hellstrom
  2016-11-05 12:11   ` Christian König
  0 siblings, 2 replies; 28+ messages in thread
From: Eric Engestrom @ 2016-11-05  1:33 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ville Syrjälä,
	Eric Engestrom, Alex Deucher, Christian König, David Airlie,
	Xinliang Liu, Daniel Vetter, Jani Nikula, VMware Graphics,
	Sinclair Yeh, Thomas Hellstrom, Tom St Denis, Michel Dänzer,
	Gustavo Padovan, Emily Deng, Chunming Zhou, Flora Cui,
	Vitaly Prosyak, Ken Wang, Colin Ian King, Alexandre Demers,
	Junwei Zhang, Xinwei Kong, Chris Wilson, Laurent Pinchart,
	Wei Yongjun, dri-devel, intel-gfx

Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07

    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>

Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
---
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c          |  7 ++---
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c          |  7 ++---
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c           |  3 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c           |  7 ++---
 drivers/gpu/drm/drm_atomic.c                    |  7 +++--
 drivers/gpu/drm/drm_crtc.c                      |  7 +++--
 drivers/gpu/drm/drm_fourcc.c                    | 12 +++-----
 drivers/gpu/drm/drm_framebuffer.c               |  7 +++--
 drivers/gpu/drm/drm_modeset_helper.c            |  7 +++--
 drivers/gpu/drm/drm_plane.c                     |  7 +++--
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  7 ++---
 drivers/gpu/drm/i915/i915_debugfs.c             |  8 ++---
 drivers/gpu/drm/i915/intel_atomic_plane.c       |  8 ++---
 drivers/gpu/drm/i915/intel_display.c            | 41 ++++++++++---------------
 drivers/gpu/drm/radeon/atombios_crtc.c          | 14 ++++-----
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c             |  3 +-
 include/drm/drm_fourcc.h                        |  3 +-
 17 files changed, 71 insertions(+), 84 deletions(-)

diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index dc0aafa..5a8cb4b 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -54,6 +54,7 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
 int drm_format_vert_chroma_subsampling(uint32_t format);
 int drm_format_plane_width(int width, uint32_t format, int plane);
 int drm_format_plane_height(int height, uint32_t format, int plane);
-char *drm_get_format_name(uint32_t format) __malloc;
+typedef char drm_format_name_buf[32];
+char *drm_get_format_name(uint32_t format, drm_format_name_buf buf);
 
 #endif /* __DRM_FOURCC_H__ */
diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index cbb8b77..34ed520 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -79,17 +79,13 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
 EXPORT_SYMBOL(drm_mode_legacy_fb_format);
 
 /**
- * drm_get_format_name - return a string for drm fourcc format
+ * drm_get_format_name - fill a string with a drm fourcc format's name
  * @format: format to compute name of
+ * @buf: caller-supplied buffer
- *
- * Note that the buffer returned by this function is owned by the caller
- * and will need to be freed using kfree().
  */
-char *drm_get_format_name(uint32_t format)
+char *drm_get_format_name(uint32_t format, drm_format_name_buf buf)
 {
-	char *buf = kmalloc(32, GFP_KERNEL);
-
-	snprintf(buf, 32,
+	snprintf(buf, sizeof(drm_format_name_buf),
 		 "%c%c%c%c %s-endian (0x%08x)",
 		 printable_char(format & 0xff),
 		 printable_char((format >> 8) & 0xff),
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
index 199d3f7..cefa3d8 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
@@ -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;
+	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;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
index ecd000e..462abb8 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
@@ -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;
+	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;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
index 44547f9..3b8cea3 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
@@ -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;
+	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;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
index 979aedf..8c624b5 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
@@ -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;
+	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;
 	}
 
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index c32fb3c..8d2e6a5 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -835,9 +835,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);
+		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;
 	}
 
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 13441e2..7f5bbe3 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -827,9 +827,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
 			ret = drm_plane_check_pixel_format(crtc->primary,
 							   fb->pixel_format);
 			if (ret) {
-				char *format_name = drm_get_format_name(fb->pixel_format);
-				DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
-				kfree(format_name);
+				drm_format_name_buf format_name;
+				DRM_DEBUG_KMS("Invalid pixel format %s\n",
+				              drm_get_format_name(fb->pixel_format,
+				                                  format_name));
 				goto out;
 			}
 		}
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index 49fd7db..12ad188 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -133,9 +133,10 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
 
 	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);
-		kfree(format_name);
+		drm_format_name_buf format_name;
+		DRM_DEBUG_KMS("bad framebuffer format %s\n",
+		              drm_get_format_name(r->pixel_format,
+		                                  format_name));
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c
index 2544dfe..b6ab72a 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -75,10 +75,11 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
 
 	info = drm_format_info(mode_cmd->pixel_format);
 	if (!info || !info->depth) {
-		char *format_name = drm_get_format_name(mode_cmd->pixel_format);
+		drm_format_name_buf format_name;
 
-		DRM_DEBUG_KMS("non-RGB pixel format %s\n", format_name);
-		kfree(format_name);
+		DRM_DEBUG_KMS("non-RGB pixel format %s\n",
+		              drm_get_format_name(mode_cmd->pixel_format,
+		                                  format_name));
 
 		fb->depth = 0;
 		fb->bits_per_pixel = 0;
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 249c0ae..9a45c52 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -479,9 +479,10 @@ static int __setplane_internal(struct drm_plane *plane,
 	/* Check whether this plane supports the fb pixel format. */
 	ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
 	if (ret) {
-		char *format_name = drm_get_format_name(fb->pixel_format);
-		DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
-		kfree(format_name);
+		drm_format_name_buf format_name;
+		DRM_DEBUG_KMS("Invalid pixel format %s\n",
+		              drm_get_format_name(fb->pixel_format,
+		                                  format_name));
 		goto out;
 	}
 
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 7e7a4d4..c5c0b38 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -608,17 +608,16 @@ static void ade_rdma_set(void __iomem *base, struct drm_framebuffer *fb,
 			 u32 ch, u32 y, u32 in_h, u32 fmt)
 {
 	struct drm_gem_cma_object *obj = drm_fb_cma_get_gem_obj(fb, 0);
-	char *format_name;
+	drm_format_name_buf format_name;
 	u32 reg_ctrl, reg_addr, reg_size, reg_stride, reg_space, reg_en;
 	u32 stride = fb->pitches[0];
 	u32 addr = (u32)obj->paddr + y * stride;
 
 	DRM_DEBUG_DRIVER("rdma%d: (y=%d, height=%d), stride=%d, paddr=0x%x\n",
 			 ch + 1, y, in_h, stride, (u32)obj->paddr);
-	format_name = drm_get_format_name(fb->pixel_format);
 	DRM_DEBUG_DRIVER("addr=0x%x, fb:%dx%d, pixel_format=%d(%s)\n",
-			 addr, fb->width, fb->height, fmt, format_name);
+			 addr, fb->width, fb->height, fmt,
+			 drm_get_format_name(fb->pixel_format, format_name));
-	kfree(format_name);
 
 	/* get reg offset */
 	reg_ctrl = RD_CH_CTRL(ch);
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 20638d2..39f76b1 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -2971,7 +2971,7 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 	for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
 		struct drm_plane_state *state;
 		struct drm_plane *plane = &intel_plane->base;
-		char *format_name;
+		drm_format_name_buf format_name;
 
 		if (!plane->state) {
 			seq_puts(m, "plane->state is NULL!\n");
@@ -2981,9 +2981,9 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 		state = plane->state;
 
 		if (state->fb) {
-			format_name = drm_get_format_name(state->fb->pixel_format);
+			drm_get_format_name(state->fb->pixel_format, format_name);
 		} else {
-			format_name = kstrdup("N/A", GFP_KERNEL);
+			sprintf(format_name, "N/A");
 		}
 
 		seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
@@ -3001,8 +3001,6 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 			   ((state->src_h & 0xffff) * 15625) >> 10,
 			   format_name,
 			   plane_rotation(state->rotation));
-
-		kfree(format_name);
 	}
 }
 
diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c b/drivers/gpu/drm/i915/intel_atomic_plane.c
index c762ae5..289ebc9 100644
--- a/drivers/gpu/drm/i915/intel_atomic_plane.c
+++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
@@ -143,7 +143,7 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
 		crtc_state->base.enable ? crtc_state->pipe_src_h : 0;
 
 	if (state->fb && drm_rotation_90_or_270(state->rotation)) {
-		char *format_name;
+		drm_format_name_buf format_name;
 
 		if (!(state->fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
 			state->fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED)) {
@@ -159,9 +159,9 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
 		switch (state->fb->pixel_format) {
 		case DRM_FORMAT_C8:
 		case DRM_FORMAT_RGB565:
-			format_name = drm_get_format_name(state->fb->pixel_format);
-			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
+			              drm_get_format_name(state->fb->pixel_format,
+			                                  format_name));
 			return -EINVAL;
 
 		default:
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 6f8f6ec..ab0882f 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -12871,7 +12871,7 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 
 	DRM_DEBUG_KMS("planes on this crtc\n");
 	list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
-		char *format_name;
+		drm_format_name_buf format_name;
 		intel_plane = to_intel_plane(plane);
 		if (intel_plane->pipe != crtc->pipe)
 			continue;
@@ -12884,12 +12884,11 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 			continue;
 		}
 
-		format_name = drm_get_format_name(fb->pixel_format);
-
 		DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
 			      plane->base.id, plane->name);
 		DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
-			      fb->base.id, fb->width, fb->height, format_name);
+			      fb->base.id, fb->width, fb->height,
+			      drm_get_format_name(fb->pixel_format, format_name));
 		DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
 			      state->scaler_id,
 			      state->base.src.x1 >> 16,
@@ -12899,8 +12898,6 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 			      state->base.dst.x1, state->base.dst.y1,
 			      drm_rect_width(&state->base.dst),
 			      drm_rect_height(&state->base.dst));
-
-		kfree(format_name);
 	}
 }
 
@@ -15749,7 +15746,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	unsigned int tiling = i915_gem_object_get_tiling(obj);
 	int ret;
 	u32 pitch_limit, stride_alignment;
-	char *format_name;
+	drm_format_name_buf format_name;
 
 	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
 
@@ -15840,18 +15837,16 @@ static int intel_framebuffer_init(struct drm_device *dev,
 		break;
 	case DRM_FORMAT_XRGB1555:
 		if (INTEL_INFO(dev)->gen > 3) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, format_name));
 			return -EINVAL;
 		}
 		break;
 	case DRM_FORMAT_ABGR8888:
 		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
 		    INTEL_INFO(dev)->gen < 9) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, format_name));
 			return -EINVAL;
 		}
 		break;
@@ -15859,17 +15854,15 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	case DRM_FORMAT_XRGB2101010:
 	case DRM_FORMAT_XBGR2101010:
 		if (INTEL_INFO(dev)->gen < 4) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, format_name));
 			return -EINVAL;
 		}
 		break;
 	case DRM_FORMAT_ABGR2101010:
 		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, format_name));
 			return -EINVAL;
 		}
 		break;
@@ -15878,16 +15871,14 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	case DRM_FORMAT_YVYU:
 	case DRM_FORMAT_VYUY:
 		if (INTEL_INFO(dev)->gen < 5) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, format_name));
 			return -EINVAL;
 		}
 		break;
 	default:
-		format_name = drm_get_format_name(mode_cmd->pixel_format);
-		DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-		kfree(format_name);
+		DRM_DEBUG("unsupported pixel format: %s\n",
+		          drm_get_format_name(mode_cmd->pixel_format, format_name));
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index 74f99ba..adff13b 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -1156,7 +1156,7 @@ static int dce4_crtc_do_set_base(struct drm_crtc *crtc,
 	u32 tmp, viewport_w, viewport_h;
 	int r;
 	bool bypass_lut = false;
-	char *format_name;
+	drm_format_name_buf format_name;
 
 	/* no fb bound */
 	if (!atomic && !crtc->primary->fb) {
@@ -1260,9 +1260,8 @@ static int dce4_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;
 	}
 
@@ -1473,7 +1472,7 @@ static int avivo_crtc_do_set_base(struct drm_crtc *crtc,
 	u32 viewport_w, viewport_h;
 	int r;
 	bool bypass_lut = false;
-	char *format_name;
+	drm_format_name_buf format_name;
 
 	/* no fb bound */
 	if (!atomic && !crtc->primary->fb) {
@@ -1563,9 +1562,8 @@ static int avivo_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;
 	}
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index c965514..7376307 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -985,8 +985,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
 
 	info = drm_format_info(mode_cmd2->pixel_format);
 	if (!info || !info->depth) {
+		drm_format_name_buf format_name;
 		DRM_ERROR("Unsupported framebuffer format %s\n",
-			  drm_get_format_name(mode_cmd2->pixel_format));
+		          drm_get_format_name(mode_cmd2->pixel_format, format_name));
 		return ERR_PTR(-EINVAL);
 	}
 
-- 
Cheers,
  Eric

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH] drm: move allocation out of drm_get_format_name()
  2016-11-05  1:33 ` [PATCH] drm: move allocation out of drm_get_format_name() Eric Engestrom
@ 2016-11-05  6:56   ` Thomas Hellstrom
  2016-11-05 12:11   ` Christian König
  1 sibling, 0 replies; 28+ messages in thread
From: Thomas Hellstrom @ 2016-11-05  6:56 UTC (permalink / raw)
  To: Eric Engestrom, linux-kernel
  Cc: Ville Syrjälä,
	Alex Deucher, Christian König, David Airlie, Xinliang Liu,
	Daniel Vetter, Jani Nikula, VMware Graphics, Sinclair Yeh,
	Tom St Denis, Michel Dänzer, Gustavo Padovan, Emily Deng,
	Chunming Zhou, Flora Cui, Vitaly Prosyak, Ken Wang,
	Colin Ian King, Alexandre Demers, Junwei Zhang, Xinwei Kong,
	Chris Wilson, Laurent Pinchart, Wei Yongjun, dri-devel,
	intel-gfx

For the vmwgfx part:

Acked-by: Thomas Hellstrom <thellstrom@vmware.com>


On 11/05/2016 08:33 AM, Eric Engestrom wrote:
> Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07
>
>     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>
>
> Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Eric Engestrom <eric@engestrom.ch>
> ---
>  drivers/gpu/drm/amd/amdgpu/dce_v10_0.c          |  7 ++---
>  drivers/gpu/drm/amd/amdgpu/dce_v11_0.c          |  7 ++---
>  drivers/gpu/drm/amd/amdgpu/dce_v6_0.c           |  3 +-
>  drivers/gpu/drm/amd/amdgpu/dce_v8_0.c           |  7 ++---
>  drivers/gpu/drm/drm_atomic.c                    |  7 +++--
>  drivers/gpu/drm/drm_crtc.c                      |  7 +++--
>  drivers/gpu/drm/drm_fourcc.c                    | 12 +++-----
>  drivers/gpu/drm/drm_framebuffer.c               |  7 +++--
>  drivers/gpu/drm/drm_modeset_helper.c            |  7 +++--
>  drivers/gpu/drm/drm_plane.c                     |  7 +++--
>  drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  7 ++---
>  drivers/gpu/drm/i915/i915_debugfs.c             |  8 ++---
>  drivers/gpu/drm/i915/intel_atomic_plane.c       |  8 ++---
>  drivers/gpu/drm/i915/intel_display.c            | 41 ++++++++++---------------
>  drivers/gpu/drm/radeon/atombios_crtc.c          | 14 ++++-----
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c             |  3 +-
>  include/drm/drm_fourcc.h                        |  3 +-
>  17 files changed, 71 insertions(+), 84 deletions(-)
>
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index dc0aafa..5a8cb4b 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -54,6 +54,7 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
>  int drm_format_vert_chroma_subsampling(uint32_t format);
>  int drm_format_plane_width(int width, uint32_t format, int plane);
>  int drm_format_plane_height(int height, uint32_t format, int plane);
> -char *drm_get_format_name(uint32_t format) __malloc;
> +typedef char drm_format_name_buf[32];
> +char *drm_get_format_name(uint32_t format, drm_format_name_buf buf);
>  
>  #endif /* __DRM_FOURCC_H__ */
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index cbb8b77..34ed520 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -79,17 +79,13 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
>  EXPORT_SYMBOL(drm_mode_legacy_fb_format);
>  
>  /**
> - * drm_get_format_name - return a string for drm fourcc format
> + * drm_get_format_name - fill a string with a drm fourcc format's name
>   * @format: format to compute name of
> + * @buf: caller-supplied buffer
> - *
> - * Note that the buffer returned by this function is owned by the caller
> - * and will need to be freed using kfree().
>   */
> -char *drm_get_format_name(uint32_t format)
> +char *drm_get_format_name(uint32_t format, drm_format_name_buf buf)
>  {
> -	char *buf = kmalloc(32, GFP_KERNEL);
> -
> -	snprintf(buf, 32,
> +	snprintf(buf, sizeof(drm_format_name_buf),
>  		 "%c%c%c%c %s-endian (0x%08x)",
>  		 printable_char(format & 0xff),
>  		 printable_char((format >> 8) & 0xff),
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> index 199d3f7..cefa3d8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> @@ -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;
> +	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;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> index ecd000e..462abb8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> @@ -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;
> +	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;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> index 44547f9..3b8cea3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> @@ -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;
> +	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;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> index 979aedf..8c624b5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> @@ -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;
> +	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;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index c32fb3c..8d2e6a5 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -835,9 +835,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);
> +		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;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 13441e2..7f5bbe3 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -827,9 +827,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
>  			ret = drm_plane_check_pixel_format(crtc->primary,
>  							   fb->pixel_format);
>  			if (ret) {
> -				char *format_name = drm_get_format_name(fb->pixel_format);
> -				DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> -				kfree(format_name);
> +				drm_format_name_buf format_name;
> +				DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +				              drm_get_format_name(fb->pixel_format,
> +				                                  format_name));
>  				goto out;
>  			}
>  		}
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 49fd7db..12ad188 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -133,9 +133,10 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
>  
>  	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);
> -		kfree(format_name);
> +		drm_format_name_buf format_name;
> +		DRM_DEBUG_KMS("bad framebuffer format %s\n",
> +		              drm_get_format_name(r->pixel_format,
> +		                                  format_name));
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c
> index 2544dfe..b6ab72a 100644
> --- a/drivers/gpu/drm/drm_modeset_helper.c
> +++ b/drivers/gpu/drm/drm_modeset_helper.c
> @@ -75,10 +75,11 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
>  
>  	info = drm_format_info(mode_cmd->pixel_format);
>  	if (!info || !info->depth) {
> -		char *format_name = drm_get_format_name(mode_cmd->pixel_format);
> +		drm_format_name_buf format_name;
>  
> -		DRM_DEBUG_KMS("non-RGB pixel format %s\n", format_name);
> -		kfree(format_name);
> +		DRM_DEBUG_KMS("non-RGB pixel format %s\n",
> +		              drm_get_format_name(mode_cmd->pixel_format,
> +		                                  format_name));
>  
>  		fb->depth = 0;
>  		fb->bits_per_pixel = 0;
> diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
> index 249c0ae..9a45c52 100644
> --- a/drivers/gpu/drm/drm_plane.c
> +++ b/drivers/gpu/drm/drm_plane.c
> @@ -479,9 +479,10 @@ static int __setplane_internal(struct drm_plane *plane,
>  	/* Check whether this plane supports the fb pixel format. */
>  	ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
>  	if (ret) {
> -		char *format_name = drm_get_format_name(fb->pixel_format);
> -		DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> -		kfree(format_name);
> +		drm_format_name_buf format_name;
> +		DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +		              drm_get_format_name(fb->pixel_format,
> +		                                  format_name));
>  		goto out;
>  	}
>  
> diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> index 7e7a4d4..c5c0b38 100644
> --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> @@ -608,17 +608,16 @@ static void ade_rdma_set(void __iomem *base, struct drm_framebuffer *fb,
>  			 u32 ch, u32 y, u32 in_h, u32 fmt)
>  {
>  	struct drm_gem_cma_object *obj = drm_fb_cma_get_gem_obj(fb, 0);
> -	char *format_name;
> +	drm_format_name_buf format_name;
>  	u32 reg_ctrl, reg_addr, reg_size, reg_stride, reg_space, reg_en;
>  	u32 stride = fb->pitches[0];
>  	u32 addr = (u32)obj->paddr + y * stride;
>  
>  	DRM_DEBUG_DRIVER("rdma%d: (y=%d, height=%d), stride=%d, paddr=0x%x\n",
>  			 ch + 1, y, in_h, stride, (u32)obj->paddr);
> -	format_name = drm_get_format_name(fb->pixel_format);
>  	DRM_DEBUG_DRIVER("addr=0x%x, fb:%dx%d, pixel_format=%d(%s)\n",
> -			 addr, fb->width, fb->height, fmt, format_name);
> +			 addr, fb->width, fb->height, fmt,
> +			 drm_get_format_name(fb->pixel_format, format_name));
> -	kfree(format_name);
>  
>  	/* get reg offset */
>  	reg_ctrl = RD_CH_CTRL(ch);
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index 20638d2..39f76b1 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -2971,7 +2971,7 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  	for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
>  		struct drm_plane_state *state;
>  		struct drm_plane *plane = &intel_plane->base;
> -		char *format_name;
> +		drm_format_name_buf format_name;
>  
>  		if (!plane->state) {
>  			seq_puts(m, "plane->state is NULL!\n");
> @@ -2981,9 +2981,9 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  		state = plane->state;
>  
>  		if (state->fb) {
> -			format_name = drm_get_format_name(state->fb->pixel_format);
> +			drm_get_format_name(state->fb->pixel_format, format_name);
>  		} else {
> -			format_name = kstrdup("N/A", GFP_KERNEL);
> +			sprintf(format_name, "N/A");
>  		}
>  
>  		seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
> @@ -3001,8 +3001,6 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  			   ((state->src_h & 0xffff) * 15625) >> 10,
>  			   format_name,
>  			   plane_rotation(state->rotation));
> -
> -		kfree(format_name);
>  	}
>  }
>  
> diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c b/drivers/gpu/drm/i915/intel_atomic_plane.c
> index c762ae5..289ebc9 100644
> --- a/drivers/gpu/drm/i915/intel_atomic_plane.c
> +++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
> @@ -143,7 +143,7 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>  		crtc_state->base.enable ? crtc_state->pipe_src_h : 0;
>  
>  	if (state->fb && drm_rotation_90_or_270(state->rotation)) {
> -		char *format_name;
> +		drm_format_name_buf format_name;
>  
>  		if (!(state->fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
>  			state->fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED)) {
> @@ -159,9 +159,9 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>  		switch (state->fb->pixel_format) {
>  		case DRM_FORMAT_C8:
>  		case DRM_FORMAT_RGB565:
> -			format_name = drm_get_format_name(state->fb->pixel_format);
> -			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n", format_name);
> -			kfree(format_name);
> +			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
> +			              drm_get_format_name(state->fb->pixel_format,
> +			                                  format_name));
>  			return -EINVAL;
>  
>  		default:
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 6f8f6ec..ab0882f 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -12871,7 +12871,7 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  
>  	DRM_DEBUG_KMS("planes on this crtc\n");
>  	list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
> -		char *format_name;
> +		drm_format_name_buf format_name;
>  		intel_plane = to_intel_plane(plane);
>  		if (intel_plane->pipe != crtc->pipe)
>  			continue;
> @@ -12884,12 +12884,11 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  			continue;
>  		}
>  
> -		format_name = drm_get_format_name(fb->pixel_format);
> -
>  		DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
>  			      plane->base.id, plane->name);
>  		DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
> -			      fb->base.id, fb->width, fb->height, format_name);
> +			      fb->base.id, fb->width, fb->height,
> +			      drm_get_format_name(fb->pixel_format, format_name));
>  		DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
>  			      state->scaler_id,
>  			      state->base.src.x1 >> 16,
> @@ -12899,8 +12898,6 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  			      state->base.dst.x1, state->base.dst.y1,
>  			      drm_rect_width(&state->base.dst),
>  			      drm_rect_height(&state->base.dst));
> -
> -		kfree(format_name);
>  	}
>  }
>  
> @@ -15749,7 +15746,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	unsigned int tiling = i915_gem_object_get_tiling(obj);
>  	int ret;
>  	u32 pitch_limit, stride_alignment;
> -	char *format_name;
> +	drm_format_name_buf format_name;
>  
>  	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
>  
> @@ -15840,18 +15837,16 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  		break;
>  	case DRM_FORMAT_XRGB1555:
>  		if (INTEL_INFO(dev)->gen > 3) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> -			kfree(format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, format_name));
>  			return -EINVAL;
>  		}
>  		break;
>  	case DRM_FORMAT_ABGR8888:
>  		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
>  		    INTEL_INFO(dev)->gen < 9) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> -			kfree(format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, format_name));
>  			return -EINVAL;
>  		}
>  		break;
> @@ -15859,17 +15854,15 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	case DRM_FORMAT_XRGB2101010:
>  	case DRM_FORMAT_XBGR2101010:
>  		if (INTEL_INFO(dev)->gen < 4) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> -			kfree(format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, format_name));
>  			return -EINVAL;
>  		}
>  		break;
>  	case DRM_FORMAT_ABGR2101010:
>  		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> -			kfree(format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, format_name));
>  			return -EINVAL;
>  		}
>  		break;
> @@ -15878,16 +15871,14 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	case DRM_FORMAT_YVYU:
>  	case DRM_FORMAT_VYUY:
>  		if (INTEL_INFO(dev)->gen < 5) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> -			kfree(format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, format_name));
>  			return -EINVAL;
>  		}
>  		break;
>  	default:
> -		format_name = drm_get_format_name(mode_cmd->pixel_format);
> -		DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> -		kfree(format_name);
> +		DRM_DEBUG("unsupported pixel format: %s\n",
> +		          drm_get_format_name(mode_cmd->pixel_format, format_name));
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
> index 74f99ba..adff13b 100644
> --- a/drivers/gpu/drm/radeon/atombios_crtc.c
> +++ b/drivers/gpu/drm/radeon/atombios_crtc.c
> @@ -1156,7 +1156,7 @@ static int dce4_crtc_do_set_base(struct drm_crtc *crtc,
>  	u32 tmp, viewport_w, viewport_h;
>  	int r;
>  	bool bypass_lut = false;
> -	char *format_name;
> +	drm_format_name_buf format_name;
>  
>  	/* no fb bound */
>  	if (!atomic && !crtc->primary->fb) {
> @@ -1260,9 +1260,8 @@ static int dce4_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;
>  	}
>  
> @@ -1473,7 +1472,7 @@ static int avivo_crtc_do_set_base(struct drm_crtc *crtc,
>  	u32 viewport_w, viewport_h;
>  	int r;
>  	bool bypass_lut = false;
> -	char *format_name;
> +	drm_format_name_buf format_name;
>  
>  	/* no fb bound */
>  	if (!atomic && !crtc->primary->fb) {
> @@ -1563,9 +1562,8 @@ static int avivo_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;
>  	}
>  
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> index c965514..7376307 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> @@ -985,8 +985,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
>  
>  	info = drm_format_info(mode_cmd2->pixel_format);
>  	if (!info || !info->depth) {
> +		drm_format_name_buf format_name;
>  		DRM_ERROR("Unsupported framebuffer format %s\n",
> -			  drm_get_format_name(mode_cmd2->pixel_format));
> +		          drm_get_format_name(mode_cmd2->pixel_format, format_name));
>  		return ERR_PTR(-EINVAL);
>  	}
>  

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] drm: move allocation out of drm_get_format_name()
  2016-11-05  1:33 ` [PATCH] drm: move allocation out of drm_get_format_name() Eric Engestrom
  2016-11-05  6:56   ` Thomas Hellstrom
@ 2016-11-05 12:11   ` Christian König
  2016-11-05 16:38     ` Eric Engestrom
  1 sibling, 1 reply; 28+ messages in thread
From: Christian König @ 2016-11-05 12:11 UTC (permalink / raw)
  To: Eric Engestrom, linux-kernel
  Cc: Ville Syrjälä,
	Alex Deucher, David Airlie, Xinliang Liu, Daniel Vetter,
	Jani Nikula, VMware Graphics, Sinclair Yeh, Thomas Hellstrom,
	Tom St Denis, Michel Dänzer, Gustavo Padovan, Emily Deng,
	Chunming Zhou, Flora Cui, Vitaly Prosyak, Ken Wang,
	Colin Ian King, Alexandre Demers, Junwei Zhang, Xinwei Kong,
	Chris Wilson, Laurent Pinchart, Wei Yongjun, dri-devel,
	intel-gfx

Am 05.11.2016 um 02:33 schrieb Eric Engestrom:
> +typedef char drm_format_name_buf[32];

Please don't use a typedef for this, just define the maximum size of 
characters the function might write somewhere.

See the kernel coding style as well:
> In general, a pointer, or a struct that has elements that can reasonably
> be directly accessed should **never** be a typedef.

Regards,
Christian.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] drm: move allocation out of drm_get_format_name()
  2016-11-05 12:11   ` Christian König
@ 2016-11-05 16:38     ` Eric Engestrom
  2016-11-05 16:49       ` Rob Clark
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Engestrom @ 2016-11-05 16:38 UTC (permalink / raw)
  To: Christian König
  Cc: linux-kernel, Ville Syrjälä,
	Alex Deucher, David Airlie, Xinliang Liu, Daniel Vetter,
	Jani Nikula, VMware Graphics, Sinclair Yeh, Thomas Hellstrom,
	Tom St Denis, Michel Dänzer, Gustavo Padovan, Emily Deng,
	Chunming Zhou, Flora Cui, Vitaly Prosyak, Ken Wang,
	Colin Ian King, Alexandre Demers, Junwei Zhang, Xinwei Kong,
	Chris Wilson, Laurent Pinchart, Wei Yongjun, dri-devel,
	intel-gfx

On Saturday, 2016-11-05 13:11:36 +0100, Christian König wrote:
> Am 05.11.2016 um 02:33 schrieb Eric Engestrom:
> > +typedef char drm_format_name_buf[32];
> 
> Please don't use a typedef for this, just define the maximum size of
> characters the function might write somewhere.
> 
> See the kernel coding style as well:
> > In general, a pointer, or a struct that has elements that can reasonably
> > be directly accessed should **never** be a typedef.
> 

I would normally agree as I tend to hate typedefs ($DAYJOB {ab,mis}uses
them way too much), and your way was what I wrote at first, but Rob Clark's
typedef idea makes it much harder for someone to allocate a buffer of
the wrong size, which IMO is good thing here.

I can rewrite the typedef out if you think it's better.

Cheers,
  Eric

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] drm: move allocation out of drm_get_format_name()
  2016-11-05 16:38     ` Eric Engestrom
@ 2016-11-05 16:49       ` Rob Clark
  2016-11-06  9:47         ` Christian König
  0 siblings, 1 reply; 28+ messages in thread
From: Rob Clark @ 2016-11-05 16:49 UTC (permalink / raw)
  To: Eric Engestrom
  Cc: Christian König, dri-devel, Wei Yongjun, Daniel Vetter,
	Flora Cui, Gustavo Padovan, Tom St Denis, Thomas Hellstrom,
	Laurent Pinchart, Xinliang Liu, VMware Graphics, Vitaly Prosyak,
	Alexandre Demers, Intel Graphics Development, Emily Deng,
	Ken Wang, Junwei Zhang, Michel Dänzer,
	Linux Kernel Mailing List, Alex Deucher, Colin Ian King

On Sat, Nov 5, 2016 at 12:38 PM, Eric Engestrom <eric@engestrom.ch> wrote:
> On Saturday, 2016-11-05 13:11:36 +0100, Christian König wrote:
>> Am 05.11.2016 um 02:33 schrieb Eric Engestrom:
>> > +typedef char drm_format_name_buf[32];
>>
>> Please don't use a typedef for this, just define the maximum size of
>> characters the function might write somewhere.
>>
>> See the kernel coding style as well:
>> > In general, a pointer, or a struct that has elements that can reasonably
>> > be directly accessed should **never** be a typedef.
>>
>
> I would normally agree as I tend to hate typedefs ($DAYJOB {ab,mis}uses
> them way too much), and your way was what I wrote at first, but Rob Clark's
> typedef idea makes it much harder for someone to allocate a buffer of
> the wrong size, which IMO is good thing here.

IMHO I would make a small test program to verify this actually helps
the compiler catch problems.  And if it does, I would stick with it.
The coding-style should be guidelines, not something that supersedes
common sense / practicality.

That is my $0.02 anyways.. if others vehemently disagree and want to
dogmatically stick to the coding-style guidelines, ok then.  OTOH, if
this approach doesn't help the compiler catch issues, then it isn't
worth it.

BR,
-R

> I can rewrite the typedef out if you think it's better.
>
> Cheers,
>   Eric
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] drm: move allocation out of drm_get_format_name()
  2016-11-05 16:49       ` Rob Clark
@ 2016-11-06  9:47         ` Christian König
  2016-11-06 13:03           ` Rob Clark
  0 siblings, 1 reply; 28+ messages in thread
From: Christian König @ 2016-11-06  9:47 UTC (permalink / raw)
  To: Rob Clark, Eric Engestrom
  Cc: dri-devel, Wei Yongjun, Daniel Vetter, Flora Cui,
	Gustavo Padovan, Tom St Denis, Thomas Hellstrom,
	Laurent Pinchart, Xinliang Liu, VMware Graphics, Vitaly Prosyak,
	Alexandre Demers, Intel Graphics Development, Emily Deng,
	Ken Wang, Junwei Zhang, Michel Dänzer,
	Linux Kernel Mailing List, Alex Deucher, Colin Ian King

Am 05.11.2016 um 17:49 schrieb Rob Clark:
> On Sat, Nov 5, 2016 at 12:38 PM, Eric Engestrom <eric@engestrom.ch> wrote:
>> On Saturday, 2016-11-05 13:11:36 +0100, Christian König wrote:
>>> Am 05.11.2016 um 02:33 schrieb Eric Engestrom:
>>>> +typedef char drm_format_name_buf[32];
>>> Please don't use a typedef for this, just define the maximum size of
>>> characters the function might write somewhere.
>>>
>>> See the kernel coding style as well:
>>>> In general, a pointer, or a struct that has elements that can reasonably
>>>> be directly accessed should **never** be a typedef.
>> I would normally agree as I tend to hate typedefs ($DAYJOB {ab,mis}uses
>> them way too much), and your way was what I wrote at first, but Rob Clark's
>> typedef idea makes it much harder for someone to allocate a buffer of
>> the wrong size, which IMO is good thing here.
> IMHO I would make a small test program to verify this actually helps
> the compiler catch problems.  And if it does, I would stick with it.
> The coding-style should be guidelines, not something that supersedes
> common sense / practicality.

Well completely agree that we should be able to question the coding 
style rules, but when we do it we discuss this on a the mailing list 
first and then start to use it in code. Not the other way around.

>
> That is my $0.02 anyways.. if others vehemently disagree and want to
> dogmatically stick to the coding-style guidelines, ok then.  OTOH, if
> this approach doesn't help the compiler catch issues, then it isn't
> worth it.

Yeah, exactly that's the point. If I'm not completely mistaken the 
compiler won't issue a warning here if you pass an array with the wrong 
size.

I think you need something like "struct drm_format_name_buf { char 
str[32]; };" to trigger this.

Apart from that is this function really called so often that using 
kasprintf() is a problem here? Or is there another motivation behind the 
change?

Regards,
Christian.

>
> BR,
> -R
>
>> I can rewrite the typedef out if you think it's better.
>>
>> Cheers,
>>    Eric
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] drm: move allocation out of drm_get_format_name()
  2016-11-06  9:47         ` Christian König
@ 2016-11-06 13:03           ` Rob Clark
  2016-11-07  0:47             ` Eric Engestrom
  0 siblings, 1 reply; 28+ messages in thread
From: Rob Clark @ 2016-11-06 13:03 UTC (permalink / raw)
  To: Christian König
  Cc: Eric Engestrom, dri-devel, Wei Yongjun, Daniel Vetter, Flora Cui,
	Gustavo Padovan, Tom St Denis, Thomas Hellstrom,
	Laurent Pinchart, Xinliang Liu, VMware Graphics, Vitaly Prosyak,
	Alexandre Demers, Intel Graphics Development, Emily Deng,
	Ken Wang, Junwei Zhang, Michel Dänzer,
	Linux Kernel Mailing List, Alex Deucher, Colin Ian King

On Sun, Nov 6, 2016 at 4:47 AM, Christian König
<christian.koenig@amd.com> wrote:
> Am 05.11.2016 um 17:49 schrieb Rob Clark:
>>
>> On Sat, Nov 5, 2016 at 12:38 PM, Eric Engestrom <eric@engestrom.ch> wrote:
>>>
>>> On Saturday, 2016-11-05 13:11:36 +0100, Christian König wrote:
>>>>
>>>> Am 05.11.2016 um 02:33 schrieb Eric Engestrom:
>>>>>
>>>>> +typedef char drm_format_name_buf[32];
>>>>
>>>> Please don't use a typedef for this, just define the maximum size of
>>>> characters the function might write somewhere.
>>>>
>>>> See the kernel coding style as well:
>>>>>
>>>>> In general, a pointer, or a struct that has elements that can
>>>>> reasonably
>>>>> be directly accessed should **never** be a typedef.
>>>
>>> I would normally agree as I tend to hate typedefs ($DAYJOB {ab,mis}uses
>>> them way too much), and your way was what I wrote at first, but Rob
>>> Clark's
>>> typedef idea makes it much harder for someone to allocate a buffer of
>>> the wrong size, which IMO is good thing here.
>>
>> IMHO I would make a small test program to verify this actually helps
>> the compiler catch problems.  And if it does, I would stick with it.
>> The coding-style should be guidelines, not something that supersedes
>> common sense / practicality.
>
>
> Well completely agree that we should be able to question the coding style
> rules, but when we do it we discuss this on a the mailing list first and
> then start to use it in code. Not the other way around.

if I'm not mistaken, that is what we are doing ;-)

>>
>> That is my $0.02 anyways.. if others vehemently disagree and want to
>> dogmatically stick to the coding-style guidelines, ok then.  OTOH, if
>> this approach doesn't help the compiler catch issues, then it isn't
>> worth it.
>
>
> Yeah, exactly that's the point. If I'm not completely mistaken the compiler
> won't issue a warning here if you pass an array with the wrong size.
>
> I think you need something like "struct drm_format_name_buf { char str[32];
> };" to trigger this.

hmm, actually the struct is a nice idea then if the compiler wouldn't
catch the wrong-size-array

> Apart from that is this function really called so often that using
> kasprintf() is a problem here? Or is there another motivation behind the
> change?

Two things trouble me about the kasprintf approach.. (ignoring the
fact that atm it is not GFP_ATOMIC)
1) you can't do DRM_DEBUG("format: %s\n", drm_get_format_name(..)) so
it pulls the memory allocation and sprintf outside of the drm_debug
check
2) seems awfully easy to forget the kfree...  I wouldn't have even
known that now you need to free the result (with some patches I'm
working on) if it weren't for the fact that lockdep alerted me to the
GFP_KERNEL allocation in atomic ctx ;-)

BR,
-R

> Regards,
> Christian.
>
>
>>
>> BR,
>> -R
>>
>>> I can rewrite the typedef out if you think it's better.
>>>
>>> Cheers,
>>>    Eric
>>> _______________________________________________
>>> dri-devel mailing list
>>> dri-devel@lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
>
>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] drm: move allocation out of drm_get_format_name()
  2016-11-06 13:03           ` Rob Clark
@ 2016-11-07  0:47             ` Eric Engestrom
  2016-11-07  0:48               ` [PATCH v2] " Eric Engestrom
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Engestrom @ 2016-11-07  0:47 UTC (permalink / raw)
  To: Rob Clark
  Cc: Christian König, dri-devel, Wei Yongjun, Daniel Vetter,
	Flora Cui, Gustavo Padovan, Tom St Denis, Thomas Hellstrom,
	Laurent Pinchart, Xinliang Liu, VMware Graphics, Vitaly Prosyak,
	Alexandre Demers, Intel Graphics Development, Emily Deng,
	Ken Wang, Junwei Zhang, Michel Dänzer,
	Linux Kernel Mailing List, Alex Deucher, Colin Ian King

On Sunday, 2016-11-06 08:03:47 -0500, Rob Clark wrote:
> On Sun, Nov 6, 2016 at 4:47 AM, Christian König
> <christian.koenig@amd.com> wrote:
> > Am 05.11.2016 um 17:49 schrieb Rob Clark:
> >>
> >> On Sat, Nov 5, 2016 at 12:38 PM, Eric Engestrom <eric@engestrom.ch> wrote:
> >>>
> >>> On Saturday, 2016-11-05 13:11:36 +0100, Christian König wrote:
> >>>>
> >>>> Am 05.11.2016 um 02:33 schrieb Eric Engestrom:
> >>>>>
> >>>>> +typedef char drm_format_name_buf[32];
> >>>>
> >>>> Please don't use a typedef for this, just define the maximum size of
> >>>> characters the function might write somewhere.
> >>>>
> >>>> See the kernel coding style as well:
> >>>>>
> >>>>> In general, a pointer, or a struct that has elements that can
> >>>>> reasonably
> >>>>> be directly accessed should **never** be a typedef.
> >>>
> >>> I would normally agree as I tend to hate typedefs ($DAYJOB {ab,mis}uses
> >>> them way too much), and your way was what I wrote at first, but Rob
> >>> Clark's
> >>> typedef idea makes it much harder for someone to allocate a buffer of
> >>> the wrong size, which IMO is good thing here.
> >>
> >> IMHO I would make a small test program to verify this actually helps
> >> the compiler catch problems.  And if it does, I would stick with it.
> >> The coding-style should be guidelines, not something that supersedes
> >> common sense / practicality.
> >
> >
> > Well completely agree that we should be able to question the coding style
> > rules, but when we do it we discuss this on a the mailing list first and
> > then start to use it in code. Not the other way around.
> 
> if I'm not mistaken, that is what we are doing ;-)
> 
> >>
> >> That is my $0.02 anyways.. if others vehemently disagree and want to
> >> dogmatically stick to the coding-style guidelines, ok then.  OTOH, if
> >> this approach doesn't help the compiler catch issues, then it isn't
> >> worth it.
> >
> >
> > Yeah, exactly that's the point. If I'm not completely mistaken the compiler
> > won't issue a warning here if you pass an array with the wrong size.
> >
> > I think you need something like "struct drm_format_name_buf { char str[32];
> > };" to trigger this.
> 
> hmm, actually the struct is a nice idea then if the compiler wouldn't
> catch the wrong-size-array

Sending the patch in a minute.

> 
> > apart from that is this function really called so often that using
> > kasprintf() is a problem here? or is there another motivation behind the
> > change?
> 
> two things trouble me about the kasprintf approach.. (ignoring the
> fact that atm it is not gfp_atomic)
> 1) you can't do drm_debug("format: %s\n", drm_get_format_name(..)) so
> it pulls the memory allocation and sprintf outside of the drm_debug
> check
> 2) seems awfully easy to forget the kfree...

I actually found a couple of these memory leaks while doing this patch,
look for files where i don't remove kfree :)
(eg. vmwgfx at the end of the patch)

> i wouldn't have even
> known that now you need to free the result (with some patches i'm
> working on) if it weren't for the fact that lockdep alerted me to the
> gfp_kernel allocation in atomic ctx ;-)
> 
> br,
> -r

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v2] drm: move allocation out of drm_get_format_name()
  2016-11-07  0:47             ` Eric Engestrom
@ 2016-11-07  0:48               ` Eric Engestrom
  2016-11-07  7:46                 ` Christian König
                                   ` (3 more replies)
  0 siblings, 4 replies; 28+ messages in thread
From: Eric Engestrom @ 2016-11-07  0:48 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ville Syrjälä,
	Eric Engestrom, Rob Clark, Christian König, Alex Deucher,
	David Airlie, Xinliang Liu, Daniel Vetter, Jani Nikula,
	VMware Graphics, Sinclair Yeh, Thomas Hellstrom, Tom St Denis,
	Michel Dänzer, Gustavo Padovan, Emily Deng, Chunming Zhou,
	Flora Cui, Vitaly Prosyak, Colin Ian King, Ken Wang,
	Alexandre Demers, Eric Engestrom, Junwei Zhang, Xinwei Kong,
	Wei Yongjun, Chris Wilson, Laurent Pinchart, dri-devel,
	intel-gfx

Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07

    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>

Cc: Rob Clark <robdclark@gmail.com>
Cc: Christian König <christian.koenig@amd.com>
Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
---

v2: use single-field struct instead of typedef to let the compiler
    enforce the type (Christian König)

---
 include/drm/drm_fourcc.h                        | 10 +++++-
 drivers/gpu/drm/drm_fourcc.c                    | 14 +++------
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c          |  7 ++---
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c          |  7 ++---
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c           |  3 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c           |  7 ++---
 drivers/gpu/drm/drm_atomic.c                    |  7 +++--
 drivers/gpu/drm/drm_crtc.c                      |  7 +++--
 drivers/gpu/drm/drm_framebuffer.c               |  7 +++--
 drivers/gpu/drm/drm_modeset_helper.c            |  7 +++--
 drivers/gpu/drm/drm_plane.c                     |  7 +++--
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  7 ++---
 drivers/gpu/drm/i915/i915_debugfs.c             | 10 +++---
 drivers/gpu/drm/i915/intel_atomic_plane.c       |  8 ++---
 drivers/gpu/drm/i915/intel_display.c            | 41 ++++++++++---------------
 drivers/gpu/drm/radeon/atombios_crtc.c          | 14 ++++-----
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c             |  3 +-
 17 files changed, 80 insertions(+), 86 deletions(-)

diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index dc0aafa..4b03ca0 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -45,6 +45,14 @@ struct drm_format_info {
 	u8 vsub;
 };
 
+/**
+ * struct drm_format_name_buf - name of a DRM format
+ * @str: string buffer containing the format name
+ */
+struct drm_format_name_buf {
+	char str[32];
+};
+
 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);
@@ -54,6 +62,6 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
 int drm_format_vert_chroma_subsampling(uint32_t format);
 int drm_format_plane_width(int width, uint32_t format, int plane);
 int drm_format_plane_height(int height, uint32_t format, int plane);
-char *drm_get_format_name(uint32_t format) __malloc;
+char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
 
 #endif /* __DRM_FOURCC_H__ */
diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index cbb8b77..99b0b60 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -79,17 +79,13 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
 EXPORT_SYMBOL(drm_mode_legacy_fb_format);
 
 /**
- * drm_get_format_name - return a string for drm fourcc format
+ * drm_get_format_name - fill a string with a drm fourcc format's name
  * @format: format to compute name of
+ * @buf: caller-supplied buffer
- *
- * Note that the buffer returned by this function is owned by the caller
- * and will need to be freed using kfree().
  */
-char *drm_get_format_name(uint32_t format)
+char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf)
 {
-	char *buf = kmalloc(32, GFP_KERNEL);
-
-	snprintf(buf, 32,
+	snprintf(buf->str, sizeof(buf->str),
 		 "%c%c%c%c %s-endian (0x%08x)",
 		 printable_char(format & 0xff),
 		 printable_char((format >> 8) & 0xff),
@@ -98,7 +94,7 @@ char *drm_get_format_name(uint32_t format)
 		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
 		 format);
 
-	return buf;
+	return buf->str;
 }
 EXPORT_SYMBOL(drm_get_format_name);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
index 199d3f7..2924cdd 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
@@ -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);
+		DRM_ERROR("Unsupported screen format %s\n",
+		          drm_get_format_name(target_fb->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
index ecd000e..f0e3c5c 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
@@ -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);
+		DRM_ERROR("Unsupported screen format %s\n",
+		          drm_get_format_name(target_fb->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
index 44547f9..5c6b82f 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
@@ -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;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
index 979aedf..5aef19d 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
@@ -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);
+		DRM_ERROR("Unsupported screen format %s\n",
+		          drm_get_format_name(target_fb->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index c32fb3c..f29d3c5 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -835,9 +835,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);
+		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));
-		kfree(format_name);
 		return ret;
 	}
 
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 13441e2..08ac216 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -827,9 +827,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
 			ret = drm_plane_check_pixel_format(crtc->primary,
 							   fb->pixel_format);
 			if (ret) {
-				char *format_name = drm_get_format_name(fb->pixel_format);
-				DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
+				struct drm_format_name_buf format_name;
+				DRM_DEBUG_KMS("Invalid pixel format %s\n",
+				              drm_get_format_name(fb->pixel_format,
+				                                  &format_name));
-				kfree(format_name);
 				goto out;
 			}
 		}
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index 49fd7db..df6b180 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -133,9 +133,10 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
 
 	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);
+		struct drm_format_name_buf format_name;
+		DRM_DEBUG_KMS("bad framebuffer format %s\n",
+		              drm_get_format_name(r->pixel_format,
+		                                  &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c
index 2544dfe..2f452b3 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -75,10 +75,11 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
 
 	info = drm_format_info(mode_cmd->pixel_format);
 	if (!info || !info->depth) {
-		char *format_name = drm_get_format_name(mode_cmd->pixel_format);
+		struct drm_format_name_buf format_name;
 
-		DRM_DEBUG_KMS("non-RGB pixel format %s\n", format_name);
+		DRM_DEBUG_KMS("non-RGB pixel format %s\n",
+		              drm_get_format_name(mode_cmd->pixel_format,
+		                                  &format_name));
-		kfree(format_name);
 
 		fb->depth = 0;
 		fb->bits_per_pixel = 0;
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 249c0ae..2ba0c22 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -479,9 +479,10 @@ static int __setplane_internal(struct drm_plane *plane,
 	/* Check whether this plane supports the fb pixel format. */
 	ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
 	if (ret) {
-		char *format_name = drm_get_format_name(fb->pixel_format);
-		DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
+		struct drm_format_name_buf format_name;
+		DRM_DEBUG_KMS("Invalid pixel format %s\n",
+		              drm_get_format_name(fb->pixel_format,
+		                                  &format_name));
-		kfree(format_name);
 		goto out;
 	}
 
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 7e7a4d4..afc2b5d 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -608,17 +608,16 @@ static void ade_rdma_set(void __iomem *base, struct drm_framebuffer *fb,
 			 u32 ch, u32 y, u32 in_h, u32 fmt)
 {
 	struct drm_gem_cma_object *obj = drm_fb_cma_get_gem_obj(fb, 0);
-	char *format_name;
+	struct drm_format_name_buf format_name;
 	u32 reg_ctrl, reg_addr, reg_size, reg_stride, reg_space, reg_en;
 	u32 stride = fb->pitches[0];
 	u32 addr = (u32)obj->paddr + y * stride;
 
 	DRM_DEBUG_DRIVER("rdma%d: (y=%d, height=%d), stride=%d, paddr=0x%x\n",
 			 ch + 1, y, in_h, stride, (u32)obj->paddr);
-	format_name = drm_get_format_name(fb->pixel_format);
 	DRM_DEBUG_DRIVER("addr=0x%x, fb:%dx%d, pixel_format=%d(%s)\n",
-			 addr, fb->width, fb->height, fmt, format_name);
+			 addr, fb->width, fb->height, fmt,
+			 drm_get_format_name(fb->pixel_format, &format_name));
-	kfree(format_name);
 
 	/* get reg offset */
 	reg_ctrl = RD_CH_CTRL(ch);
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 20638d2..670423e 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -2971,7 +2971,7 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 	for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
 		struct drm_plane_state *state;
 		struct drm_plane *plane = &intel_plane->base;
-		char *format_name;
+		struct drm_format_name_buf format_name;
 
 		if (!plane->state) {
 			seq_puts(m, "plane->state is NULL!\n");
@@ -2981,9 +2981,9 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 		state = plane->state;
 
 		if (state->fb) {
-			format_name = drm_get_format_name(state->fb->pixel_format);
+			drm_get_format_name(state->fb->pixel_format, &format_name);
 		} else {
-			format_name = kstrdup("N/A", GFP_KERNEL);
+			sprintf(format_name.str, "N/A");
 		}
 
 		seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
@@ -2999,10 +2999,8 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 			   ((state->src_w & 0xffff) * 15625) >> 10,
 			   (state->src_h >> 16),
 			   ((state->src_h & 0xffff) * 15625) >> 10,
-			   format_name,
+			   format_name.str,
 			   plane_rotation(state->rotation));
-
-		kfree(format_name);
 	}
 }
 
diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c b/drivers/gpu/drm/i915/intel_atomic_plane.c
index c762ae5..6c76e3d 100644
--- a/drivers/gpu/drm/i915/intel_atomic_plane.c
+++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
@@ -143,7 +143,7 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
 		crtc_state->base.enable ? crtc_state->pipe_src_h : 0;
 
 	if (state->fb && drm_rotation_90_or_270(state->rotation)) {
-		char *format_name;
+		struct drm_format_name_buf format_name;
 
 		if (!(state->fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
 			state->fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED)) {
@@ -159,9 +159,9 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
 		switch (state->fb->pixel_format) {
 		case DRM_FORMAT_C8:
 		case DRM_FORMAT_RGB565:
-			format_name = drm_get_format_name(state->fb->pixel_format);
-			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n", format_name);
+			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
+			              drm_get_format_name(state->fb->pixel_format,
+			                                  &format_name));
-			kfree(format_name);
 			return -EINVAL;
 
 		default:
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 6f8f6ec..8209170 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -12871,7 +12871,7 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 
 	DRM_DEBUG_KMS("planes on this crtc\n");
 	list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
-		char *format_name;
+		struct drm_format_name_buf format_name;
 		intel_plane = to_intel_plane(plane);
 		if (intel_plane->pipe != crtc->pipe)
 			continue;
@@ -12884,12 +12884,11 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 			continue;
 		}
 
-		format_name = drm_get_format_name(fb->pixel_format);
-
 		DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
 			      plane->base.id, plane->name);
 		DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
-			      fb->base.id, fb->width, fb->height, format_name);
+			      fb->base.id, fb->width, fb->height,
+			      drm_get_format_name(fb->pixel_format, &format_name));
 		DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
 			      state->scaler_id,
 			      state->base.src.x1 >> 16,
@@ -12899,8 +12898,6 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 			      state->base.dst.x1, state->base.dst.y1,
 			      drm_rect_width(&state->base.dst),
 			      drm_rect_height(&state->base.dst));
-
-		kfree(format_name);
 	}
 }
 
@@ -15749,7 +15746,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	unsigned int tiling = i915_gem_object_get_tiling(obj);
 	int ret;
 	u32 pitch_limit, stride_alignment;
-	char *format_name;
+	struct drm_format_name_buf format_name;
 
 	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
 
@@ -15840,18 +15837,16 @@ static int intel_framebuffer_init(struct drm_device *dev,
 		break;
 	case DRM_FORMAT_XRGB1555:
 		if (INTEL_INFO(dev)->gen > 3) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-			kfree(format_name);
 			return -EINVAL;
 		}
 		break;
 	case DRM_FORMAT_ABGR8888:
 		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
 		    INTEL_INFO(dev)->gen < 9) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-			kfree(format_name);
 			return -EINVAL;
 		}
 		break;
@@ -15859,17 +15854,15 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	case DRM_FORMAT_XRGB2101010:
 	case DRM_FORMAT_XBGR2101010:
 		if (INTEL_INFO(dev)->gen < 4) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-			kfree(format_name);
 			return -EINVAL;
 		}
 		break;
 	case DRM_FORMAT_ABGR2101010:
 		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-			kfree(format_name);
 			return -EINVAL;
 		}
 		break;
@@ -15878,16 +15871,14 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	case DRM_FORMAT_YVYU:
 	case DRM_FORMAT_VYUY:
 		if (INTEL_INFO(dev)->gen < 5) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-			kfree(format_name);
 			return -EINVAL;
 		}
 		break;
 	default:
-		format_name = drm_get_format_name(mode_cmd->pixel_format);
-		DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+		DRM_DEBUG("unsupported pixel format: %s\n",
+		          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index 74f99ba..05f4ebe 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -1156,7 +1156,7 @@ static int dce4_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) {
@@ -1260,9 +1260,8 @@ static int dce4_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);
+		DRM_ERROR("Unsupported screen format %s\n",
+		          drm_get_format_name(target_fb->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
@@ -1473,7 +1472,7 @@ static int avivo_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) {
@@ -1563,9 +1562,8 @@ static int avivo_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);
+		DRM_ERROR("Unsupported screen format %s\n",
+		          drm_get_format_name(target_fb->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index c965514..e3f68cc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -985,8 +985,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
 
 	info = drm_format_info(mode_cmd2->pixel_format);
 	if (!info || !info->depth) {
+		struct drm_format_name_buf format_name;
 		DRM_ERROR("Unsupported framebuffer format %s\n",
-			  drm_get_format_name(mode_cmd2->pixel_format));
+		          drm_get_format_name(mode_cmd2->pixel_format, &format_name));
 		return ERR_PTR(-EINVAL);
 	}
 
-- 
Cheers,
  Eric

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH v2] drm: move allocation out of drm_get_format_name()
  2016-11-07  0:48               ` [PATCH v2] " Eric Engestrom
@ 2016-11-07  7:46                 ` Christian König
  2016-11-07  8:10                 ` Jani Nikula
                                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 28+ messages in thread
From: Christian König @ 2016-11-07  7:46 UTC (permalink / raw)
  To: Eric Engestrom, linux-kernel
  Cc: Ville Syrjälä,
	Rob Clark, Alex Deucher, David Airlie, Xinliang Liu,
	Daniel Vetter, Jani Nikula, VMware Graphics, Sinclair Yeh,
	Thomas Hellstrom, Tom St Denis, Michel Dänzer,
	Gustavo Padovan, Emily Deng, Chunming Zhou, Flora Cui,
	Vitaly Prosyak, Colin Ian King, Ken Wang, Alexandre Demers,
	Eric Engestrom, Junwei Zhang, Xinwei Kong, Wei Yongjun,
	Chris Wilson, Laurent Pinchart, dri-devel, intel-gfx

Am 07.11.2016 um 01:48 schrieb Eric Engestrom:
> Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07
>
>      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>
>
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Christian König <christian.koenig@amd.com>
> Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Acked-by: Christian König <christian.koenig@amd.com>.

> ---
>
> v2: use single-field struct instead of typedef to let the compiler
>      enforce the type (Christian König)
>
> ---
>   include/drm/drm_fourcc.h                        | 10 +++++-
>   drivers/gpu/drm/drm_fourcc.c                    | 14 +++------
>   drivers/gpu/drm/amd/amdgpu/dce_v10_0.c          |  7 ++---
>   drivers/gpu/drm/amd/amdgpu/dce_v11_0.c          |  7 ++---
>   drivers/gpu/drm/amd/amdgpu/dce_v6_0.c           |  3 +-
>   drivers/gpu/drm/amd/amdgpu/dce_v8_0.c           |  7 ++---
>   drivers/gpu/drm/drm_atomic.c                    |  7 +++--
>   drivers/gpu/drm/drm_crtc.c                      |  7 +++--
>   drivers/gpu/drm/drm_framebuffer.c               |  7 +++--
>   drivers/gpu/drm/drm_modeset_helper.c            |  7 +++--
>   drivers/gpu/drm/drm_plane.c                     |  7 +++--
>   drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  7 ++---
>   drivers/gpu/drm/i915/i915_debugfs.c             | 10 +++---
>   drivers/gpu/drm/i915/intel_atomic_plane.c       |  8 ++---
>   drivers/gpu/drm/i915/intel_display.c            | 41 ++++++++++---------------
>   drivers/gpu/drm/radeon/atombios_crtc.c          | 14 ++++-----
>   drivers/gpu/drm/vmwgfx/vmwgfx_kms.c             |  3 +-
>   17 files changed, 80 insertions(+), 86 deletions(-)
>
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index dc0aafa..4b03ca0 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -45,6 +45,14 @@ struct drm_format_info {
>   	u8 vsub;
>   };
>   
> +/**
> + * struct drm_format_name_buf - name of a DRM format
> + * @str: string buffer containing the format name
> + */
> +struct drm_format_name_buf {
> +	char str[32];
> +};
> +
>   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);
> @@ -54,6 +62,6 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
>   int drm_format_vert_chroma_subsampling(uint32_t format);
>   int drm_format_plane_width(int width, uint32_t format, int plane);
>   int drm_format_plane_height(int height, uint32_t format, int plane);
> -char *drm_get_format_name(uint32_t format) __malloc;
> +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
>   
>   #endif /* __DRM_FOURCC_H__ */
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index cbb8b77..99b0b60 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -79,17 +79,13 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
>   EXPORT_SYMBOL(drm_mode_legacy_fb_format);
>   
>   /**
> - * drm_get_format_name - return a string for drm fourcc format
> + * drm_get_format_name - fill a string with a drm fourcc format's name
>    * @format: format to compute name of
> + * @buf: caller-supplied buffer
> - *
> - * Note that the buffer returned by this function is owned by the caller
> - * and will need to be freed using kfree().
>    */
> -char *drm_get_format_name(uint32_t format)
> +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf)
>   {
> -	char *buf = kmalloc(32, GFP_KERNEL);
> -
> -	snprintf(buf, 32,
> +	snprintf(buf->str, sizeof(buf->str),
>   		 "%c%c%c%c %s-endian (0x%08x)",
>   		 printable_char(format & 0xff),
>   		 printable_char((format >> 8) & 0xff),
> @@ -98,7 +94,7 @@ char *drm_get_format_name(uint32_t format)
>   		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
>   		 format);
>   
> -	return buf;
> +	return buf->str;
>   }
>   EXPORT_SYMBOL(drm_get_format_name);
>   
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> index 199d3f7..2924cdd 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>   		return -EINVAL;
>   	}
>   
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> index ecd000e..f0e3c5c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>   		return -EINVAL;
>   	}
>   
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> index 44547f9..5c6b82f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> @@ -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;
>   	}
>   
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> index 979aedf..5aef19d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>   		return -EINVAL;
>   	}
>   
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index c32fb3c..f29d3c5 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -835,9 +835,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);
> +		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));
> -		kfree(format_name);
>   		return ret;
>   	}
>   
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 13441e2..08ac216 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -827,9 +827,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
>   			ret = drm_plane_check_pixel_format(crtc->primary,
>   							   fb->pixel_format);
>   			if (ret) {
> -				char *format_name = drm_get_format_name(fb->pixel_format);
> -				DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> +				struct drm_format_name_buf format_name;
> +				DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +				              drm_get_format_name(fb->pixel_format,
> +				                                  &format_name));
> -				kfree(format_name);
>   				goto out;
>   			}
>   		}
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 49fd7db..df6b180 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -133,9 +133,10 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
>   
>   	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);
> +		struct drm_format_name_buf format_name;
> +		DRM_DEBUG_KMS("bad framebuffer format %s\n",
> +		              drm_get_format_name(r->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>   		return -EINVAL;
>   	}
>   
> diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c
> index 2544dfe..2f452b3 100644
> --- a/drivers/gpu/drm/drm_modeset_helper.c
> +++ b/drivers/gpu/drm/drm_modeset_helper.c
> @@ -75,10 +75,11 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
>   
>   	info = drm_format_info(mode_cmd->pixel_format);
>   	if (!info || !info->depth) {
> -		char *format_name = drm_get_format_name(mode_cmd->pixel_format);
> +		struct drm_format_name_buf format_name;
>   
> -		DRM_DEBUG_KMS("non-RGB pixel format %s\n", format_name);
> +		DRM_DEBUG_KMS("non-RGB pixel format %s\n",
> +		              drm_get_format_name(mode_cmd->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>   
>   		fb->depth = 0;
>   		fb->bits_per_pixel = 0;
> diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
> index 249c0ae..2ba0c22 100644
> --- a/drivers/gpu/drm/drm_plane.c
> +++ b/drivers/gpu/drm/drm_plane.c
> @@ -479,9 +479,10 @@ static int __setplane_internal(struct drm_plane *plane,
>   	/* Check whether this plane supports the fb pixel format. */
>   	ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
>   	if (ret) {
> -		char *format_name = drm_get_format_name(fb->pixel_format);
> -		DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> +		struct drm_format_name_buf format_name;
> +		DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +		              drm_get_format_name(fb->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>   		goto out;
>   	}
>   
> diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> index 7e7a4d4..afc2b5d 100644
> --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> @@ -608,17 +608,16 @@ static void ade_rdma_set(void __iomem *base, struct drm_framebuffer *fb,
>   			 u32 ch, u32 y, u32 in_h, u32 fmt)
>   {
>   	struct drm_gem_cma_object *obj = drm_fb_cma_get_gem_obj(fb, 0);
> -	char *format_name;
> +	struct drm_format_name_buf format_name;
>   	u32 reg_ctrl, reg_addr, reg_size, reg_stride, reg_space, reg_en;
>   	u32 stride = fb->pitches[0];
>   	u32 addr = (u32)obj->paddr + y * stride;
>   
>   	DRM_DEBUG_DRIVER("rdma%d: (y=%d, height=%d), stride=%d, paddr=0x%x\n",
>   			 ch + 1, y, in_h, stride, (u32)obj->paddr);
> -	format_name = drm_get_format_name(fb->pixel_format);
>   	DRM_DEBUG_DRIVER("addr=0x%x, fb:%dx%d, pixel_format=%d(%s)\n",
> -			 addr, fb->width, fb->height, fmt, format_name);
> +			 addr, fb->width, fb->height, fmt,
> +			 drm_get_format_name(fb->pixel_format, &format_name));
> -	kfree(format_name);
>   
>   	/* get reg offset */
>   	reg_ctrl = RD_CH_CTRL(ch);
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index 20638d2..670423e 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -2971,7 +2971,7 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>   	for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
>   		struct drm_plane_state *state;
>   		struct drm_plane *plane = &intel_plane->base;
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>   
>   		if (!plane->state) {
>   			seq_puts(m, "plane->state is NULL!\n");
> @@ -2981,9 +2981,9 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>   		state = plane->state;
>   
>   		if (state->fb) {
> -			format_name = drm_get_format_name(state->fb->pixel_format);
> +			drm_get_format_name(state->fb->pixel_format, &format_name);
>   		} else {
> -			format_name = kstrdup("N/A", GFP_KERNEL);
> +			sprintf(format_name.str, "N/A");
>   		}
>   
>   		seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
> @@ -2999,10 +2999,8 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>   			   ((state->src_w & 0xffff) * 15625) >> 10,
>   			   (state->src_h >> 16),
>   			   ((state->src_h & 0xffff) * 15625) >> 10,
> -			   format_name,
> +			   format_name.str,
>   			   plane_rotation(state->rotation));
> -
> -		kfree(format_name);
>   	}
>   }
>   
> diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c b/drivers/gpu/drm/i915/intel_atomic_plane.c
> index c762ae5..6c76e3d 100644
> --- a/drivers/gpu/drm/i915/intel_atomic_plane.c
> +++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
> @@ -143,7 +143,7 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>   		crtc_state->base.enable ? crtc_state->pipe_src_h : 0;
>   
>   	if (state->fb && drm_rotation_90_or_270(state->rotation)) {
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>   
>   		if (!(state->fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
>   			state->fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED)) {
> @@ -159,9 +159,9 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>   		switch (state->fb->pixel_format) {
>   		case DRM_FORMAT_C8:
>   		case DRM_FORMAT_RGB565:
> -			format_name = drm_get_format_name(state->fb->pixel_format);
> -			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n", format_name);
> +			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
> +			              drm_get_format_name(state->fb->pixel_format,
> +			                                  &format_name));
> -			kfree(format_name);
>   			return -EINVAL;
>   
>   		default:
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 6f8f6ec..8209170 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -12871,7 +12871,7 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>   
>   	DRM_DEBUG_KMS("planes on this crtc\n");
>   	list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>   		intel_plane = to_intel_plane(plane);
>   		if (intel_plane->pipe != crtc->pipe)
>   			continue;
> @@ -12884,12 +12884,11 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>   			continue;
>   		}
>   
> -		format_name = drm_get_format_name(fb->pixel_format);
> -
>   		DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
>   			      plane->base.id, plane->name);
>   		DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
> -			      fb->base.id, fb->width, fb->height, format_name);
> +			      fb->base.id, fb->width, fb->height,
> +			      drm_get_format_name(fb->pixel_format, &format_name));
>   		DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
>   			      state->scaler_id,
>   			      state->base.src.x1 >> 16,
> @@ -12899,8 +12898,6 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>   			      state->base.dst.x1, state->base.dst.y1,
>   			      drm_rect_width(&state->base.dst),
>   			      drm_rect_height(&state->base.dst));
> -
> -		kfree(format_name);
>   	}
>   }
>   
> @@ -15749,7 +15746,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
>   	unsigned int tiling = i915_gem_object_get_tiling(obj);
>   	int ret;
>   	u32 pitch_limit, stride_alignment;
> -	char *format_name;
> +	struct drm_format_name_buf format_name;
>   
>   	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
>   
> @@ -15840,18 +15837,16 @@ static int intel_framebuffer_init(struct drm_device *dev,
>   		break;
>   	case DRM_FORMAT_XRGB1555:
>   		if (INTEL_INFO(dev)->gen > 3) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>   			return -EINVAL;
>   		}
>   		break;
>   	case DRM_FORMAT_ABGR8888:
>   		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
>   		    INTEL_INFO(dev)->gen < 9) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>   			return -EINVAL;
>   		}
>   		break;
> @@ -15859,17 +15854,15 @@ static int intel_framebuffer_init(struct drm_device *dev,
>   	case DRM_FORMAT_XRGB2101010:
>   	case DRM_FORMAT_XBGR2101010:
>   		if (INTEL_INFO(dev)->gen < 4) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>   			return -EINVAL;
>   		}
>   		break;
>   	case DRM_FORMAT_ABGR2101010:
>   		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>   			return -EINVAL;
>   		}
>   		break;
> @@ -15878,16 +15871,14 @@ static int intel_framebuffer_init(struct drm_device *dev,
>   	case DRM_FORMAT_YVYU:
>   	case DRM_FORMAT_VYUY:
>   		if (INTEL_INFO(dev)->gen < 5) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>   			return -EINVAL;
>   		}
>   		break;
>   	default:
> -		format_name = drm_get_format_name(mode_cmd->pixel_format);
> -		DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +		DRM_DEBUG("unsupported pixel format: %s\n",
> +		          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -		kfree(format_name);
>   		return -EINVAL;
>   	}
>   
> diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
> index 74f99ba..05f4ebe 100644
> --- a/drivers/gpu/drm/radeon/atombios_crtc.c
> +++ b/drivers/gpu/drm/radeon/atombios_crtc.c
> @@ -1156,7 +1156,7 @@ static int dce4_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) {
> @@ -1260,9 +1260,8 @@ static int dce4_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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>   		return -EINVAL;
>   	}
>   
> @@ -1473,7 +1472,7 @@ static int avivo_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) {
> @@ -1563,9 +1562,8 @@ static int avivo_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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>   		return -EINVAL;
>   	}
>   
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> index c965514..e3f68cc 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> @@ -985,8 +985,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
>   
>   	info = drm_format_info(mode_cmd2->pixel_format);
>   	if (!info || !info->depth) {
> +		struct drm_format_name_buf format_name;
>   		DRM_ERROR("Unsupported framebuffer format %s\n",
> -			  drm_get_format_name(mode_cmd2->pixel_format));
> +		          drm_get_format_name(mode_cmd2->pixel_format, &format_name));
>   		return ERR_PTR(-EINVAL);
>   	}
>   

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2] drm: move allocation out of drm_get_format_name()
  2016-11-07  0:48               ` [PATCH v2] " Eric Engestrom
  2016-11-07  7:46                 ` Christian König
@ 2016-11-07  8:10                 ` Jani Nikula
  2016-11-07 17:12                   ` Eric Engestrom
  2016-11-07 14:45                 ` [PATCH v2] " Rob Clark
  2016-11-07 18:12                 ` Sinclair Yeh
  3 siblings, 1 reply; 28+ messages in thread
From: Jani Nikula @ 2016-11-07  8:10 UTC (permalink / raw)
  To: Eric Engestrom, linux-kernel
  Cc: Ville Syrjälä,
	Eric Engestrom, Rob Clark, Christian König, Alex Deucher,
	David Airlie, Xinliang Liu, Daniel Vetter, VMware Graphics,
	Sinclair Yeh, Thomas Hellstrom, Tom St Denis, Michel Dänzer,
	Gustavo Padovan, Emily Deng, Chunming Zhou, Flora Cui,
	Vitaly Prosyak, Colin Ian King, Ken Wang, Alexandre Demers,
	Eric Engestrom, Junwei Zhang, Xinwei Kong, Wei Yongjun,
	Chris Wilson, Laurent Pinchart, dri-devel, intel-gfx

On Mon, 07 Nov 2016, Eric Engestrom <eric@engestrom.ch> wrote:
> Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07
>
>     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>

The Fixes: format is:

Fixes: 90844f00049e ("drm: make drm_get_format_name thread-safe")

But is this a fix, really, or just an improvement? What exactly is the
bug being fixed? The commit message is not sufficient.

> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Christian König <christian.koenig@amd.com>
> Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Eric Engestrom <eric@engestrom.ch>
> ---
>
> v2: use single-field struct instead of typedef to let the compiler
>     enforce the type (Christian König)

Just to make it clear: NAK three times over for v1. This patch is
definitely a better alternative.

>
> ---
>  include/drm/drm_fourcc.h                        | 10 +++++-
>  drivers/gpu/drm/drm_fourcc.c                    | 14 +++------
>  drivers/gpu/drm/amd/amdgpu/dce_v10_0.c          |  7 ++---
>  drivers/gpu/drm/amd/amdgpu/dce_v11_0.c          |  7 ++---
>  drivers/gpu/drm/amd/amdgpu/dce_v6_0.c           |  3 +-
>  drivers/gpu/drm/amd/amdgpu/dce_v8_0.c           |  7 ++---
>  drivers/gpu/drm/drm_atomic.c                    |  7 +++--
>  drivers/gpu/drm/drm_crtc.c                      |  7 +++--
>  drivers/gpu/drm/drm_framebuffer.c               |  7 +++--
>  drivers/gpu/drm/drm_modeset_helper.c            |  7 +++--
>  drivers/gpu/drm/drm_plane.c                     |  7 +++--
>  drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  7 ++---
>  drivers/gpu/drm/i915/i915_debugfs.c             | 10 +++---
>  drivers/gpu/drm/i915/intel_atomic_plane.c       |  8 ++---
>  drivers/gpu/drm/i915/intel_display.c            | 41 ++++++++++---------------
>  drivers/gpu/drm/radeon/atombios_crtc.c          | 14 ++++-----
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c             |  3 +-
>  17 files changed, 80 insertions(+), 86 deletions(-)
>
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index dc0aafa..4b03ca0 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -45,6 +45,14 @@ struct drm_format_info {
>  	u8 vsub;
>  };
>  
> +/**
> + * struct drm_format_name_buf - name of a DRM format
> + * @str: string buffer containing the format name
> + */
> +struct drm_format_name_buf {
> +	char str[32];
> +};
> +
>  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);
> @@ -54,6 +62,6 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
>  int drm_format_vert_chroma_subsampling(uint32_t format);
>  int drm_format_plane_width(int width, uint32_t format, int plane);
>  int drm_format_plane_height(int height, uint32_t format, int plane);
> -char *drm_get_format_name(uint32_t format) __malloc;
> +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);

I wonder if it would be better to make that return "const char *". If
the user really wants to look under the hood, there's buf->str. *shrug*

With the commit message improved,

Reviewed-by: Jani Nikula <jani.nikula@intel.com>

>  
>  #endif /* __DRM_FOURCC_H__ */
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index cbb8b77..99b0b60 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -79,17 +79,13 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
>  EXPORT_SYMBOL(drm_mode_legacy_fb_format);
>  
>  /**
> - * drm_get_format_name - return a string for drm fourcc format
> + * drm_get_format_name - fill a string with a drm fourcc format's name
>   * @format: format to compute name of
> + * @buf: caller-supplied buffer
> - *
> - * Note that the buffer returned by this function is owned by the caller
> - * and will need to be freed using kfree().
>   */
> -char *drm_get_format_name(uint32_t format)
> +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf)
>  {
> -	char *buf = kmalloc(32, GFP_KERNEL);
> -
> -	snprintf(buf, 32,
> +	snprintf(buf->str, sizeof(buf->str),
>  		 "%c%c%c%c %s-endian (0x%08x)",
>  		 printable_char(format & 0xff),
>  		 printable_char((format >> 8) & 0xff),
> @@ -98,7 +94,7 @@ char *drm_get_format_name(uint32_t format)
>  		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
>  		 format);
>  
> -	return buf;
> +	return buf->str;
>  }
>  EXPORT_SYMBOL(drm_get_format_name);
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> index 199d3f7..2924cdd 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> index ecd000e..f0e3c5c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> index 44547f9..5c6b82f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> @@ -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;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> index 979aedf..5aef19d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index c32fb3c..f29d3c5 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -835,9 +835,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);
> +		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));
> -		kfree(format_name);
>  		return ret;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 13441e2..08ac216 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -827,9 +827,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
>  			ret = drm_plane_check_pixel_format(crtc->primary,
>  							   fb->pixel_format);
>  			if (ret) {
> -				char *format_name = drm_get_format_name(fb->pixel_format);
> -				DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> +				struct drm_format_name_buf format_name;
> +				DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +				              drm_get_format_name(fb->pixel_format,
> +				                                  &format_name));
> -				kfree(format_name);
>  				goto out;
>  			}
>  		}
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 49fd7db..df6b180 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -133,9 +133,10 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
>  
>  	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);
> +		struct drm_format_name_buf format_name;
> +		DRM_DEBUG_KMS("bad framebuffer format %s\n",
> +		              drm_get_format_name(r->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c
> index 2544dfe..2f452b3 100644
> --- a/drivers/gpu/drm/drm_modeset_helper.c
> +++ b/drivers/gpu/drm/drm_modeset_helper.c
> @@ -75,10 +75,11 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
>  
>  	info = drm_format_info(mode_cmd->pixel_format);
>  	if (!info || !info->depth) {
> -		char *format_name = drm_get_format_name(mode_cmd->pixel_format);
> +		struct drm_format_name_buf format_name;
>  
> -		DRM_DEBUG_KMS("non-RGB pixel format %s\n", format_name);
> +		DRM_DEBUG_KMS("non-RGB pixel format %s\n",
> +		              drm_get_format_name(mode_cmd->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>  
>  		fb->depth = 0;
>  		fb->bits_per_pixel = 0;
> diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
> index 249c0ae..2ba0c22 100644
> --- a/drivers/gpu/drm/drm_plane.c
> +++ b/drivers/gpu/drm/drm_plane.c
> @@ -479,9 +479,10 @@ static int __setplane_internal(struct drm_plane *plane,
>  	/* Check whether this plane supports the fb pixel format. */
>  	ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
>  	if (ret) {
> -		char *format_name = drm_get_format_name(fb->pixel_format);
> -		DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> +		struct drm_format_name_buf format_name;
> +		DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +		              drm_get_format_name(fb->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>  		goto out;
>  	}
>  
> diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> index 7e7a4d4..afc2b5d 100644
> --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> @@ -608,17 +608,16 @@ static void ade_rdma_set(void __iomem *base, struct drm_framebuffer *fb,
>  			 u32 ch, u32 y, u32 in_h, u32 fmt)
>  {
>  	struct drm_gem_cma_object *obj = drm_fb_cma_get_gem_obj(fb, 0);
> -	char *format_name;
> +	struct drm_format_name_buf format_name;
>  	u32 reg_ctrl, reg_addr, reg_size, reg_stride, reg_space, reg_en;
>  	u32 stride = fb->pitches[0];
>  	u32 addr = (u32)obj->paddr + y * stride;
>  
>  	DRM_DEBUG_DRIVER("rdma%d: (y=%d, height=%d), stride=%d, paddr=0x%x\n",
>  			 ch + 1, y, in_h, stride, (u32)obj->paddr);
> -	format_name = drm_get_format_name(fb->pixel_format);
>  	DRM_DEBUG_DRIVER("addr=0x%x, fb:%dx%d, pixel_format=%d(%s)\n",
> -			 addr, fb->width, fb->height, fmt, format_name);
> +			 addr, fb->width, fb->height, fmt,
> +			 drm_get_format_name(fb->pixel_format, &format_name));
> -	kfree(format_name);
>  
>  	/* get reg offset */
>  	reg_ctrl = RD_CH_CTRL(ch);
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index 20638d2..670423e 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -2971,7 +2971,7 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  	for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
>  		struct drm_plane_state *state;
>  		struct drm_plane *plane = &intel_plane->base;
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>  
>  		if (!plane->state) {
>  			seq_puts(m, "plane->state is NULL!\n");
> @@ -2981,9 +2981,9 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  		state = plane->state;
>  
>  		if (state->fb) {
> -			format_name = drm_get_format_name(state->fb->pixel_format);
> +			drm_get_format_name(state->fb->pixel_format, &format_name);
>  		} else {
> -			format_name = kstrdup("N/A", GFP_KERNEL);
> +			sprintf(format_name.str, "N/A");
>  		}
>  
>  		seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
> @@ -2999,10 +2999,8 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  			   ((state->src_w & 0xffff) * 15625) >> 10,
>  			   (state->src_h >> 16),
>  			   ((state->src_h & 0xffff) * 15625) >> 10,
> -			   format_name,
> +			   format_name.str,
>  			   plane_rotation(state->rotation));
> -
> -		kfree(format_name);
>  	}
>  }
>  
> diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c b/drivers/gpu/drm/i915/intel_atomic_plane.c
> index c762ae5..6c76e3d 100644
> --- a/drivers/gpu/drm/i915/intel_atomic_plane.c
> +++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
> @@ -143,7 +143,7 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>  		crtc_state->base.enable ? crtc_state->pipe_src_h : 0;
>  
>  	if (state->fb && drm_rotation_90_or_270(state->rotation)) {
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>  
>  		if (!(state->fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
>  			state->fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED)) {
> @@ -159,9 +159,9 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>  		switch (state->fb->pixel_format) {
>  		case DRM_FORMAT_C8:
>  		case DRM_FORMAT_RGB565:
> -			format_name = drm_get_format_name(state->fb->pixel_format);
> -			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n", format_name);
> +			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
> +			              drm_get_format_name(state->fb->pixel_format,
> +			                                  &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  
>  		default:
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 6f8f6ec..8209170 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -12871,7 +12871,7 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  
>  	DRM_DEBUG_KMS("planes on this crtc\n");
>  	list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>  		intel_plane = to_intel_plane(plane);
>  		if (intel_plane->pipe != crtc->pipe)
>  			continue;
> @@ -12884,12 +12884,11 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  			continue;
>  		}
>  
> -		format_name = drm_get_format_name(fb->pixel_format);
> -
>  		DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
>  			      plane->base.id, plane->name);
>  		DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
> -			      fb->base.id, fb->width, fb->height, format_name);
> +			      fb->base.id, fb->width, fb->height,
> +			      drm_get_format_name(fb->pixel_format, &format_name));
>  		DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
>  			      state->scaler_id,
>  			      state->base.src.x1 >> 16,
> @@ -12899,8 +12898,6 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  			      state->base.dst.x1, state->base.dst.y1,
>  			      drm_rect_width(&state->base.dst),
>  			      drm_rect_height(&state->base.dst));
> -
> -		kfree(format_name);
>  	}
>  }
>  
> @@ -15749,7 +15746,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	unsigned int tiling = i915_gem_object_get_tiling(obj);
>  	int ret;
>  	u32 pitch_limit, stride_alignment;
> -	char *format_name;
> +	struct drm_format_name_buf format_name;
>  
>  	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
>  
> @@ -15840,18 +15837,16 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  		break;
>  	case DRM_FORMAT_XRGB1555:
>  		if (INTEL_INFO(dev)->gen > 3) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
>  	case DRM_FORMAT_ABGR8888:
>  		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
>  		    INTEL_INFO(dev)->gen < 9) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
> @@ -15859,17 +15854,15 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	case DRM_FORMAT_XRGB2101010:
>  	case DRM_FORMAT_XBGR2101010:
>  		if (INTEL_INFO(dev)->gen < 4) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
>  	case DRM_FORMAT_ABGR2101010:
>  		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
> @@ -15878,16 +15871,14 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	case DRM_FORMAT_YVYU:
>  	case DRM_FORMAT_VYUY:
>  		if (INTEL_INFO(dev)->gen < 5) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
>  	default:
> -		format_name = drm_get_format_name(mode_cmd->pixel_format);
> -		DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +		DRM_DEBUG("unsupported pixel format: %s\n",
> +		          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
> index 74f99ba..05f4ebe 100644
> --- a/drivers/gpu/drm/radeon/atombios_crtc.c
> +++ b/drivers/gpu/drm/radeon/atombios_crtc.c
> @@ -1156,7 +1156,7 @@ static int dce4_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) {
> @@ -1260,9 +1260,8 @@ static int dce4_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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> @@ -1473,7 +1472,7 @@ static int avivo_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) {
> @@ -1563,9 +1562,8 @@ static int avivo_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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> index c965514..e3f68cc 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> @@ -985,8 +985,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
>  
>  	info = drm_format_info(mode_cmd2->pixel_format);
>  	if (!info || !info->depth) {
> +		struct drm_format_name_buf format_name;
>  		DRM_ERROR("Unsupported framebuffer format %s\n",
> -			  drm_get_format_name(mode_cmd2->pixel_format));
> +		          drm_get_format_name(mode_cmd2->pixel_format, &format_name));
>  		return ERR_PTR(-EINVAL);
>  	}

-- 
Jani Nikula, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2] drm: move allocation out of drm_get_format_name()
  2016-11-07  0:48               ` [PATCH v2] " Eric Engestrom
  2016-11-07  7:46                 ` Christian König
  2016-11-07  8:10                 ` Jani Nikula
@ 2016-11-07 14:45                 ` Rob Clark
  2016-11-07 18:12                 ` Sinclair Yeh
  3 siblings, 0 replies; 28+ messages in thread
From: Rob Clark @ 2016-11-07 14:45 UTC (permalink / raw)
  To: Eric Engestrom
  Cc: Linux Kernel Mailing List, Ville Syrjälä,
	Christian König, Alex Deucher, David Airlie, Xinliang Liu,
	Daniel Vetter, Jani Nikula, VMware Graphics, Sinclair Yeh,
	Thomas Hellstrom, Tom St Denis, Michel Dänzer,
	Gustavo Padovan, Emily Deng, Chunming Zhou, Flora Cui,
	Vitaly Prosyak, Colin Ian King, Ken Wang, Alexandre Demers,
	Eric Engestrom, Junwei Zhang, Xinwei Kong, Wei Yongjun,
	Chris Wilson, Laurent Pinchart, dri-devel,
	Intel Graphics Development

On Sun, Nov 6, 2016 at 7:48 PM, Eric Engestrom <eric@engestrom.ch> wrote:
> Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07
>
>     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>
>
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Christian König <christian.koenig@amd.com>
> Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Eric Engestrom <eric@engestrom.ch>

Thanks,

Acked-by: Rob Clark <robdclark@gmail.com>

> ---
>
> v2: use single-field struct instead of typedef to let the compiler
>     enforce the type (Christian König)
>
> ---
>  include/drm/drm_fourcc.h                        | 10 +++++-
>  drivers/gpu/drm/drm_fourcc.c                    | 14 +++------
>  drivers/gpu/drm/amd/amdgpu/dce_v10_0.c          |  7 ++---
>  drivers/gpu/drm/amd/amdgpu/dce_v11_0.c          |  7 ++---
>  drivers/gpu/drm/amd/amdgpu/dce_v6_0.c           |  3 +-
>  drivers/gpu/drm/amd/amdgpu/dce_v8_0.c           |  7 ++---
>  drivers/gpu/drm/drm_atomic.c                    |  7 +++--
>  drivers/gpu/drm/drm_crtc.c                      |  7 +++--
>  drivers/gpu/drm/drm_framebuffer.c               |  7 +++--
>  drivers/gpu/drm/drm_modeset_helper.c            |  7 +++--
>  drivers/gpu/drm/drm_plane.c                     |  7 +++--
>  drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  7 ++---
>  drivers/gpu/drm/i915/i915_debugfs.c             | 10 +++---
>  drivers/gpu/drm/i915/intel_atomic_plane.c       |  8 ++---
>  drivers/gpu/drm/i915/intel_display.c            | 41 ++++++++++---------------
>  drivers/gpu/drm/radeon/atombios_crtc.c          | 14 ++++-----
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c             |  3 +-
>  17 files changed, 80 insertions(+), 86 deletions(-)
>
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index dc0aafa..4b03ca0 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -45,6 +45,14 @@ struct drm_format_info {
>         u8 vsub;
>  };
>
> +/**
> + * struct drm_format_name_buf - name of a DRM format
> + * @str: string buffer containing the format name
> + */
> +struct drm_format_name_buf {
> +       char str[32];
> +};
> +
>  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);
> @@ -54,6 +62,6 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
>  int drm_format_vert_chroma_subsampling(uint32_t format);
>  int drm_format_plane_width(int width, uint32_t format, int plane);
>  int drm_format_plane_height(int height, uint32_t format, int plane);
> -char *drm_get_format_name(uint32_t format) __malloc;
> +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
>
>  #endif /* __DRM_FOURCC_H__ */
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index cbb8b77..99b0b60 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -79,17 +79,13 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
>  EXPORT_SYMBOL(drm_mode_legacy_fb_format);
>
>  /**
> - * drm_get_format_name - return a string for drm fourcc format
> + * drm_get_format_name - fill a string with a drm fourcc format's name
>   * @format: format to compute name of
> + * @buf: caller-supplied buffer
> - *
> - * Note that the buffer returned by this function is owned by the caller
> - * and will need to be freed using kfree().
>   */
> -char *drm_get_format_name(uint32_t format)
> +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf)
>  {
> -       char *buf = kmalloc(32, GFP_KERNEL);
> -
> -       snprintf(buf, 32,
> +       snprintf(buf->str, sizeof(buf->str),
>                  "%c%c%c%c %s-endian (0x%08x)",
>                  printable_char(format & 0xff),
>                  printable_char((format >> 8) & 0xff),
> @@ -98,7 +94,7 @@ char *drm_get_format_name(uint32_t format)
>                  format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
>                  format);
>
> -       return buf;
> +       return buf->str;
>  }
>  EXPORT_SYMBOL(drm_get_format_name);
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> index 199d3f7..2924cdd 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> @@ -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);
> +               DRM_ERROR("Unsupported screen format %s\n",
> +                         drm_get_format_name(target_fb->pixel_format, &format_name));
> -               kfree(format_name);
>                 return -EINVAL;
>         }
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> index ecd000e..f0e3c5c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> @@ -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);
> +               DRM_ERROR("Unsupported screen format %s\n",
> +                         drm_get_format_name(target_fb->pixel_format, &format_name));
> -               kfree(format_name);
>                 return -EINVAL;
>         }
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> index 44547f9..5c6b82f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> @@ -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;
>         }
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> index 979aedf..5aef19d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> @@ -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);
> +               DRM_ERROR("Unsupported screen format %s\n",
> +                         drm_get_format_name(target_fb->pixel_format, &format_name));
> -               kfree(format_name);
>                 return -EINVAL;
>         }
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index c32fb3c..f29d3c5 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -835,9 +835,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);
> +               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));
> -               kfree(format_name);
>                 return ret;
>         }
>
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 13441e2..08ac216 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -827,9 +827,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
>                         ret = drm_plane_check_pixel_format(crtc->primary,
>                                                            fb->pixel_format);
>                         if (ret) {
> -                               char *format_name = drm_get_format_name(fb->pixel_format);
> -                               DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> +                               struct drm_format_name_buf format_name;
> +                               DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +                                             drm_get_format_name(fb->pixel_format,
> +                                                                 &format_name));
> -                               kfree(format_name);
>                                 goto out;
>                         }
>                 }
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 49fd7db..df6b180 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -133,9 +133,10 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
>
>         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);
> +               struct drm_format_name_buf format_name;
> +               DRM_DEBUG_KMS("bad framebuffer format %s\n",
> +                             drm_get_format_name(r->pixel_format,
> +                                                 &format_name));
> -               kfree(format_name);
>                 return -EINVAL;
>         }
>
> diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c
> index 2544dfe..2f452b3 100644
> --- a/drivers/gpu/drm/drm_modeset_helper.c
> +++ b/drivers/gpu/drm/drm_modeset_helper.c
> @@ -75,10 +75,11 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
>
>         info = drm_format_info(mode_cmd->pixel_format);
>         if (!info || !info->depth) {
> -               char *format_name = drm_get_format_name(mode_cmd->pixel_format);
> +               struct drm_format_name_buf format_name;
>
> -               DRM_DEBUG_KMS("non-RGB pixel format %s\n", format_name);
> +               DRM_DEBUG_KMS("non-RGB pixel format %s\n",
> +                             drm_get_format_name(mode_cmd->pixel_format,
> +                                                 &format_name));
> -               kfree(format_name);
>
>                 fb->depth = 0;
>                 fb->bits_per_pixel = 0;
> diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
> index 249c0ae..2ba0c22 100644
> --- a/drivers/gpu/drm/drm_plane.c
> +++ b/drivers/gpu/drm/drm_plane.c
> @@ -479,9 +479,10 @@ static int __setplane_internal(struct drm_plane *plane,
>         /* Check whether this plane supports the fb pixel format. */
>         ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
>         if (ret) {
> -               char *format_name = drm_get_format_name(fb->pixel_format);
> -               DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> +               struct drm_format_name_buf format_name;
> +               DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +                             drm_get_format_name(fb->pixel_format,
> +                                                 &format_name));
> -               kfree(format_name);
>                 goto out;
>         }
>
> diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> index 7e7a4d4..afc2b5d 100644
> --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> @@ -608,17 +608,16 @@ static void ade_rdma_set(void __iomem *base, struct drm_framebuffer *fb,
>                          u32 ch, u32 y, u32 in_h, u32 fmt)
>  {
>         struct drm_gem_cma_object *obj = drm_fb_cma_get_gem_obj(fb, 0);
> -       char *format_name;
> +       struct drm_format_name_buf format_name;
>         u32 reg_ctrl, reg_addr, reg_size, reg_stride, reg_space, reg_en;
>         u32 stride = fb->pitches[0];
>         u32 addr = (u32)obj->paddr + y * stride;
>
>         DRM_DEBUG_DRIVER("rdma%d: (y=%d, height=%d), stride=%d, paddr=0x%x\n",
>                          ch + 1, y, in_h, stride, (u32)obj->paddr);
> -       format_name = drm_get_format_name(fb->pixel_format);
>         DRM_DEBUG_DRIVER("addr=0x%x, fb:%dx%d, pixel_format=%d(%s)\n",
> -                        addr, fb->width, fb->height, fmt, format_name);
> +                        addr, fb->width, fb->height, fmt,
> +                        drm_get_format_name(fb->pixel_format, &format_name));
> -       kfree(format_name);
>
>         /* get reg offset */
>         reg_ctrl = RD_CH_CTRL(ch);
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index 20638d2..670423e 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -2971,7 +2971,7 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>         for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
>                 struct drm_plane_state *state;
>                 struct drm_plane *plane = &intel_plane->base;
> -               char *format_name;
> +               struct drm_format_name_buf format_name;
>
>                 if (!plane->state) {
>                         seq_puts(m, "plane->state is NULL!\n");
> @@ -2981,9 +2981,9 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>                 state = plane->state;
>
>                 if (state->fb) {
> -                       format_name = drm_get_format_name(state->fb->pixel_format);
> +                       drm_get_format_name(state->fb->pixel_format, &format_name);
>                 } else {
> -                       format_name = kstrdup("N/A", GFP_KERNEL);
> +                       sprintf(format_name.str, "N/A");
>                 }
>
>                 seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
> @@ -2999,10 +2999,8 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>                            ((state->src_w & 0xffff) * 15625) >> 10,
>                            (state->src_h >> 16),
>                            ((state->src_h & 0xffff) * 15625) >> 10,
> -                          format_name,
> +                          format_name.str,
>                            plane_rotation(state->rotation));
> -
> -               kfree(format_name);
>         }
>  }
>
> diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c b/drivers/gpu/drm/i915/intel_atomic_plane.c
> index c762ae5..6c76e3d 100644
> --- a/drivers/gpu/drm/i915/intel_atomic_plane.c
> +++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
> @@ -143,7 +143,7 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>                 crtc_state->base.enable ? crtc_state->pipe_src_h : 0;
>
>         if (state->fb && drm_rotation_90_or_270(state->rotation)) {
> -               char *format_name;
> +               struct drm_format_name_buf format_name;
>
>                 if (!(state->fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
>                         state->fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED)) {
> @@ -159,9 +159,9 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>                 switch (state->fb->pixel_format) {
>                 case DRM_FORMAT_C8:
>                 case DRM_FORMAT_RGB565:
> -                       format_name = drm_get_format_name(state->fb->pixel_format);
> -                       DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n", format_name);
> +                       DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
> +                                     drm_get_format_name(state->fb->pixel_format,
> +                                                         &format_name));
> -                       kfree(format_name);
>                         return -EINVAL;
>
>                 default:
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 6f8f6ec..8209170 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -12871,7 +12871,7 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>
>         DRM_DEBUG_KMS("planes on this crtc\n");
>         list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
> -               char *format_name;
> +               struct drm_format_name_buf format_name;
>                 intel_plane = to_intel_plane(plane);
>                 if (intel_plane->pipe != crtc->pipe)
>                         continue;
> @@ -12884,12 +12884,11 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>                         continue;
>                 }
>
> -               format_name = drm_get_format_name(fb->pixel_format);
> -
>                 DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
>                               plane->base.id, plane->name);
>                 DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
> -                             fb->base.id, fb->width, fb->height, format_name);
> +                             fb->base.id, fb->width, fb->height,
> +                             drm_get_format_name(fb->pixel_format, &format_name));
>                 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
>                               state->scaler_id,
>                               state->base.src.x1 >> 16,
> @@ -12899,8 +12898,6 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>                               state->base.dst.x1, state->base.dst.y1,
>                               drm_rect_width(&state->base.dst),
>                               drm_rect_height(&state->base.dst));
> -
> -               kfree(format_name);
>         }
>  }
>
> @@ -15749,7 +15746,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
>         unsigned int tiling = i915_gem_object_get_tiling(obj);
>         int ret;
>         u32 pitch_limit, stride_alignment;
> -       char *format_name;
> +       struct drm_format_name_buf format_name;
>
>         WARN_ON(!mutex_is_locked(&dev->struct_mutex));
>
> @@ -15840,18 +15837,16 @@ static int intel_framebuffer_init(struct drm_device *dev,
>                 break;
>         case DRM_FORMAT_XRGB1555:
>                 if (INTEL_INFO(dev)->gen > 3) {
> -                       format_name = drm_get_format_name(mode_cmd->pixel_format);
> -                       DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +                       DRM_DEBUG("unsupported pixel format: %s\n",
> +                                 drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -                       kfree(format_name);
>                         return -EINVAL;
>                 }
>                 break;
>         case DRM_FORMAT_ABGR8888:
>                 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
>                     INTEL_INFO(dev)->gen < 9) {
> -                       format_name = drm_get_format_name(mode_cmd->pixel_format);
> -                       DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +                       DRM_DEBUG("unsupported pixel format: %s\n",
> +                                 drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -                       kfree(format_name);
>                         return -EINVAL;
>                 }
>                 break;
> @@ -15859,17 +15854,15 @@ static int intel_framebuffer_init(struct drm_device *dev,
>         case DRM_FORMAT_XRGB2101010:
>         case DRM_FORMAT_XBGR2101010:
>                 if (INTEL_INFO(dev)->gen < 4) {
> -                       format_name = drm_get_format_name(mode_cmd->pixel_format);
> -                       DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +                       DRM_DEBUG("unsupported pixel format: %s\n",
> +                                 drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -                       kfree(format_name);
>                         return -EINVAL;
>                 }
>                 break;
>         case DRM_FORMAT_ABGR2101010:
>                 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
> -                       format_name = drm_get_format_name(mode_cmd->pixel_format);
> -                       DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +                       DRM_DEBUG("unsupported pixel format: %s\n",
> +                                 drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -                       kfree(format_name);
>                         return -EINVAL;
>                 }
>                 break;
> @@ -15878,16 +15871,14 @@ static int intel_framebuffer_init(struct drm_device *dev,
>         case DRM_FORMAT_YVYU:
>         case DRM_FORMAT_VYUY:
>                 if (INTEL_INFO(dev)->gen < 5) {
> -                       format_name = drm_get_format_name(mode_cmd->pixel_format);
> -                       DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +                       DRM_DEBUG("unsupported pixel format: %s\n",
> +                                 drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -                       kfree(format_name);
>                         return -EINVAL;
>                 }
>                 break;
>         default:
> -               format_name = drm_get_format_name(mode_cmd->pixel_format);
> -               DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +               DRM_DEBUG("unsupported pixel format: %s\n",
> +                         drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -               kfree(format_name);
>                 return -EINVAL;
>         }
>
> diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
> index 74f99ba..05f4ebe 100644
> --- a/drivers/gpu/drm/radeon/atombios_crtc.c
> +++ b/drivers/gpu/drm/radeon/atombios_crtc.c
> @@ -1156,7 +1156,7 @@ static int dce4_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) {
> @@ -1260,9 +1260,8 @@ static int dce4_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);
> +               DRM_ERROR("Unsupported screen format %s\n",
> +                         drm_get_format_name(target_fb->pixel_format, &format_name));
> -               kfree(format_name);
>                 return -EINVAL;
>         }
>
> @@ -1473,7 +1472,7 @@ static int avivo_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) {
> @@ -1563,9 +1562,8 @@ static int avivo_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);
> +               DRM_ERROR("Unsupported screen format %s\n",
> +                         drm_get_format_name(target_fb->pixel_format, &format_name));
> -               kfree(format_name);
>                 return -EINVAL;
>         }
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> index c965514..e3f68cc 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> @@ -985,8 +985,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
>
>         info = drm_format_info(mode_cmd2->pixel_format);
>         if (!info || !info->depth) {
> +               struct drm_format_name_buf format_name;
>                 DRM_ERROR("Unsupported framebuffer format %s\n",
> -                         drm_get_format_name(mode_cmd2->pixel_format));
> +                         drm_get_format_name(mode_cmd2->pixel_format, &format_name));
>                 return ERR_PTR(-EINVAL);
>         }
>
> --
> Cheers,
>   Eric
>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2] drm: move allocation out of drm_get_format_name()
  2016-11-07  8:10                 ` Jani Nikula
@ 2016-11-07 17:12                   ` Eric Engestrom
  2016-11-07 17:38                     ` Jani Nikula
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Engestrom @ 2016-11-07 17:12 UTC (permalink / raw)
  To: Jani Nikula
  Cc: Eric Engestrom, linux-kernel, Ville Syrjälä,
	Rob Clark, Christian König, Alex Deucher, David Airlie,
	Xinliang Liu, Daniel Vetter, VMware Graphics, Sinclair Yeh,
	Thomas Hellstrom, Tom St Denis, Michel Dänzer,
	Gustavo Padovan, Emily Deng, Chunming Zhou, Flora Cui,
	Vitaly Prosyak, Colin Ian King, Ken Wang, Alexandre Demers,
	Junwei Zhang, Xinwei Kong, Wei Yongjun, Chris Wilson,
	Laurent Pinchart, dri-devel, intel-gfx

On Monday, 2016-11-07 10:10:13 +0200, Jani Nikula wrote:
> On Mon, 07 Nov 2016, Eric Engestrom <eric@engestrom.ch> wrote:
> > Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07
> >
> >     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>
> 
> The Fixes: format is:
> 
> Fixes: 90844f00049e ("drm: make drm_get_format_name thread-safe")
> 
> But is this a fix, really, or just an improvement? What exactly is the
> bug being fixed? The commit message is not sufficient.

"The function's behaviour was changed in 90844f00049e, 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."

Does this sound good?

> > @@ -54,6 +62,6 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
> >  int drm_format_vert_chroma_subsampling(uint32_t format);
> >  int drm_format_plane_width(int width, uint32_t format, int plane);
> >  int drm_format_plane_height(int height, uint32_t format, int plane);
> > -char *drm_get_format_name(uint32_t format) __malloc;
> > +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
> 
> I wonder if it would be better to make that return "const char *". If
> the user really wants to look under the hood, there's buf->str. *shrug*

Good idea, I'll do that in v3 with the proper commit msg and tags. It'll
have to wait another day though, -ENOTIME and all.

> 
> With the commit message improved,
> 
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>

Cheers :)
  Eric

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2] drm: move allocation out of drm_get_format_name()
  2016-11-07 17:12                   ` Eric Engestrom
@ 2016-11-07 17:38                     ` Jani Nikula
  2016-11-08 10:15                       ` [Intel-gfx] " Daniel Vetter
  0 siblings, 1 reply; 28+ messages in thread
From: Jani Nikula @ 2016-11-07 17:38 UTC (permalink / raw)
  To: Eric Engestrom
  Cc: Eric Engestrom, linux-kernel, Ville Syrjälä,
	Rob Clark, Christian König, Alex Deucher, David Airlie,
	Xinliang Liu, Daniel Vetter, VMware Graphics, Sinclair Yeh,
	Thomas Hellstrom, Tom St Denis, Michel Dänzer,
	Gustavo Padovan, Emily Deng, Chunming Zhou, Flora Cui,
	Vitaly Prosyak, Colin Ian King, Ken Wang, Alexandre Demers,
	Junwei Zhang, Xinwei Kong, Wei Yongjun, Chris Wilson,
	Laurent Pinchart, dri-devel, intel-gfx

On Mon, 07 Nov 2016, Eric Engestrom <eric.engestrom@imgtec.com> wrote:
> On Monday, 2016-11-07 10:10:13 +0200, Jani Nikula wrote:
>> On Mon, 07 Nov 2016, Eric Engestrom <eric@engestrom.ch> wrote:
>> > Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07
>> >
>> >     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>
>> 
>> The Fixes: format is:
>> 
>> Fixes: 90844f00049e ("drm: make drm_get_format_name thread-safe")
>> 
>> But is this a fix, really, or just an improvement? What exactly is the
>> bug being fixed? The commit message is not sufficient.
>
> "The function's behaviour was changed in 90844f00049e, 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."
>
> Does this sound good?

It's fine; no need to go overboard. ;)

BR,
Jani.

>
>> > @@ -54,6 +62,6 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
>> >  int drm_format_vert_chroma_subsampling(uint32_t format);
>> >  int drm_format_plane_width(int width, uint32_t format, int plane);
>> >  int drm_format_plane_height(int height, uint32_t format, int plane);
>> > -char *drm_get_format_name(uint32_t format) __malloc;
>> > +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
>> 
>> I wonder if it would be better to make that return "const char *". If
>> the user really wants to look under the hood, there's buf->str. *shrug*
>
> Good idea, I'll do that in v3 with the proper commit msg and tags. It'll
> have to wait another day though, -ENOTIME and all.
>
>> 
>> With the commit message improved,
>> 
>> Reviewed-by: Jani Nikula <jani.nikula@intel.com>
>
> Cheers :)
>   Eric

-- 
Jani Nikula, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2] drm: move allocation out of drm_get_format_name()
  2016-11-07  0:48               ` [PATCH v2] " Eric Engestrom
                                   ` (2 preceding siblings ...)
  2016-11-07 14:45                 ` [PATCH v2] " Rob Clark
@ 2016-11-07 18:12                 ` Sinclair Yeh
  3 siblings, 0 replies; 28+ messages in thread
From: Sinclair Yeh @ 2016-11-07 18:12 UTC (permalink / raw)
  To: Eric Engestrom
  Cc: linux-kernel, Ville Syrjälä,
	Rob Clark, Christian König, Alex Deucher, David Airlie,
	Xinliang Liu, Daniel Vetter, Jani Nikula, VMware Graphics,
	Thomas Hellstrom, Tom St Denis, Michel Dänzer,
	Gustavo Padovan, Emily Deng, Chunming Zhou, Flora Cui,
	Vitaly Prosyak, Colin Ian King, Ken Wang, Alexandre Demers,
	Eric Engestrom, Junwei Zhang, Xinwei Kong, Wei Yongjun,
	Chris Wilson, Laurent Pinchart, dri-devel, intel-gfx

Thomas has already acked the earlier version, but in case you need
it for this one, too.

vmwgfx portion:  Acked-by: Sinclair Yeh <syeh@vmware.com>

On Mon, Nov 07, 2016 at 12:48:09AM +0000, Eric Engestrom wrote:
> Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07
> 
>     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>
> 
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Christian König <christian.koenig@amd.com>
> Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Eric Engestrom <eric@engestrom.ch>
> ---
> 
> v2: use single-field struct instead of typedef to let the compiler
>     enforce the type (Christian König)
> 
> ---
>  include/drm/drm_fourcc.h                        | 10 +++++-
>  drivers/gpu/drm/drm_fourcc.c                    | 14 +++------
>  drivers/gpu/drm/amd/amdgpu/dce_v10_0.c          |  7 ++---
>  drivers/gpu/drm/amd/amdgpu/dce_v11_0.c          |  7 ++---
>  drivers/gpu/drm/amd/amdgpu/dce_v6_0.c           |  3 +-
>  drivers/gpu/drm/amd/amdgpu/dce_v8_0.c           |  7 ++---
>  drivers/gpu/drm/drm_atomic.c                    |  7 +++--
>  drivers/gpu/drm/drm_crtc.c                      |  7 +++--
>  drivers/gpu/drm/drm_framebuffer.c               |  7 +++--
>  drivers/gpu/drm/drm_modeset_helper.c            |  7 +++--
>  drivers/gpu/drm/drm_plane.c                     |  7 +++--
>  drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  7 ++---
>  drivers/gpu/drm/i915/i915_debugfs.c             | 10 +++---
>  drivers/gpu/drm/i915/intel_atomic_plane.c       |  8 ++---
>  drivers/gpu/drm/i915/intel_display.c            | 41 ++++++++++---------------
>  drivers/gpu/drm/radeon/atombios_crtc.c          | 14 ++++-----
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c             |  3 +-
>  17 files changed, 80 insertions(+), 86 deletions(-)
> 
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index dc0aafa..4b03ca0 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -45,6 +45,14 @@ struct drm_format_info {
>  	u8 vsub;
>  };
>  
> +/**
> + * struct drm_format_name_buf - name of a DRM format
> + * @str: string buffer containing the format name
> + */
> +struct drm_format_name_buf {
> +	char str[32];
> +};
> +
>  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);
> @@ -54,6 +62,6 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
>  int drm_format_vert_chroma_subsampling(uint32_t format);
>  int drm_format_plane_width(int width, uint32_t format, int plane);
>  int drm_format_plane_height(int height, uint32_t format, int plane);
> -char *drm_get_format_name(uint32_t format) __malloc;
> +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
>  
>  #endif /* __DRM_FOURCC_H__ */
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index cbb8b77..99b0b60 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -79,17 +79,13 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
>  EXPORT_SYMBOL(drm_mode_legacy_fb_format);
>  
>  /**
> - * drm_get_format_name - return a string for drm fourcc format
> + * drm_get_format_name - fill a string with a drm fourcc format's name
>   * @format: format to compute name of
> + * @buf: caller-supplied buffer
> - *
> - * Note that the buffer returned by this function is owned by the caller
> - * and will need to be freed using kfree().
>   */
> -char *drm_get_format_name(uint32_t format)
> +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf)
>  {
> -	char *buf = kmalloc(32, GFP_KERNEL);
> -
> -	snprintf(buf, 32,
> +	snprintf(buf->str, sizeof(buf->str),
>  		 "%c%c%c%c %s-endian (0x%08x)",
>  		 printable_char(format & 0xff),
>  		 printable_char((format >> 8) & 0xff),
> @@ -98,7 +94,7 @@ char *drm_get_format_name(uint32_t format)
>  		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
>  		 format);
>  
> -	return buf;
> +	return buf->str;
>  }
>  EXPORT_SYMBOL(drm_get_format_name);
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> index 199d3f7..2924cdd 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> index ecd000e..f0e3c5c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> index 44547f9..5c6b82f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> @@ -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;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> index 979aedf..5aef19d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index c32fb3c..f29d3c5 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -835,9 +835,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);
> +		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));
> -		kfree(format_name);
>  		return ret;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 13441e2..08ac216 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -827,9 +827,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
>  			ret = drm_plane_check_pixel_format(crtc->primary,
>  							   fb->pixel_format);
>  			if (ret) {
> -				char *format_name = drm_get_format_name(fb->pixel_format);
> -				DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> +				struct drm_format_name_buf format_name;
> +				DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +				              drm_get_format_name(fb->pixel_format,
> +				                                  &format_name));
> -				kfree(format_name);
>  				goto out;
>  			}
>  		}
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 49fd7db..df6b180 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -133,9 +133,10 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
>  
>  	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);
> +		struct drm_format_name_buf format_name;
> +		DRM_DEBUG_KMS("bad framebuffer format %s\n",
> +		              drm_get_format_name(r->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c
> index 2544dfe..2f452b3 100644
> --- a/drivers/gpu/drm/drm_modeset_helper.c
> +++ b/drivers/gpu/drm/drm_modeset_helper.c
> @@ -75,10 +75,11 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
>  
>  	info = drm_format_info(mode_cmd->pixel_format);
>  	if (!info || !info->depth) {
> -		char *format_name = drm_get_format_name(mode_cmd->pixel_format);
> +		struct drm_format_name_buf format_name;
>  
> -		DRM_DEBUG_KMS("non-RGB pixel format %s\n", format_name);
> +		DRM_DEBUG_KMS("non-RGB pixel format %s\n",
> +		              drm_get_format_name(mode_cmd->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>  
>  		fb->depth = 0;
>  		fb->bits_per_pixel = 0;
> diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
> index 249c0ae..2ba0c22 100644
> --- a/drivers/gpu/drm/drm_plane.c
> +++ b/drivers/gpu/drm/drm_plane.c
> @@ -479,9 +479,10 @@ static int __setplane_internal(struct drm_plane *plane,
>  	/* Check whether this plane supports the fb pixel format. */
>  	ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
>  	if (ret) {
> -		char *format_name = drm_get_format_name(fb->pixel_format);
> -		DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> +		struct drm_format_name_buf format_name;
> +		DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +		              drm_get_format_name(fb->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>  		goto out;
>  	}
>  
> diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> index 7e7a4d4..afc2b5d 100644
> --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> @@ -608,17 +608,16 @@ static void ade_rdma_set(void __iomem *base, struct drm_framebuffer *fb,
>  			 u32 ch, u32 y, u32 in_h, u32 fmt)
>  {
>  	struct drm_gem_cma_object *obj = drm_fb_cma_get_gem_obj(fb, 0);
> -	char *format_name;
> +	struct drm_format_name_buf format_name;
>  	u32 reg_ctrl, reg_addr, reg_size, reg_stride, reg_space, reg_en;
>  	u32 stride = fb->pitches[0];
>  	u32 addr = (u32)obj->paddr + y * stride;
>  
>  	DRM_DEBUG_DRIVER("rdma%d: (y=%d, height=%d), stride=%d, paddr=0x%x\n",
>  			 ch + 1, y, in_h, stride, (u32)obj->paddr);
> -	format_name = drm_get_format_name(fb->pixel_format);
>  	DRM_DEBUG_DRIVER("addr=0x%x, fb:%dx%d, pixel_format=%d(%s)\n",
> -			 addr, fb->width, fb->height, fmt, format_name);
> +			 addr, fb->width, fb->height, fmt,
> +			 drm_get_format_name(fb->pixel_format, &format_name));
> -	kfree(format_name);
>  
>  	/* get reg offset */
>  	reg_ctrl = RD_CH_CTRL(ch);
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index 20638d2..670423e 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -2971,7 +2971,7 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  	for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
>  		struct drm_plane_state *state;
>  		struct drm_plane *plane = &intel_plane->base;
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>  
>  		if (!plane->state) {
>  			seq_puts(m, "plane->state is NULL!\n");
> @@ -2981,9 +2981,9 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  		state = plane->state;
>  
>  		if (state->fb) {
> -			format_name = drm_get_format_name(state->fb->pixel_format);
> +			drm_get_format_name(state->fb->pixel_format, &format_name);
>  		} else {
> -			format_name = kstrdup("N/A", GFP_KERNEL);
> +			sprintf(format_name.str, "N/A");
>  		}
>  
>  		seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
> @@ -2999,10 +2999,8 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  			   ((state->src_w & 0xffff) * 15625) >> 10,
>  			   (state->src_h >> 16),
>  			   ((state->src_h & 0xffff) * 15625) >> 10,
> -			   format_name,
> +			   format_name.str,
>  			   plane_rotation(state->rotation));
> -
> -		kfree(format_name);
>  	}
>  }
>  
> diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c b/drivers/gpu/drm/i915/intel_atomic_plane.c
> index c762ae5..6c76e3d 100644
> --- a/drivers/gpu/drm/i915/intel_atomic_plane.c
> +++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
> @@ -143,7 +143,7 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>  		crtc_state->base.enable ? crtc_state->pipe_src_h : 0;
>  
>  	if (state->fb && drm_rotation_90_or_270(state->rotation)) {
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>  
>  		if (!(state->fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
>  			state->fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED)) {
> @@ -159,9 +159,9 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>  		switch (state->fb->pixel_format) {
>  		case DRM_FORMAT_C8:
>  		case DRM_FORMAT_RGB565:
> -			format_name = drm_get_format_name(state->fb->pixel_format);
> -			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n", format_name);
> +			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
> +			              drm_get_format_name(state->fb->pixel_format,
> +			                                  &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  
>  		default:
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 6f8f6ec..8209170 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -12871,7 +12871,7 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  
>  	DRM_DEBUG_KMS("planes on this crtc\n");
>  	list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>  		intel_plane = to_intel_plane(plane);
>  		if (intel_plane->pipe != crtc->pipe)
>  			continue;
> @@ -12884,12 +12884,11 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  			continue;
>  		}
>  
> -		format_name = drm_get_format_name(fb->pixel_format);
> -
>  		DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
>  			      plane->base.id, plane->name);
>  		DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
> -			      fb->base.id, fb->width, fb->height, format_name);
> +			      fb->base.id, fb->width, fb->height,
> +			      drm_get_format_name(fb->pixel_format, &format_name));
>  		DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
>  			      state->scaler_id,
>  			      state->base.src.x1 >> 16,
> @@ -12899,8 +12898,6 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  			      state->base.dst.x1, state->base.dst.y1,
>  			      drm_rect_width(&state->base.dst),
>  			      drm_rect_height(&state->base.dst));
> -
> -		kfree(format_name);
>  	}
>  }
>  
> @@ -15749,7 +15746,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	unsigned int tiling = i915_gem_object_get_tiling(obj);
>  	int ret;
>  	u32 pitch_limit, stride_alignment;
> -	char *format_name;
> +	struct drm_format_name_buf format_name;
>  
>  	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
>  
> @@ -15840,18 +15837,16 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  		break;
>  	case DRM_FORMAT_XRGB1555:
>  		if (INTEL_INFO(dev)->gen > 3) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
>  	case DRM_FORMAT_ABGR8888:
>  		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
>  		    INTEL_INFO(dev)->gen < 9) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
> @@ -15859,17 +15854,15 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	case DRM_FORMAT_XRGB2101010:
>  	case DRM_FORMAT_XBGR2101010:
>  		if (INTEL_INFO(dev)->gen < 4) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
>  	case DRM_FORMAT_ABGR2101010:
>  		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
> @@ -15878,16 +15871,14 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	case DRM_FORMAT_YVYU:
>  	case DRM_FORMAT_VYUY:
>  		if (INTEL_INFO(dev)->gen < 5) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
>  	default:
> -		format_name = drm_get_format_name(mode_cmd->pixel_format);
> -		DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +		DRM_DEBUG("unsupported pixel format: %s\n",
> +		          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
> index 74f99ba..05f4ebe 100644
> --- a/drivers/gpu/drm/radeon/atombios_crtc.c
> +++ b/drivers/gpu/drm/radeon/atombios_crtc.c
> @@ -1156,7 +1156,7 @@ static int dce4_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) {
> @@ -1260,9 +1260,8 @@ static int dce4_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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> @@ -1473,7 +1472,7 @@ static int avivo_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) {
> @@ -1563,9 +1562,8 @@ static int avivo_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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> index c965514..e3f68cc 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> @@ -985,8 +985,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
>  
>  	info = drm_format_info(mode_cmd2->pixel_format);
>  	if (!info || !info->depth) {
> +		struct drm_format_name_buf format_name;
>  		DRM_ERROR("Unsupported framebuffer format %s\n",
> -			  drm_get_format_name(mode_cmd2->pixel_format));
> +		          drm_get_format_name(mode_cmd2->pixel_format, &format_name));
>  		return ERR_PTR(-EINVAL);
>  	}
>  
> -- 
> Cheers,
>   Eric
> 

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Intel-gfx] [PATCH v2] drm: move allocation out of drm_get_format_name()
  2016-11-07 17:38                     ` Jani Nikula
@ 2016-11-08 10:15                       ` Daniel Vetter
  2016-11-09  0:17                         ` [PATCH v3] " Eric Engestrom
  0 siblings, 1 reply; 28+ messages in thread
From: Daniel Vetter @ 2016-11-08 10:15 UTC (permalink / raw)
  To: Jani Nikula
  Cc: Eric Engestrom, David Airlie, dri-devel, Wei Yongjun,
	Daniel Vetter, Flora Cui, Gustavo Padovan, Tom St Denis,
	Chunming Zhou, Thomas Hellstrom, Laurent Pinchart, Sinclair Yeh,
	Xinliang Liu, Xinwei Kong, VMware Graphics, Vitaly Prosyak,
	Alexandre Demers, intel-gfx, Eric Engestrom, Emily Deng,
	Junwei Zhang, Michel Dänzer, linux-kernel, Alex Deucher,
	Colin Ian King, Christian König

On Mon, Nov 07, 2016 at 07:38:25PM +0200, Jani Nikula wrote:
> On Mon, 07 Nov 2016, Eric Engestrom <eric.engestrom@imgtec.com> wrote:
> > On Monday, 2016-11-07 10:10:13 +0200, Jani Nikula wrote:
> >> On Mon, 07 Nov 2016, Eric Engestrom <eric@engestrom.ch> wrote:
> >> > Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07
> >> >
> >> >     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>
> >> 
> >> The Fixes: format is:
> >> 
> >> Fixes: 90844f00049e ("drm: make drm_get_format_name thread-safe")
> >> 
> >> But is this a fix, really, or just an improvement? What exactly is the
> >> bug being fixed? The commit message is not sufficient.
> >
> > "The function's behaviour was changed in 90844f00049e, 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."
> >
> > Does this sound good?
> 
> It's fine; no need to go overboard. ;)

Can you pls resend with that and corrected Fixes and all the acks
collected?
-Daniel

> 
> BR,
> Jani.
> 
> >
> >> > @@ -54,6 +62,6 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
> >> >  int drm_format_vert_chroma_subsampling(uint32_t format);
> >> >  int drm_format_plane_width(int width, uint32_t format, int plane);
> >> >  int drm_format_plane_height(int height, uint32_t format, int plane);
> >> > -char *drm_get_format_name(uint32_t format) __malloc;
> >> > +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
> >> 
> >> I wonder if it would be better to make that return "const char *". If
> >> the user really wants to look under the hood, there's buf->str. *shrug*
> >
> > Good idea, I'll do that in v3 with the proper commit msg and tags. It'll
> > have to wait another day though, -ENOTIME and all.
> >
> >> 
> >> With the commit message improved,
> >> 
> >> Reviewed-by: Jani Nikula <jani.nikula@intel.com>
> >
> > Cheers :)
> >   Eric
> 
> -- 
> Jani Nikula, Intel Open Source Technology Center
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v3] drm: move allocation out of drm_get_format_name()
  2016-11-08 10:15                       ` [Intel-gfx] " Daniel Vetter
@ 2016-11-09  0:17                         ` Eric Engestrom
  2016-11-09  1:09                           ` [Intel-gfx] " Daniel Vetter
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Engestrom @ 2016-11-09  0:17 UTC (permalink / raw)
  To: linux-kernel
  Cc: Christian König, Rob Clark, Sinclair Yeh, Jani Nikula,
	Ville Syrjälä,
	Eric Engestrom, Alex Deucher, David Airlie, Xinliang Liu,
	Daniel Vetter, Jani Nikula, VMware Graphics, Thomas Hellstrom,
	Tom St Denis, Michel Dänzer, Gustavo Padovan,
	Eric Engestrom, Emily Deng, Chunming Zhou, Flora Cui,
	Vitaly Prosyak, Ken Wang, Colin Ian King, Alexandre Demers,
	Junwei Zhang, Xinwei Kong, Laurent Pinchart, Wei Yongjun,
	dri-devel, intel-gfx

The function's behaviour was changed in 90844f00049e, 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: 90844f00049e ("drm: make drm_get_format_name thread-safe")
Cc: Rob Clark <robdclark@gmail.com>
Cc: Christian König <christian.koenig@amd.com>
Acked-by: Christian König <christian.koenig@amd.com>
Acked-by: Rob Clark <robdclark@gmail.com>
Acked-by: Sinclair Yeh <syeh@vmware.com> (vmwgfx)
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
---
v3 - fix "Fixes" tag, replace it with an actual commit message
   - collect ack & r-b

v2 - use single-field struct instead of typedef to let the compiler
     enforce the type (Christian König)
---
 include/drm/drm_fourcc.h                        | 10 +++++-
 drivers/gpu/drm/drm_fourcc.c                    | 14 +++------
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c          |  7 ++---
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c          |  7 ++---
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c           |  3 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c           |  7 ++---
 drivers/gpu/drm/drm_atomic.c                    |  7 +++--
 drivers/gpu/drm/drm_crtc.c                      |  7 +++--
 drivers/gpu/drm/drm_framebuffer.c               |  7 +++--
 drivers/gpu/drm/drm_modeset_helper.c            |  7 +++--
 drivers/gpu/drm/drm_plane.c                     |  7 +++--
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  7 ++---
 drivers/gpu/drm/i915/i915_debugfs.c             | 10 +++---
 drivers/gpu/drm/i915/intel_atomic_plane.c       |  8 ++---
 drivers/gpu/drm/i915/intel_display.c            | 41 ++++++++++---------------
 drivers/gpu/drm/radeon/atombios_crtc.c          | 14 ++++-----
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c             |  3 +-
 17 files changed, 80 insertions(+), 86 deletions(-)

diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index dc0aafa..4b03ca0 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -45,6 +45,14 @@ struct drm_format_info {
 	u8 vsub;
 };
 
+/**
+ * struct drm_format_name_buf - name of a DRM format
+ * @str: string buffer containing the format name
+ */
+struct drm_format_name_buf {
+	char str[32];
+};
+
 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);
@@ -54,6 +62,6 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
 int drm_format_vert_chroma_subsampling(uint32_t format);
 int drm_format_plane_width(int width, uint32_t format, int plane);
 int drm_format_plane_height(int height, uint32_t format, int plane);
-char *drm_get_format_name(uint32_t format) __malloc;
+char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
 
 #endif /* __DRM_FOURCC_H__ */
diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index cbb8b77..99b0b60 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -79,17 +79,13 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
 EXPORT_SYMBOL(drm_mode_legacy_fb_format);
 
 /**
- * drm_get_format_name - return a string for drm fourcc format
+ * drm_get_format_name - fill a string with a drm fourcc format's name
  * @format: format to compute name of
+ * @buf: caller-supplied buffer
- *
- * Note that the buffer returned by this function is owned by the caller
- * and will need to be freed using kfree().
  */
-char *drm_get_format_name(uint32_t format)
+char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf)
 {
-	char *buf = kmalloc(32, GFP_KERNEL);
-
-	snprintf(buf, 32,
+	snprintf(buf->str, sizeof(buf->str),
 		 "%c%c%c%c %s-endian (0x%08x)",
 		 printable_char(format & 0xff),
 		 printable_char((format >> 8) & 0xff),
@@ -98,7 +94,7 @@ char *drm_get_format_name(uint32_t format)
 		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
 		 format);
 
-	return buf;
+	return buf->str;
 }
 EXPORT_SYMBOL(drm_get_format_name);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
index 199d3f7..2924cdd 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
@@ -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);
+		DRM_ERROR("Unsupported screen format %s\n",
+		          drm_get_format_name(target_fb->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
index ecd000e..f0e3c5c 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
@@ -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);
+		DRM_ERROR("Unsupported screen format %s\n",
+		          drm_get_format_name(target_fb->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
index 44547f9..5c6b82f 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
@@ -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;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
index 979aedf..5aef19d 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
@@ -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);
+		DRM_ERROR("Unsupported screen format %s\n",
+		          drm_get_format_name(target_fb->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index c32fb3c..f29d3c5 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -835,9 +835,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);
+		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));
-		kfree(format_name);
 		return ret;
 	}
 
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 13441e2..08ac216 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -827,9 +827,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
 			ret = drm_plane_check_pixel_format(crtc->primary,
 							   fb->pixel_format);
 			if (ret) {
-				char *format_name = drm_get_format_name(fb->pixel_format);
-				DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
+				struct drm_format_name_buf format_name;
+				DRM_DEBUG_KMS("Invalid pixel format %s\n",
+				              drm_get_format_name(fb->pixel_format,
+				                                  &format_name));
-				kfree(format_name);
 				goto out;
 			}
 		}
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index 49fd7db..df6b180 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -133,9 +133,10 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
 
 	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);
+		struct drm_format_name_buf format_name;
+		DRM_DEBUG_KMS("bad framebuffer format %s\n",
+		              drm_get_format_name(r->pixel_format,
+		                                  &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c
index 2544dfe..2f452b3 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -75,10 +75,11 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
 
 	info = drm_format_info(mode_cmd->pixel_format);
 	if (!info || !info->depth) {
-		char *format_name = drm_get_format_name(mode_cmd->pixel_format);
+		struct drm_format_name_buf format_name;
 
-		DRM_DEBUG_KMS("non-RGB pixel format %s\n", format_name);
+		DRM_DEBUG_KMS("non-RGB pixel format %s\n",
+		              drm_get_format_name(mode_cmd->pixel_format,
+		                                  &format_name));
-		kfree(format_name);
 
 		fb->depth = 0;
 		fb->bits_per_pixel = 0;
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 249c0ae..2ba0c22 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -479,9 +479,10 @@ static int __setplane_internal(struct drm_plane *plane,
 	/* Check whether this plane supports the fb pixel format. */
 	ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
 	if (ret) {
-		char *format_name = drm_get_format_name(fb->pixel_format);
-		DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
+		struct drm_format_name_buf format_name;
+		DRM_DEBUG_KMS("Invalid pixel format %s\n",
+		              drm_get_format_name(fb->pixel_format,
+		                                  &format_name));
-		kfree(format_name);
 		goto out;
 	}
 
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 7e7a4d4..afc2b5d 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -608,17 +608,16 @@ static void ade_rdma_set(void __iomem *base, struct drm_framebuffer *fb,
 			 u32 ch, u32 y, u32 in_h, u32 fmt)
 {
 	struct drm_gem_cma_object *obj = drm_fb_cma_get_gem_obj(fb, 0);
-	char *format_name;
+	struct drm_format_name_buf format_name;
 	u32 reg_ctrl, reg_addr, reg_size, reg_stride, reg_space, reg_en;
 	u32 stride = fb->pitches[0];
 	u32 addr = (u32)obj->paddr + y * stride;
 
 	DRM_DEBUG_DRIVER("rdma%d: (y=%d, height=%d), stride=%d, paddr=0x%x\n",
 			 ch + 1, y, in_h, stride, (u32)obj->paddr);
-	format_name = drm_get_format_name(fb->pixel_format);
 	DRM_DEBUG_DRIVER("addr=0x%x, fb:%dx%d, pixel_format=%d(%s)\n",
-			 addr, fb->width, fb->height, fmt, format_name);
+			 addr, fb->width, fb->height, fmt,
+			 drm_get_format_name(fb->pixel_format, &format_name));
-	kfree(format_name);
 
 	/* get reg offset */
 	reg_ctrl = RD_CH_CTRL(ch);
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 20638d2..670423e 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -2971,7 +2971,7 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 	for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
 		struct drm_plane_state *state;
 		struct drm_plane *plane = &intel_plane->base;
-		char *format_name;
+		struct drm_format_name_buf format_name;
 
 		if (!plane->state) {
 			seq_puts(m, "plane->state is NULL!\n");
@@ -2981,9 +2981,9 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 		state = plane->state;
 
 		if (state->fb) {
-			format_name = drm_get_format_name(state->fb->pixel_format);
+			drm_get_format_name(state->fb->pixel_format, &format_name);
 		} else {
-			format_name = kstrdup("N/A", GFP_KERNEL);
+			sprintf(format_name.str, "N/A");
 		}
 
 		seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
@@ -2999,10 +2999,8 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 			   ((state->src_w & 0xffff) * 15625) >> 10,
 			   (state->src_h >> 16),
 			   ((state->src_h & 0xffff) * 15625) >> 10,
-			   format_name,
+			   format_name.str,
 			   plane_rotation(state->rotation));
-
-		kfree(format_name);
 	}
 }
 
diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c b/drivers/gpu/drm/i915/intel_atomic_plane.c
index c762ae5..6c76e3d 100644
--- a/drivers/gpu/drm/i915/intel_atomic_plane.c
+++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
@@ -143,7 +143,7 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
 		crtc_state->base.enable ? crtc_state->pipe_src_h : 0;
 
 	if (state->fb && drm_rotation_90_or_270(state->rotation)) {
-		char *format_name;
+		struct drm_format_name_buf format_name;
 
 		if (!(state->fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
 			state->fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED)) {
@@ -159,9 +159,9 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
 		switch (state->fb->pixel_format) {
 		case DRM_FORMAT_C8:
 		case DRM_FORMAT_RGB565:
-			format_name = drm_get_format_name(state->fb->pixel_format);
-			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n", format_name);
+			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
+			              drm_get_format_name(state->fb->pixel_format,
+			                                  &format_name));
-			kfree(format_name);
 			return -EINVAL;
 
 		default:
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 6f8f6ec..8209170 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -12871,7 +12871,7 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 
 	DRM_DEBUG_KMS("planes on this crtc\n");
 	list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
-		char *format_name;
+		struct drm_format_name_buf format_name;
 		intel_plane = to_intel_plane(plane);
 		if (intel_plane->pipe != crtc->pipe)
 			continue;
@@ -12884,12 +12884,11 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 			continue;
 		}
 
-		format_name = drm_get_format_name(fb->pixel_format);
-
 		DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
 			      plane->base.id, plane->name);
 		DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
-			      fb->base.id, fb->width, fb->height, format_name);
+			      fb->base.id, fb->width, fb->height,
+			      drm_get_format_name(fb->pixel_format, &format_name));
 		DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
 			      state->scaler_id,
 			      state->base.src.x1 >> 16,
@@ -12899,8 +12898,6 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 			      state->base.dst.x1, state->base.dst.y1,
 			      drm_rect_width(&state->base.dst),
 			      drm_rect_height(&state->base.dst));
-
-		kfree(format_name);
 	}
 }
 
@@ -15749,7 +15746,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	unsigned int tiling = i915_gem_object_get_tiling(obj);
 	int ret;
 	u32 pitch_limit, stride_alignment;
-	char *format_name;
+	struct drm_format_name_buf format_name;
 
 	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
 
@@ -15840,18 +15837,16 @@ static int intel_framebuffer_init(struct drm_device *dev,
 		break;
 	case DRM_FORMAT_XRGB1555:
 		if (INTEL_INFO(dev)->gen > 3) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-			kfree(format_name);
 			return -EINVAL;
 		}
 		break;
 	case DRM_FORMAT_ABGR8888:
 		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
 		    INTEL_INFO(dev)->gen < 9) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-			kfree(format_name);
 			return -EINVAL;
 		}
 		break;
@@ -15859,17 +15854,15 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	case DRM_FORMAT_XRGB2101010:
 	case DRM_FORMAT_XBGR2101010:
 		if (INTEL_INFO(dev)->gen < 4) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-			kfree(format_name);
 			return -EINVAL;
 		}
 		break;
 	case DRM_FORMAT_ABGR2101010:
 		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-			kfree(format_name);
 			return -EINVAL;
 		}
 		break;
@@ -15878,16 +15871,14 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	case DRM_FORMAT_YVYU:
 	case DRM_FORMAT_VYUY:
 		if (INTEL_INFO(dev)->gen < 5) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-			kfree(format_name);
 			return -EINVAL;
 		}
 		break;
 	default:
-		format_name = drm_get_format_name(mode_cmd->pixel_format);
-		DRM_DEBUG("unsupported pixel format: %s\n", format_name);
+		DRM_DEBUG("unsupported pixel format: %s\n",
+		          drm_get_format_name(mode_cmd->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index 74f99ba..05f4ebe 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -1156,7 +1156,7 @@ static int dce4_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) {
@@ -1260,9 +1260,8 @@ static int dce4_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);
+		DRM_ERROR("Unsupported screen format %s\n",
+		          drm_get_format_name(target_fb->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
@@ -1473,7 +1472,7 @@ static int avivo_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) {
@@ -1563,9 +1562,8 @@ static int avivo_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);
+		DRM_ERROR("Unsupported screen format %s\n",
+		          drm_get_format_name(target_fb->pixel_format, &format_name));
-		kfree(format_name);
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index c965514..e3f68cc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -985,8 +985,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
 
 	info = drm_format_info(mode_cmd2->pixel_format);
 	if (!info || !info->depth) {
+		struct drm_format_name_buf format_name;
 		DRM_ERROR("Unsupported framebuffer format %s\n",
-			  drm_get_format_name(mode_cmd2->pixel_format));
+		          drm_get_format_name(mode_cmd2->pixel_format, &format_name));
 		return ERR_PTR(-EINVAL);
 	}
 
-- 
Cheers,
  Eric

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [Intel-gfx] [PATCH v3] drm: move allocation out of drm_get_format_name()
  2016-11-09  0:17                         ` [PATCH v3] " Eric Engestrom
@ 2016-11-09  1:09                           ` Daniel Vetter
  2016-11-09  1:13                             ` Daniel Vetter
  0 siblings, 1 reply; 28+ messages in thread
From: Daniel Vetter @ 2016-11-09  1:09 UTC (permalink / raw)
  To: Eric Engestrom
  Cc: linux-kernel, David Airlie, dri-devel, Wei Yongjun,
	Daniel Vetter, Flora Cui, Gustavo Padovan, Tom St Denis,
	Chunming Zhou, Thomas Hellstrom, Laurent Pinchart, Sinclair Yeh,
	Xinliang Liu, Xinwei Kong, VMware Graphics, Vitaly Prosyak,
	Eric Engestrom, Alexandre Demers, Jani Nikula, intel-gfx,
	Emily Deng, Colin Ian King, Junwei Zhang, Michel Dänzer,
	Alex Deucher, Christian König

On Wed, Nov 09, 2016 at 12:17:52AM +0000, Eric Engestrom wrote:
> The function's behaviour was changed in 90844f00049e, 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: 90844f00049e ("drm: make drm_get_format_name thread-safe")
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Christian König <christian.koenig@amd.com>
> Acked-by: Christian König <christian.koenig@amd.com>
> Acked-by: Rob Clark <robdclark@gmail.com>
> Acked-by: Sinclair Yeh <syeh@vmware.com> (vmwgfx)
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>
> Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Eric Engestrom <eric@engestrom.ch>
> ---
> v3 - fix "Fixes" tag, replace it with an actual commit message
>    - collect ack & r-b
> 
> v2 - use single-field struct instead of typedef to let the compiler
>      enforce the type (Christian König)

Applied to drm-misc, thanks.
-Daniel

> ---
>  include/drm/drm_fourcc.h                        | 10 +++++-
>  drivers/gpu/drm/drm_fourcc.c                    | 14 +++------
>  drivers/gpu/drm/amd/amdgpu/dce_v10_0.c          |  7 ++---
>  drivers/gpu/drm/amd/amdgpu/dce_v11_0.c          |  7 ++---
>  drivers/gpu/drm/amd/amdgpu/dce_v6_0.c           |  3 +-
>  drivers/gpu/drm/amd/amdgpu/dce_v8_0.c           |  7 ++---
>  drivers/gpu/drm/drm_atomic.c                    |  7 +++--
>  drivers/gpu/drm/drm_crtc.c                      |  7 +++--
>  drivers/gpu/drm/drm_framebuffer.c               |  7 +++--
>  drivers/gpu/drm/drm_modeset_helper.c            |  7 +++--
>  drivers/gpu/drm/drm_plane.c                     |  7 +++--
>  drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  7 ++---
>  drivers/gpu/drm/i915/i915_debugfs.c             | 10 +++---
>  drivers/gpu/drm/i915/intel_atomic_plane.c       |  8 ++---
>  drivers/gpu/drm/i915/intel_display.c            | 41 ++++++++++---------------
>  drivers/gpu/drm/radeon/atombios_crtc.c          | 14 ++++-----
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c             |  3 +-
>  17 files changed, 80 insertions(+), 86 deletions(-)
> 
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index dc0aafa..4b03ca0 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -45,6 +45,14 @@ struct drm_format_info {
>  	u8 vsub;
>  };
>  
> +/**
> + * struct drm_format_name_buf - name of a DRM format
> + * @str: string buffer containing the format name
> + */
> +struct drm_format_name_buf {
> +	char str[32];
> +};
> +
>  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);
> @@ -54,6 +62,6 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
>  int drm_format_vert_chroma_subsampling(uint32_t format);
>  int drm_format_plane_width(int width, uint32_t format, int plane);
>  int drm_format_plane_height(int height, uint32_t format, int plane);
> -char *drm_get_format_name(uint32_t format) __malloc;
> +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
>  
>  #endif /* __DRM_FOURCC_H__ */
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index cbb8b77..99b0b60 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -79,17 +79,13 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
>  EXPORT_SYMBOL(drm_mode_legacy_fb_format);
>  
>  /**
> - * drm_get_format_name - return a string for drm fourcc format
> + * drm_get_format_name - fill a string with a drm fourcc format's name
>   * @format: format to compute name of
> + * @buf: caller-supplied buffer
> - *
> - * Note that the buffer returned by this function is owned by the caller
> - * and will need to be freed using kfree().
>   */
> -char *drm_get_format_name(uint32_t format)
> +char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf)
>  {
> -	char *buf = kmalloc(32, GFP_KERNEL);
> -
> -	snprintf(buf, 32,
> +	snprintf(buf->str, sizeof(buf->str),
>  		 "%c%c%c%c %s-endian (0x%08x)",
>  		 printable_char(format & 0xff),
>  		 printable_char((format >> 8) & 0xff),
> @@ -98,7 +94,7 @@ char *drm_get_format_name(uint32_t format)
>  		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
>  		 format);
>  
> -	return buf;
> +	return buf->str;
>  }
>  EXPORT_SYMBOL(drm_get_format_name);
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> index 199d3f7..2924cdd 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> index ecd000e..f0e3c5c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> index 44547f9..5c6b82f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
> @@ -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;
>  	}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> index 979aedf..5aef19d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
> @@ -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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index c32fb3c..f29d3c5 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -835,9 +835,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);
> +		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));
> -		kfree(format_name);
>  		return ret;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 13441e2..08ac216 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -827,9 +827,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
>  			ret = drm_plane_check_pixel_format(crtc->primary,
>  							   fb->pixel_format);
>  			if (ret) {
> -				char *format_name = drm_get_format_name(fb->pixel_format);
> -				DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> +				struct drm_format_name_buf format_name;
> +				DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +				              drm_get_format_name(fb->pixel_format,
> +				                                  &format_name));
> -				kfree(format_name);
>  				goto out;
>  			}
>  		}
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 49fd7db..df6b180 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -133,9 +133,10 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
>  
>  	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);
> +		struct drm_format_name_buf format_name;
> +		DRM_DEBUG_KMS("bad framebuffer format %s\n",
> +		              drm_get_format_name(r->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c
> index 2544dfe..2f452b3 100644
> --- a/drivers/gpu/drm/drm_modeset_helper.c
> +++ b/drivers/gpu/drm/drm_modeset_helper.c
> @@ -75,10 +75,11 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
>  
>  	info = drm_format_info(mode_cmd->pixel_format);
>  	if (!info || !info->depth) {
> -		char *format_name = drm_get_format_name(mode_cmd->pixel_format);
> +		struct drm_format_name_buf format_name;
>  
> -		DRM_DEBUG_KMS("non-RGB pixel format %s\n", format_name);
> +		DRM_DEBUG_KMS("non-RGB pixel format %s\n",
> +		              drm_get_format_name(mode_cmd->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>  
>  		fb->depth = 0;
>  		fb->bits_per_pixel = 0;
> diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
> index 249c0ae..2ba0c22 100644
> --- a/drivers/gpu/drm/drm_plane.c
> +++ b/drivers/gpu/drm/drm_plane.c
> @@ -479,9 +479,10 @@ static int __setplane_internal(struct drm_plane *plane,
>  	/* Check whether this plane supports the fb pixel format. */
>  	ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
>  	if (ret) {
> -		char *format_name = drm_get_format_name(fb->pixel_format);
> -		DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
> +		struct drm_format_name_buf format_name;
> +		DRM_DEBUG_KMS("Invalid pixel format %s\n",
> +		              drm_get_format_name(fb->pixel_format,
> +		                                  &format_name));
> -		kfree(format_name);
>  		goto out;
>  	}
>  
> diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> index 7e7a4d4..afc2b5d 100644
> --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
> @@ -608,17 +608,16 @@ static void ade_rdma_set(void __iomem *base, struct drm_framebuffer *fb,
>  			 u32 ch, u32 y, u32 in_h, u32 fmt)
>  {
>  	struct drm_gem_cma_object *obj = drm_fb_cma_get_gem_obj(fb, 0);
> -	char *format_name;
> +	struct drm_format_name_buf format_name;
>  	u32 reg_ctrl, reg_addr, reg_size, reg_stride, reg_space, reg_en;
>  	u32 stride = fb->pitches[0];
>  	u32 addr = (u32)obj->paddr + y * stride;
>  
>  	DRM_DEBUG_DRIVER("rdma%d: (y=%d, height=%d), stride=%d, paddr=0x%x\n",
>  			 ch + 1, y, in_h, stride, (u32)obj->paddr);
> -	format_name = drm_get_format_name(fb->pixel_format);
>  	DRM_DEBUG_DRIVER("addr=0x%x, fb:%dx%d, pixel_format=%d(%s)\n",
> -			 addr, fb->width, fb->height, fmt, format_name);
> +			 addr, fb->width, fb->height, fmt,
> +			 drm_get_format_name(fb->pixel_format, &format_name));
> -	kfree(format_name);
>  
>  	/* get reg offset */
>  	reg_ctrl = RD_CH_CTRL(ch);
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index 20638d2..670423e 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -2971,7 +2971,7 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  	for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
>  		struct drm_plane_state *state;
>  		struct drm_plane *plane = &intel_plane->base;
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>  
>  		if (!plane->state) {
>  			seq_puts(m, "plane->state is NULL!\n");
> @@ -2981,9 +2981,9 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  		state = plane->state;
>  
>  		if (state->fb) {
> -			format_name = drm_get_format_name(state->fb->pixel_format);
> +			drm_get_format_name(state->fb->pixel_format, &format_name);
>  		} else {
> -			format_name = kstrdup("N/A", GFP_KERNEL);
> +			sprintf(format_name.str, "N/A");
>  		}
>  
>  		seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
> @@ -2999,10 +2999,8 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
>  			   ((state->src_w & 0xffff) * 15625) >> 10,
>  			   (state->src_h >> 16),
>  			   ((state->src_h & 0xffff) * 15625) >> 10,
> -			   format_name,
> +			   format_name.str,
>  			   plane_rotation(state->rotation));
> -
> -		kfree(format_name);
>  	}
>  }
>  
> diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c b/drivers/gpu/drm/i915/intel_atomic_plane.c
> index c762ae5..6c76e3d 100644
> --- a/drivers/gpu/drm/i915/intel_atomic_plane.c
> +++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
> @@ -143,7 +143,7 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>  		crtc_state->base.enable ? crtc_state->pipe_src_h : 0;
>  
>  	if (state->fb && drm_rotation_90_or_270(state->rotation)) {
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>  
>  		if (!(state->fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
>  			state->fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED)) {
> @@ -159,9 +159,9 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
>  		switch (state->fb->pixel_format) {
>  		case DRM_FORMAT_C8:
>  		case DRM_FORMAT_RGB565:
> -			format_name = drm_get_format_name(state->fb->pixel_format);
> -			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n", format_name);
> +			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
> +			              drm_get_format_name(state->fb->pixel_format,
> +			                                  &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  
>  		default:
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 6f8f6ec..8209170 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -12871,7 +12871,7 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  
>  	DRM_DEBUG_KMS("planes on this crtc\n");
>  	list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
> -		char *format_name;
> +		struct drm_format_name_buf format_name;
>  		intel_plane = to_intel_plane(plane);
>  		if (intel_plane->pipe != crtc->pipe)
>  			continue;
> @@ -12884,12 +12884,11 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  			continue;
>  		}
>  
> -		format_name = drm_get_format_name(fb->pixel_format);
> -
>  		DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
>  			      plane->base.id, plane->name);
>  		DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
> -			      fb->base.id, fb->width, fb->height, format_name);
> +			      fb->base.id, fb->width, fb->height,
> +			      drm_get_format_name(fb->pixel_format, &format_name));
>  		DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
>  			      state->scaler_id,
>  			      state->base.src.x1 >> 16,
> @@ -12899,8 +12898,6 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
>  			      state->base.dst.x1, state->base.dst.y1,
>  			      drm_rect_width(&state->base.dst),
>  			      drm_rect_height(&state->base.dst));
> -
> -		kfree(format_name);
>  	}
>  }
>  
> @@ -15749,7 +15746,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	unsigned int tiling = i915_gem_object_get_tiling(obj);
>  	int ret;
>  	u32 pitch_limit, stride_alignment;
> -	char *format_name;
> +	struct drm_format_name_buf format_name;
>  
>  	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
>  
> @@ -15840,18 +15837,16 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  		break;
>  	case DRM_FORMAT_XRGB1555:
>  		if (INTEL_INFO(dev)->gen > 3) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
>  	case DRM_FORMAT_ABGR8888:
>  		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
>  		    INTEL_INFO(dev)->gen < 9) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
> @@ -15859,17 +15854,15 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	case DRM_FORMAT_XRGB2101010:
>  	case DRM_FORMAT_XBGR2101010:
>  		if (INTEL_INFO(dev)->gen < 4) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
>  	case DRM_FORMAT_ABGR2101010:
>  		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
> @@ -15878,16 +15871,14 @@ static int intel_framebuffer_init(struct drm_device *dev,
>  	case DRM_FORMAT_YVYU:
>  	case DRM_FORMAT_VYUY:
>  		if (INTEL_INFO(dev)->gen < 5) {
> -			format_name = drm_get_format_name(mode_cmd->pixel_format);
> -			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +			DRM_DEBUG("unsupported pixel format: %s\n",
> +			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -			kfree(format_name);
>  			return -EINVAL;
>  		}
>  		break;
>  	default:
> -		format_name = drm_get_format_name(mode_cmd->pixel_format);
> -		DRM_DEBUG("unsupported pixel format: %s\n", format_name);
> +		DRM_DEBUG("unsupported pixel format: %s\n",
> +		          drm_get_format_name(mode_cmd->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
> index 74f99ba..05f4ebe 100644
> --- a/drivers/gpu/drm/radeon/atombios_crtc.c
> +++ b/drivers/gpu/drm/radeon/atombios_crtc.c
> @@ -1156,7 +1156,7 @@ static int dce4_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) {
> @@ -1260,9 +1260,8 @@ static int dce4_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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> @@ -1473,7 +1472,7 @@ static int avivo_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) {
> @@ -1563,9 +1562,8 @@ static int avivo_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);
> +		DRM_ERROR("Unsupported screen format %s\n",
> +		          drm_get_format_name(target_fb->pixel_format, &format_name));
> -		kfree(format_name);
>  		return -EINVAL;
>  	}
>  
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> index c965514..e3f68cc 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> @@ -985,8 +985,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
>  
>  	info = drm_format_info(mode_cmd2->pixel_format);
>  	if (!info || !info->depth) {
> +		struct drm_format_name_buf format_name;
>  		DRM_ERROR("Unsupported framebuffer format %s\n",
> -			  drm_get_format_name(mode_cmd2->pixel_format));
> +		          drm_get_format_name(mode_cmd2->pixel_format, &format_name));
>  		return ERR_PTR(-EINVAL);
>  	}
>  
> -- 
> Cheers,
>   Eric
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Intel-gfx] [PATCH v3] drm: move allocation out of drm_get_format_name()
  2016-11-09  1:09                           ` [Intel-gfx] " Daniel Vetter
@ 2016-11-09  1:13                             ` Daniel Vetter
  2016-11-09 11:42                               ` Eric Engestrom
  0 siblings, 1 reply; 28+ messages in thread
From: Daniel Vetter @ 2016-11-09  1:13 UTC (permalink / raw)
  To: Eric Engestrom
  Cc: linux-kernel, David Airlie, dri-devel, Wei Yongjun,
	Daniel Vetter, Flora Cui, Gustavo Padovan, Tom St Denis,
	Chunming Zhou, Thomas Hellstrom, Laurent Pinchart, Sinclair Yeh,
	Xinliang Liu, Xinwei Kong, VMware Graphics, Vitaly Prosyak,
	Eric Engestrom, Alexandre Demers, Jani Nikula, intel-gfx,
	Emily Deng, Colin Ian King, Junwei Zhang, Michel Dänzer,
	Alex Deucher, Christian König

On Wed, Nov 09, 2016 at 02:09:16AM +0100, Daniel Vetter wrote:
> On Wed, Nov 09, 2016 at 12:17:52AM +0000, Eric Engestrom wrote:
> > The function's behaviour was changed in 90844f00049e, 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: 90844f00049e ("drm: make drm_get_format_name thread-safe")
> > Cc: Rob Clark <robdclark@gmail.com>
> > Cc: Christian König <christian.koenig@amd.com>
> > Acked-by: Christian König <christian.koenig@amd.com>
> > Acked-by: Rob Clark <robdclark@gmail.com>
> > Acked-by: Sinclair Yeh <syeh@vmware.com> (vmwgfx)
> > Reviewed-by: Jani Nikula <jani.nikula@intel.com>
> > Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > Signed-off-by: Eric Engestrom <eric@engestrom.ch>
> > ---
> > v3 - fix "Fixes" tag, replace it with an actual commit message
> >    - collect ack & r-b
> > 
> > v2 - use single-field struct instead of typedef to let the compiler
> >      enforce the type (Christian König)
> 
> Applied to drm-misc, thanks.

Well, had to drop it again since it didn't compile:


  CC [M]  drivers/gpu/drm/drm_blend.o
drivers/gpu/drm/drm_atomic.c: In function ‘drm_atomic_plane_print_state’:
drivers/gpu/drm/drm_atomic.c:920:5: error: too few arguments to function ‘drm_get_format_name’
     drm_get_format_name(fb->pixel_format));
     ^~~~~~~~~~~~~~~~~~~
In file included from ./include/drm/drmP.h:71:0,
                 from drivers/gpu/drm/drm_atomic.c:29:
./include/drm/drm_fourcc.h:65:7: note: declared here
 char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
       ^~~~~~~~~~~~~~~~~~~

Can you pls rebase onto drm-misc or linux-next or something?

Thanks, Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Intel-gfx] [PATCH v3] drm: move allocation out of drm_get_format_name()
  2016-11-09  1:13                             ` Daniel Vetter
@ 2016-11-09 11:42                               ` Eric Engestrom
  2016-11-09 13:13                                 ` Daniel Vetter
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Engestrom @ 2016-11-09 11:42 UTC (permalink / raw)
  To: Eric Engestrom, linux-kernel, David Airlie, dri-devel,
	Wei Yongjun, Daniel Vetter, Flora Cui, Gustavo Padovan,
	Tom St Denis, Chunming Zhou, Thomas Hellstrom, Laurent Pinchart,
	Sinclair Yeh, Xinliang Liu, Xinwei Kong, VMware Graphics,
	Vitaly Prosyak, Alexandre Demers, Jani Nikula, intel-gfx,
	Emily Deng, Colin Ian King, Junwei Zhang, Michel Dänzer,
	Alex Deucher, Christian König

On Wednesday, 2016-11-09 02:13:25 +0100, Daniel Vetter wrote:
> On Wed, Nov 09, 2016 at 02:09:16AM +0100, Daniel Vetter wrote:
> > On Wed, Nov 09, 2016 at 12:17:52AM +0000, Eric Engestrom wrote:
> > > The function's behaviour was changed in 90844f00049e, 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: 90844f00049e ("drm: make drm_get_format_name thread-safe")
> > > Cc: Rob Clark <robdclark@gmail.com>
> > > Cc: Christian König <christian.koenig@amd.com>
> > > Acked-by: Christian König <christian.koenig@amd.com>
> > > Acked-by: Rob Clark <robdclark@gmail.com>
> > > Acked-by: Sinclair Yeh <syeh@vmware.com> (vmwgfx)
> > > Reviewed-by: Jani Nikula <jani.nikula@intel.com>
> > > Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > > Signed-off-by: Eric Engestrom <eric@engestrom.ch>
> > > ---
> > > v3 - fix "Fixes" tag, replace it with an actual commit message
> > >    - collect ack & r-b
> > > 
> > > v2 - use single-field struct instead of typedef to let the compiler
> > >      enforce the type (Christian König)
> > 
> > Applied to drm-misc, thanks.
> 
> Well, had to drop it again since it didn't compile:
> 
> 
>   CC [M]  drivers/gpu/drm/drm_blend.o
> drivers/gpu/drm/drm_atomic.c: In function ‘drm_atomic_plane_print_state’:
> drivers/gpu/drm/drm_atomic.c:920:5: error: too few arguments to function ‘drm_get_format_name’
>      drm_get_format_name(fb->pixel_format));
>      ^~~~~~~~~~~~~~~~~~~
> In file included from ./include/drm/drmP.h:71:0,
>                  from drivers/gpu/drm/drm_atomic.c:29:
> ./include/drm/drm_fourcc.h:65:7: note: declared here
>  char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
>        ^~~~~~~~~~~~~~~~~~~
> 
> Can you pls rebase onto drm-misc or linux-next or something?

That was based on airlied/drm-next (last fetched on Sunday I think),
I can rebase it on drm-misc if it helps, but it seems older than
drm-next.
Should I just rebase on top of current head of drm-next?

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Intel-gfx] [PATCH v3] drm: move allocation out of drm_get_format_name()
  2016-11-09 11:42                               ` Eric Engestrom
@ 2016-11-09 13:13                                 ` Daniel Vetter
  2016-11-09 16:59                                   ` Eric Engestrom
  0 siblings, 1 reply; 28+ messages in thread
From: Daniel Vetter @ 2016-11-09 13:13 UTC (permalink / raw)
  To: Eric Engestrom
  Cc: Eric Engestrom, Linux Kernel Mailing List, David Airlie,
	dri-devel, Wei Yongjun, Daniel Vetter, Flora Cui,
	Gustavo Padovan, Tom St Denis, Chunming Zhou, Thomas Hellstrom,
	Laurent Pinchart, Sinclair Yeh, Xinliang Liu, Xinwei Kong,
	VMware Graphics, Vitaly Prosyak, Alexandre Demers, Jani Nikula,
	intel-gfx, Emily Deng, Colin Ian King, Junwei Zhang,
	Michel Dänzer, Alex Deucher, Christian König

On Wed, Nov 9, 2016 at 12:42 PM, Eric Engestrom
<eric.engestrom@imgtec.com> wrote:
>> Well, had to drop it again since it didn't compile:
>>
>>
>>   CC [M]  drivers/gpu/drm/drm_blend.o
>> drivers/gpu/drm/drm_atomic.c: In function ‘drm_atomic_plane_print_state’:
>> drivers/gpu/drm/drm_atomic.c:920:5: error: too few arguments to function ‘drm_get_format_name’
>>      drm_get_format_name(fb->pixel_format));
>>      ^~~~~~~~~~~~~~~~~~~
>> In file included from ./include/drm/drmP.h:71:0,
>>                  from drivers/gpu/drm/drm_atomic.c:29:
>> ./include/drm/drm_fourcc.h:65:7: note: declared here
>>  char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
>>        ^~~~~~~~~~~~~~~~~~~
>>
>> Can you pls rebase onto drm-misc or linux-next or something?
>
> That was based on airlied/drm-next (last fetched on Sunday I think),
> I can rebase it on drm-misc if it helps, but it seems older than
> drm-next.
> Should I just rebase on top of current head of drm-next?

It needs to be drm-misc (linux-next doesn't have it yet) due to the
new atomic debug work that we just landed. I'm working on drm-tip as a
drm local integration tree to ease pains like these a bit, but that
doesn't really exist yet.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Intel-gfx] [PATCH v3] drm: move allocation out of drm_get_format_name()
  2016-11-09 13:13                                 ` Daniel Vetter
@ 2016-11-09 16:59                                   ` Eric Engestrom
  2016-11-10 10:03                                     ` Laurent Pinchart
  2016-11-11  9:26                                     ` Daniel Vetter
  0 siblings, 2 replies; 28+ messages in thread
From: Eric Engestrom @ 2016-11-09 16:59 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Eric Engestrom, Linux Kernel Mailing List, David Airlie,
	dri-devel, Wei Yongjun, Daniel Vetter, Flora Cui,
	Gustavo Padovan, Tom St Denis, Chunming Zhou, Thomas Hellstrom,
	Laurent Pinchart, Sinclair Yeh, Xinliang Liu, Xinwei Kong,
	VMware Graphics, Vitaly Prosyak, Alexandre Demers, Jani Nikula,
	intel-gfx, Emily Deng, Colin Ian King, Junwei Zhang,
	Michel Dänzer, Alex Deucher, Christian König

On Wednesday, 2016-11-09 14:13:40 +0100, Daniel Vetter wrote:
> On Wed, Nov 9, 2016 at 12:42 PM, Eric Engestrom
> <eric.engestrom@imgtec.com> wrote:
> >> Well, had to drop it again since it didn't compile:
> >>
> >>
> >>   CC [M]  drivers/gpu/drm/drm_blend.o
> >> drivers/gpu/drm/drm_atomic.c: In function ‘drm_atomic_plane_print_state’:
> >> drivers/gpu/drm/drm_atomic.c:920:5: error: too few arguments to function ‘drm_get_format_name’
> >>      drm_get_format_name(fb->pixel_format));
> >>      ^~~~~~~~~~~~~~~~~~~
> >> In file included from ./include/drm/drmP.h:71:0,
> >>                  from drivers/gpu/drm/drm_atomic.c:29:
> >> ./include/drm/drm_fourcc.h:65:7: note: declared here
> >>  char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
> >>        ^~~~~~~~~~~~~~~~~~~
> >>
> >> Can you pls rebase onto drm-misc or linux-next or something?
> >
> > That was based on airlied/drm-next (last fetched on Sunday I think),
> > I can rebase it on drm-misc if it helps, but it seems older than
> > drm-next.
> > Should I just rebase on top of current head of drm-next?
> 
> It needs to be drm-misc (linux-next doesn't have it yet) due to the
> new atomic debug work that we just landed. I'm working on drm-tip as a
> drm local integration tree to ease pains like these a bit, but that
> doesn't really exist yet.

I'm confused as to how the different trees and branches merge back to
Torvalds' tree (I'm interested in particular in drm), and I'm not sure
which branch you want me to rebase on in the drm-misc tree [1],
especially since all of them are older than drm-next [2].

I'll try to rebase on drm-misc-fixes (currently at 4da5caa6a6f82cda3193)
as it sounds about right, but it doesn't apply at all, so it'll take
a little while.

Could you give me a quick explanation or point me to a doc/page that
explains how the various trees and branches get merged?
I googled a bit and found this doc [4] by Jani, but it doesn't mention
drm-misc for instance, so I'm not sure how up-to-date and
non-intel-specific it is.

Looking at this page, something just occurred to me: did you mean
drm-fixes [3], instead of one of the branches on drm-misc?

Cheers,
  Eric

[1] git://anongit.freedesktop.org/drm/drm-misc
[2] git://people.freedesktop.org/~airlied/linux drm-next
[2] git://people.freedesktop.org/~airlied/linux drm-fixes
[3] https://01.org/linuxgraphics/gfx-docs/maintainer-tools/drm-intel.html

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Intel-gfx] [PATCH v3] drm: move allocation out of drm_get_format_name()
  2016-11-09 16:59                                   ` Eric Engestrom
@ 2016-11-10 10:03                                     ` Laurent Pinchart
  2016-11-10 10:30                                       ` Jani Nikula
  2016-11-11  9:26                                     ` Daniel Vetter
  1 sibling, 1 reply; 28+ messages in thread
From: Laurent Pinchart @ 2016-11-10 10:03 UTC (permalink / raw)
  To: Eric Engestrom
  Cc: Daniel Vetter, Eric Engestrom, Linux Kernel Mailing List,
	David Airlie, dri-devel, Wei Yongjun, Daniel Vetter, Flora Cui,
	Gustavo Padovan, Tom St Denis, Chunming Zhou, Thomas Hellstrom,
	Laurent Pinchart, Sinclair Yeh, Xinliang Liu, Xinwei Kong,
	VMware Graphics, Vitaly Prosyak, Alexandre Demers, Jani Nikula,
	intel-gfx, Emily Deng, Colin Ian King, Junwei Zhang,
	Michel Dänzer, Alex Deucher, Christian König

Hi Eric,

On Wednesday 09 Nov 2016 16:59:31 Eric Engestrom wrote:
> On Wednesday, 2016-11-09 14:13:40 +0100, Daniel Vetter wrote:
> > On Wed, Nov 9, 2016 at 12:42 PM, Eric Engestrom wrote:
> > >> Well, had to drop it again since it didn't compile:
> > >>   CC [M]  drivers/gpu/drm/drm_blend.o
> > >> 
> > >> drivers/gpu/drm/drm_atomic.c: In function
> > >> ‘drm_atomic_plane_print_state’:
> > >> drivers/gpu/drm/drm_atomic.c:920:5: error: too few arguments to
> > >> function ‘drm_get_format_name’> >> 
> > >>      drm_get_format_name(fb->pixel_format));
> > >>      ^~~~~~~~~~~~~~~~~~~
> > >> 
> > >> In file included from ./include/drm/drmP.h:71:0,
> > >> 
> > >>                  from drivers/gpu/drm/drm_atomic.c:29:
> > >> ./include/drm/drm_fourcc.h:65:7: note: declared here
> > >> 
> > >>  char *drm_get_format_name(uint32_t format, struct drm_format_name_buf
> > >>  *buf);> >>  
> > >>        ^~~~~~~~~~~~~~~~~~~
> > >> 
> > >> Can you pls rebase onto drm-misc or linux-next or something?
> > > 
> > > That was based on airlied/drm-next (last fetched on Sunday I think),
> > > I can rebase it on drm-misc if it helps, but it seems older than
> > > drm-next. Should I just rebase on top of current head of drm-next?
> > 
> > It needs to be drm-misc (linux-next doesn't have it yet) due to the
> > new atomic debug work that we just landed. I'm working on drm-tip as a
> > drm local integration tree to ease pains like these a bit, but that
> > doesn't really exist yet.
> 
> I'm confused as to how the different trees and branches merge back to
> Torvalds' tree (I'm interested in particular in drm), and I'm not sure
> which branch you want me to rebase on in the drm-misc tree [1],
> especially since all of them are older than drm-next [2].
> 
> I'll try to rebase on drm-misc-fixes (currently at 4da5caa6a6f82cda3193)
> as it sounds about right, but it doesn't apply at all, so it'll take
> a little while.

While at it, could you make the function return a const char * ?

By the way, while this is an improvement over the current situation in that it 
fixes the missing kfree() issue, I wonder whether the problem we're trying to 
solve should be addressed at a more global level.

The issue here is that printk can't format the fourcc as a string by itself. 
There's a bunch of places in the kernel where a similar formatting problem 
occurs. In a few occasions it has been solved by extending printk with 
additional format specifiers (such as for MAC/IP addresses, GUIDs, various 
kind of device names, ...). DRM fourccs are probably too DRM specific to be 
worth a format specifier, but I wonder whether we could introduce a new 
specifier that takes a function pointer as a formatting helper. Another 
similarly crazy option would be a format specifier for strings that would free 
the passed pointer after printing it.

> Could you give me a quick explanation or point me to a doc/page that
> explains how the various trees and branches get merged?
> I googled a bit and found this doc [4] by Jani, but it doesn't mention
> drm-misc for instance, so I'm not sure how up-to-date and
> non-intel-specific it is.
> 
> Looking at this page, something just occurred to me: did you mean
> drm-fixes [3], instead of one of the branches on drm-misc?
> 
> Cheers,
>   Eric
> 
> [1] git://anongit.freedesktop.org/drm/drm-misc
> [2] git://people.freedesktop.org/~airlied/linux drm-next
> [2] git://people.freedesktop.org/~airlied/linux drm-fixes
> [3] https://01.org/linuxgraphics/gfx-docs/maintainer-tools/drm-intel.html

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Intel-gfx] [PATCH v3] drm: move allocation out of drm_get_format_name()
  2016-11-10 10:03                                     ` Laurent Pinchart
@ 2016-11-10 10:30                                       ` Jani Nikula
  2016-11-10 10:59                                         ` Laurent Pinchart
  0 siblings, 1 reply; 28+ messages in thread
From: Jani Nikula @ 2016-11-10 10:30 UTC (permalink / raw)
  To: Laurent Pinchart, Eric Engestrom
  Cc: Daniel Vetter, Eric Engestrom, Linux Kernel Mailing List,
	David Airlie, dri-devel, Wei Yongjun, Daniel Vetter, Flora Cui,
	Gustavo Padovan, Tom St Denis, Chunming Zhou, Thomas Hellstrom,
	Laurent Pinchart, Sinclair Yeh, Xinliang Liu, Xinwei Kong,
	VMware Graphics, Vitaly Prosyak, Alexandre Demers, intel-gfx,
	Emily Deng, Colin Ian King, Junwei Zhang, Michel Dänzer,
	Alex Deucher, Christian König

On Thu, 10 Nov 2016, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote:
> Hi Eric,
>
> On Wednesday 09 Nov 2016 16:59:31 Eric Engestrom wrote:
>> On Wednesday, 2016-11-09 14:13:40 +0100, Daniel Vetter wrote:
>> > On Wed, Nov 9, 2016 at 12:42 PM, Eric Engestrom wrote:
>> > >> Well, had to drop it again since it didn't compile:
>> > >>   CC [M]  drivers/gpu/drm/drm_blend.o
>> > >> 
>> > >> drivers/gpu/drm/drm_atomic.c: In function
>> > >> ‘drm_atomic_plane_print_state’:
>> > >> drivers/gpu/drm/drm_atomic.c:920:5: error: too few arguments to
>> > >> function ‘drm_get_format_name’> >> 
>> > >>      drm_get_format_name(fb->pixel_format));
>> > >>      ^~~~~~~~~~~~~~~~~~~
>> > >> 
>> > >> In file included from ./include/drm/drmP.h:71:0,
>> > >> 
>> > >>                  from drivers/gpu/drm/drm_atomic.c:29:
>> > >> ./include/drm/drm_fourcc.h:65:7: note: declared here
>> > >> 
>> > >>  char *drm_get_format_name(uint32_t format, struct drm_format_name_buf
>> > >>  *buf);> >>  
>> > >>        ^~~~~~~~~~~~~~~~~~~
>> > >> 
>> > >> Can you pls rebase onto drm-misc or linux-next or something?
>> > > 
>> > > That was based on airlied/drm-next (last fetched on Sunday I think),
>> > > I can rebase it on drm-misc if it helps, but it seems older than
>> > > drm-next. Should I just rebase on top of current head of drm-next?
>> > 
>> > It needs to be drm-misc (linux-next doesn't have it yet) due to the
>> > new atomic debug work that we just landed. I'm working on drm-tip as a
>> > drm local integration tree to ease pains like these a bit, but that
>> > doesn't really exist yet.
>> 
>> I'm confused as to how the different trees and branches merge back to
>> Torvalds' tree (I'm interested in particular in drm), and I'm not sure
>> which branch you want me to rebase on in the drm-misc tree [1],
>> especially since all of them are older than drm-next [2].
>> 
>> I'll try to rebase on drm-misc-fixes (currently at 4da5caa6a6f82cda3193)
>> as it sounds about right, but it doesn't apply at all, so it'll take
>> a little while.
>
> While at it, could you make the function return a const char * ?

I thought I mentioned that too, though I didn't insist.

> By the way, while this is an improvement over the current situation in that it 
> fixes the missing kfree() issue, I wonder whether the problem we're trying to 
> solve should be addressed at a more global level.

Maybe, but let's not block this one!

> The issue here is that printk can't format the fourcc as a string by itself. 
> There's a bunch of places in the kernel where a similar formatting problem 
> occurs. In a few occasions it has been solved by extending printk with 
> additional format specifiers (such as for MAC/IP addresses, GUIDs, various 
> kind of device names, ...). DRM fourccs are probably too DRM specific to be 
> worth a format specifier, but I wonder whether we could introduce a new 
> specifier that takes a function pointer as a formatting helper. Another 
> similarly crazy option would be a format specifier for strings that would free 
> the passed pointer after printing it.

I think there are too many non-standard format specifiers already. I
can't review the non-standard format strings without looking at
Documentation/prink-formats.txt first. The formatting hook would be a
generic alternative, but that's more than a little scary from the
security standpoint. And what if the hook has to allocate memory? Can't
do that in atomic contexts.

BR,
Jani.


>
>> Could you give me a quick explanation or point me to a doc/page that
>> explains how the various trees and branches get merged?
>> I googled a bit and found this doc [4] by Jani, but it doesn't mention
>> drm-misc for instance, so I'm not sure how up-to-date and
>> non-intel-specific it is.
>> 
>> Looking at this page, something just occurred to me: did you mean
>> drm-fixes [3], instead of one of the branches on drm-misc?
>> 
>> Cheers,
>>   Eric
>> 
>> [1] git://anongit.freedesktop.org/drm/drm-misc
>> [2] git://people.freedesktop.org/~airlied/linux drm-next
>> [2] git://people.freedesktop.org/~airlied/linux drm-fixes
>> [3] https://01.org/linuxgraphics/gfx-docs/maintainer-tools/drm-intel.html

-- 
Jani Nikula, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Intel-gfx] [PATCH v3] drm: move allocation out of drm_get_format_name()
  2016-11-10 10:30                                       ` Jani Nikula
@ 2016-11-10 10:59                                         ` Laurent Pinchart
  2016-11-10 11:03                                           ` Jani Nikula
  0 siblings, 1 reply; 28+ messages in thread
From: Laurent Pinchart @ 2016-11-10 10:59 UTC (permalink / raw)
  To: Jani Nikula
  Cc: Eric Engestrom, Daniel Vetter, Eric Engestrom,
	Linux Kernel Mailing List, David Airlie, dri-devel, Wei Yongjun,
	Daniel Vetter, Flora Cui, Gustavo Padovan, Tom St Denis,
	Chunming Zhou, Thomas Hellstrom, Laurent Pinchart, Sinclair Yeh,
	Xinliang Liu, Xinwei Kong, VMware Graphics, Vitaly Prosyak,
	Alexandre Demers, intel-gfx, Emily Deng, Colin Ian King,
	Junwei Zhang, Michel Dänzer, Alex Deucher,
	Christian König

Hi Jani,

On Thursday 10 Nov 2016 12:30:09 Jani Nikula wrote:
> On Thu, 10 Nov 2016, Laurent Pinchart wrote:
> > On Wednesday 09 Nov 2016 16:59:31 Eric Engestrom wrote:
> >> On Wednesday, 2016-11-09 14:13:40 +0100, Daniel Vetter wrote:
> >>> On Wed, Nov 9, 2016 at 12:42 PM, Eric Engestrom wrote:
> >>>>> Well, had to drop it again since it didn't compile:
> >>>>>   CC [M]  drivers/gpu/drm/drm_blend.o
> >>>>> 
> >>>>> drivers/gpu/drm/drm_atomic.c: In function
> >>>>> ‘drm_atomic_plane_print_state’:
> >>>>> drivers/gpu/drm/drm_atomic.c:920:5: error: too few arguments to
> >>>>> function ‘drm_get_format_name’> >>
> >>>>>      drm_get_format_name(fb->pixel_format));
> >>>>>      ^~~~~~~~~~~~~~~~~~~
> >>>>> In file included from ./include/drm/drmP.h:71:0,
> >>>>>                  from drivers/gpu/drm/drm_atomic.c:29:
> >>>>> ./include/drm/drm_fourcc.h:65:7: note: declared here
> >>>>>  char *drm_get_format_name(uint32_t format, struct
> >>>>>  drm_format_name_buf *buf);
> >>>>>        ^~~~~~~~~~~~~~~~~~~
> >>>>> 
> >>>>> Can you pls rebase onto drm-misc or linux-next or something?
> >>>> 
> >>>> That was based on airlied/drm-next (last fetched on Sunday I think),
> >>>> I can rebase it on drm-misc if it helps, but it seems older than
> >>>> drm-next. Should I just rebase on top of current head of drm-next?
> >>> 
> >>> It needs to be drm-misc (linux-next doesn't have it yet) due to the
> >>> new atomic debug work that we just landed. I'm working on drm-tip as a
> >>> drm local integration tree to ease pains like these a bit, but that
> >>> doesn't really exist yet.
> >> 
> >> I'm confused as to how the different trees and branches merge back to
> >> Torvalds' tree (I'm interested in particular in drm), and I'm not sure
> >> which branch you want me to rebase on in the drm-misc tree [1],
> >> especially since all of them are older than drm-next [2].
> >> 
> >> I'll try to rebase on drm-misc-fixes (currently at 4da5caa6a6f82cda3193)
> >> as it sounds about right, but it doesn't apply at all, so it'll take
> >> a little while.
> > 
> > While at it, could you make the function return a const char * ?
> 
> I thought I mentioned that too, though I didn't insist.

You did, and I think Eric agreed to change that.

> > By the way, while this is an improvement over the current situation in
> > that it fixes the missing kfree() issue, I wonder whether the problem
> > we're trying to solve should be addressed at a more global level.
> 
> Maybe, but let's not block this one!

Sure, that wasn't the intent of my e-mail.

> > The issue here is that printk can't format the fourcc as a string by
> > itself. There's a bunch of places in the kernel where a similar
> > formatting problem occurs. In a few occasions it has been solved by
> > extending printk with additional format specifiers (such as for MAC/IP
> > addresses, GUIDs, various kind of device names, ...). DRM fourccs are
> > probably too DRM specific to be worth a format specifier, but I wonder
> > whether we could introduce a new specifier that takes a function pointer
> > as a formatting helper. Another similarly crazy option would be a format
> > specifier for strings that would free the passed pointer after printing
> > it.
> 
> I think there are too many non-standard format specifiers already. I
> can't review the non-standard format strings without looking at
> Documentation/prink-formats.txt first. The formatting hook would be a
> generic alternative, but that's more than a little scary from the
> security standpoint. And what if the hook has to allocate memory? Can't
> do that in atomic contexts.

There are lots of details to sort out obviously and I don't have an answer to 
all questions yet. I think it would be worth researching this, as the problem 
isn't specific to DRM/KMS.

> >> Could you give me a quick explanation or point me to a doc/page that
> >> explains how the various trees and branches get merged?
> >> I googled a bit and found this doc [4] by Jani, but it doesn't mention
> >> drm-misc for instance, so I'm not sure how up-to-date and
> >> non-intel-specific it is.
> >> 
> >> Looking at this page, something just occurred to me: did you mean
> >> drm-fixes [3], instead of one of the branches on drm-misc?
> >> 
> >> Cheers,
> >> 
> >>   Eric
> >> 
> >> [1] git://anongit.freedesktop.org/drm/drm-misc
> >> [2] git://people.freedesktop.org/~airlied/linux drm-next
> >> [2] git://people.freedesktop.org/~airlied/linux drm-fixes
> >> [3] https://01.org/linuxgraphics/gfx-docs/maintainer-tools/drm-intel.html

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Intel-gfx] [PATCH v3] drm: move allocation out of drm_get_format_name()
  2016-11-10 10:59                                         ` Laurent Pinchart
@ 2016-11-10 11:03                                           ` Jani Nikula
  0 siblings, 0 replies; 28+ messages in thread
From: Jani Nikula @ 2016-11-10 11:03 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Eric Engestrom, Daniel Vetter, Eric Engestrom,
	Linux Kernel Mailing List, David Airlie, dri-devel, Wei Yongjun,
	Daniel Vetter, Flora Cui, Gustavo Padovan, Tom St Denis,
	Chunming Zhou, Thomas Hellstrom, Laurent Pinchart, Sinclair Yeh,
	Xinliang Liu, Xinwei Kong, VMware Graphics, Vitaly Prosyak,
	Alexandre Demers, intel-gfx, Emily Deng, Colin Ian King,
	Junwei Zhang, Michel Dänzer, Alex Deucher,
	Christian König

On Thu, 10 Nov 2016, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote:
> Hi Jani,
>
> On Thursday 10 Nov 2016 12:30:09 Jani Nikula wrote:
>> On Thu, 10 Nov 2016, Laurent Pinchart wrote:
>> > The issue here is that printk can't format the fourcc as a string by
>> > itself. There's a bunch of places in the kernel where a similar
>> > formatting problem occurs. In a few occasions it has been solved by
>> > extending printk with additional format specifiers (such as for MAC/IP
>> > addresses, GUIDs, various kind of device names, ...). DRM fourccs are
>> > probably too DRM specific to be worth a format specifier, but I wonder
>> > whether we could introduce a new specifier that takes a function pointer
>> > as a formatting helper. Another similarly crazy option would be a format
>> > specifier for strings that would free the passed pointer after printing
>> > it.
>> 
>> I think there are too many non-standard format specifiers already. I
>> can't review the non-standard format strings without looking at
>> Documentation/prink-formats.txt first. The formatting hook would be a
>> generic alternative, but that's more than a little scary from the
>> security standpoint. And what if the hook has to allocate memory? Can't
>> do that in atomic contexts.
>
> There are lots of details to sort out obviously and I don't have an answer to 
> all questions yet. I think it would be worth researching this, as the problem 
> isn't specific to DRM/KMS.

That's easy to agree to; as much as you didn't mean to shoot down the
patch, I didn't mean to shoot down your idea! :)

BR,
Jani.


-- 
Jani Nikula, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Intel-gfx] [PATCH v3] drm: move allocation out of drm_get_format_name()
  2016-11-09 16:59                                   ` Eric Engestrom
  2016-11-10 10:03                                     ` Laurent Pinchart
@ 2016-11-11  9:26                                     ` Daniel Vetter
  2016-11-12  1:12                                       ` [PATCH v4] " Eric Engestrom
  1 sibling, 1 reply; 28+ messages in thread
From: Daniel Vetter @ 2016-11-11  9:26 UTC (permalink / raw)
  To: Eric Engestrom
  Cc: Daniel Vetter, Eric Engestrom, Linux Kernel Mailing List,
	David Airlie, dri-devel, Wei Yongjun, Daniel Vetter, Flora Cui,
	Gustavo Padovan, Tom St Denis, Chunming Zhou, Thomas Hellstrom,
	Laurent Pinchart, Sinclair Yeh, Xinliang Liu, Xinwei Kong,
	VMware Graphics, Vitaly Prosyak, Alexandre Demers, Jani Nikula,
	intel-gfx, Emily Deng, Colin Ian King, Junwei Zhang,
	Michel Dänzer, Alex Deucher, Christian König

On Wed, Nov 09, 2016 at 04:59:31PM +0000, Eric Engestrom wrote:
> On Wednesday, 2016-11-09 14:13:40 +0100, Daniel Vetter wrote:
> > On Wed, Nov 9, 2016 at 12:42 PM, Eric Engestrom
> > <eric.engestrom@imgtec.com> wrote:
> > >> Well, had to drop it again since it didn't compile:
> > >>
> > >>
> > >>   CC [M]  drivers/gpu/drm/drm_blend.o
> > >> drivers/gpu/drm/drm_atomic.c: In function ‘drm_atomic_plane_print_state’:
> > >> drivers/gpu/drm/drm_atomic.c:920:5: error: too few arguments to function ‘drm_get_format_name’
> > >>      drm_get_format_name(fb->pixel_format));
> > >>      ^~~~~~~~~~~~~~~~~~~
> > >> In file included from ./include/drm/drmP.h:71:0,
> > >>                  from drivers/gpu/drm/drm_atomic.c:29:
> > >> ./include/drm/drm_fourcc.h:65:7: note: declared here
> > >>  char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
> > >>        ^~~~~~~~~~~~~~~~~~~
> > >>
> > >> Can you pls rebase onto drm-misc or linux-next or something?
> > >
> > > That was based on airlied/drm-next (last fetched on Sunday I think),
> > > I can rebase it on drm-misc if it helps, but it seems older than
> > > drm-next.
> > > Should I just rebase on top of current head of drm-next?
> > 
> > It needs to be drm-misc (linux-next doesn't have it yet) due to the
> > new atomic debug work that we just landed. I'm working on drm-tip as a
> > drm local integration tree to ease pains like these a bit, but that
> > doesn't really exist yet.
> 
> I'm confused as to how the different trees and branches merge back to
> Torvalds' tree (I'm interested in particular in drm), and I'm not sure
> which branch you want me to rebase on in the drm-misc tree [1],
> especially since all of them are older than drm-next [2].

Dave just pulled in all outstanding pull requests, so just basing on top
of his drm-next should be good enough.

> I'll try to rebase on drm-misc-fixes (currently at 4da5caa6a6f82cda3193)
> as it sounds about right, but it doesn't apply at all, so it'll take
> a little while.
> 
> Could you give me a quick explanation or point me to a doc/page that
> explains how the various trees and branches get merged?
> I googled a bit and found this doc [4] by Jani, but it doesn't mention
> drm-misc for instance, so I'm not sure how up-to-date and
> non-intel-specific it is.

We atm don't have it :( drm-misc was kinda just a (very long running)
experiment, but I want to know make it official. Unfortunately the
scripting rework to split out a new drm-misc.git repo is taking a bit
longer. Atm things are still in flux, but I hope that'll settle soon-ish.

> Looking at this page, something just occurred to me: did you mean
> drm-fixes [3], instead of one of the branches on drm-misc?
> 
> Cheers,
>   Eric
> 
> [1] git://anongit.freedesktop.org/drm/drm-misc

Yeah, that's the new location, but atm it's just under testing and it's
not the real drm-misc. That one is in drm-intel.git, in the topic/drm-misc
branch.

> [2] git://people.freedesktop.org/~airlied/linux drm-next
> [2] git://people.freedesktop.org/~airlied/linux drm-fixes
> [3] https://01.org/linuxgraphics/gfx-docs/maintainer-tools/drm-intel.html

https://01.org/linuxgraphics/gfx-docs/maintainer-tools/drm-misc.html

We need to flesh that out, and maybe feature it a bit more prominently.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v4] drm: move allocation out of drm_get_format_name()
  2016-11-11  9:26                                     ` Daniel Vetter
@ 2016-11-12  1:12                                       ` Eric Engestrom
  0 siblings, 0 replies; 28+ messages in thread
From: Eric Engestrom @ 2016-11-12  1:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Christian König, Jani Nikula, Rob Clark, Sinclair Yeh,
	Ville Syrjälä,
	Eric Engestrom, Alex Deucher, David Airlie, Xinliang Liu,
	Daniel Vetter, Jani Nikula, VMware Graphics, Thomas Hellstrom,
	Tom St Denis, Michel Dänzer, Gustavo Padovan, Emily Deng,
	Chunming Zhou, Flora Cui, Vitaly Prosyak, Colin Ian King,
	Ken Wang, Alexandre Demers, Junwei Zhang, Xinwei Kong,
	Chris Wilson, Laurent Pinchart, Wei Yongjun, dri-devel,
	intel-gfx

The function's behaviour was changed in 90844f00049e, 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: 90844f00049e ("drm: make drm_get_format_name thread-safe")
Cc: Rob Clark <robdclark@gmail.com>
Cc: Christian König <christian.koenig@amd.com>
Acked-by: Christian König <christian.koenig@amd.com>
Acked-by: Rob Clark <robdclark@gmail.com>
Acked-by: Sinclair Yeh <syeh@vmware.com> (vmwgfx)
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
---
v4 - rebase on drm-next (d8c1abd968f1c880ad8c)
   - add missed `const` to the return value

v3 - fix "Fixes" tag, replace it with an actual commit message
   - collect ack & r-b

v2 - use single-field struct instead of typedef to let the compiler
     enforce the type (Christian König)
---
 include/drm/drm_fourcc.h                        | 10 +++++-
 drivers/gpu/drm/drm_fourcc.c                    | 14 +++------
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c          |  7 ++---
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c          |  7 ++---
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c           |  3 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c           |  7 ++---
 drivers/gpu/drm/drm_atomic.c                    | 10 +++---
 drivers/gpu/drm/drm_crtc.c                      |  7 +++--
 drivers/gpu/drm/drm_framebuffer.c               |  7 +++--
 drivers/gpu/drm/drm_modeset_helper.c            |  7 +++--
 drivers/gpu/drm/drm_plane.c                     |  7 +++--
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  7 ++---
 drivers/gpu/drm/i915/i915_debugfs.c             | 10 +++---
 drivers/gpu/drm/i915/intel_atomic_plane.c       |  8 ++---
 drivers/gpu/drm/i915/intel_display.c            | 41 ++++++++++---------------
 drivers/gpu/drm/radeon/atombios_crtc.c          | 14 ++++-----
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c             |  3 +-
 17 files changed, 82 insertions(+), 87 deletions(-)

diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index dc0aafa..fcc08da 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -45,6 +45,14 @@ struct drm_format_info {
 	u8 vsub;
 };
 
+/**
+ * struct drm_format_name_buf - name of a DRM format
+ * @str: string buffer containing the format name
+ */
+struct drm_format_name_buf {
+	char str[32];
+};
+
 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);
@@ -54,6 +62,6 @@ int drm_format_horz_chroma_subsampling(uint32_t format);
 int drm_format_vert_chroma_subsampling(uint32_t format);
 int drm_format_plane_width(int width, uint32_t format, int plane);
 int drm_format_plane_height(int height, uint32_t format, int plane);
-char *drm_get_format_name(uint32_t format) __malloc;
+const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
 
 #endif /* __DRM_FOURCC_H__ */
diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index cbb8b77..90d2cc8 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -79,17 +79,13 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
 EXPORT_SYMBOL(drm_mode_legacy_fb_format);
 
 /**
- * drm_get_format_name - return a string for drm fourcc format
+ * drm_get_format_name - fill a string with a drm fourcc format's name
  * @format: format to compute name of
+ * @buf: caller-supplied buffer
- *
- * Note that the buffer returned by this function is owned by the caller
- * and will need to be freed using kfree().
  */
-char *drm_get_format_name(uint32_t format)
+const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf)
 {
-	char *buf = kmalloc(32, GFP_KERNEL);
-
-	snprintf(buf, 32,
+	snprintf(buf->str, sizeof(buf->str),
 		 "%c%c%c%c %s-endian (0x%08x)",
 		 printable_char(format & 0xff),
 		 printable_char((format >> 8) & 0xff),
@@ -98,7 +94,7 @@ char *drm_get_format_name(uint32_t format)
 		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
 		 format);
 
-	return buf;
+	return buf->str;
 }
 EXPORT_SYMBOL(drm_get_format_name);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
index 679dd73..65a954c 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
@@ -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;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
index 807dfed..d807e87 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
@@ -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;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
index 5742333..c1bd1be 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
@@ -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;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
index 6f7656d..4ae5991 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
@@ -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;
 	}
 
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index f5ea7db..57e0a6e9 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -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++) {
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index ce274ed..5745464 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -827,9 +827,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
 			ret = drm_plane_check_pixel_format(crtc->primary,
 							   fb->pixel_format);
 			if (ret) {
-				char *format_name = drm_get_format_name(fb->pixel_format);
-				DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
-				kfree(format_name);
+				struct drm_format_name_buf format_name;
+				DRM_DEBUG_KMS("Invalid pixel format %s\n",
+				              drm_get_format_name(fb->pixel_format,
+				                                  &format_name));
 				goto out;
 			}
 		}
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index af786f2..06ad3d1 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -133,9 +133,10 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
 
 	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);
-		kfree(format_name);
+		struct drm_format_name_buf format_name;
+		DRM_DEBUG_KMS("bad framebuffer format %s\n",
+		              drm_get_format_name(r->pixel_format,
+		                                  &format_name));
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c
index 2544dfe..2f452b3 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -75,10 +75,11 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
 
 	info = drm_format_info(mode_cmd->pixel_format);
 	if (!info || !info->depth) {
-		char *format_name = drm_get_format_name(mode_cmd->pixel_format);
+		struct drm_format_name_buf format_name;
 
-		DRM_DEBUG_KMS("non-RGB pixel format %s\n", format_name);
-		kfree(format_name);
+		DRM_DEBUG_KMS("non-RGB pixel format %s\n",
+		              drm_get_format_name(mode_cmd->pixel_format,
+		                                  &format_name));
 
 		fb->depth = 0;
 		fb->bits_per_pixel = 0;
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 249c0ae..2ba0c22 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -479,9 +479,10 @@ static int __setplane_internal(struct drm_plane *plane,
 	/* Check whether this plane supports the fb pixel format. */
 	ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
 	if (ret) {
-		char *format_name = drm_get_format_name(fb->pixel_format);
-		DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name);
-		kfree(format_name);
+		struct drm_format_name_buf format_name;
+		DRM_DEBUG_KMS("Invalid pixel format %s\n",
+		              drm_get_format_name(fb->pixel_format,
+		                                  &format_name));
 		goto out;
 	}
 
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 7e7a4d4..afc2b5d 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -608,17 +608,16 @@ static void ade_rdma_set(void __iomem *base, struct drm_framebuffer *fb,
 			 u32 ch, u32 y, u32 in_h, u32 fmt)
 {
 	struct drm_gem_cma_object *obj = drm_fb_cma_get_gem_obj(fb, 0);
-	char *format_name;
+	struct drm_format_name_buf format_name;
 	u32 reg_ctrl, reg_addr, reg_size, reg_stride, reg_space, reg_en;
 	u32 stride = fb->pitches[0];
 	u32 addr = (u32)obj->paddr + y * stride;
 
 	DRM_DEBUG_DRIVER("rdma%d: (y=%d, height=%d), stride=%d, paddr=0x%x\n",
 			 ch + 1, y, in_h, stride, (u32)obj->paddr);
-	format_name = drm_get_format_name(fb->pixel_format);
 	DRM_DEBUG_DRIVER("addr=0x%x, fb:%dx%d, pixel_format=%d(%s)\n",
-			 addr, fb->width, fb->height, fmt, format_name);
-	kfree(format_name);
+			 addr, fb->width, fb->height, fmt,
+			 drm_get_format_name(fb->pixel_format, &format_name));
 
 	/* get reg offset */
 	reg_ctrl = RD_CH_CTRL(ch);
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index c9465fb..7166a1a 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -3032,7 +3032,7 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 	for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
 		struct drm_plane_state *state;
 		struct drm_plane *plane = &intel_plane->base;
-		char *format_name;
+		struct drm_format_name_buf format_name;
 
 		if (!plane->state) {
 			seq_puts(m, "plane->state is NULL!\n");
@@ -3042,9 +3042,9 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 		state = plane->state;
 
 		if (state->fb) {
-			format_name = drm_get_format_name(state->fb->pixel_format);
+			drm_get_format_name(state->fb->pixel_format, &format_name);
 		} else {
-			format_name = kstrdup("N/A", GFP_KERNEL);
+			sprintf(format_name.str, "N/A");
 		}
 
 		seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
@@ -3060,10 +3060,8 @@ static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
 			   ((state->src_w & 0xffff) * 15625) >> 10,
 			   (state->src_h >> 16),
 			   ((state->src_h & 0xffff) * 15625) >> 10,
-			   format_name,
+			   format_name.str,
 			   plane_rotation(state->rotation));
-
-		kfree(format_name);
 	}
 }
 
diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c b/drivers/gpu/drm/i915/intel_atomic_plane.c
index cb55944..984a6b7 100644
--- a/drivers/gpu/drm/i915/intel_atomic_plane.c
+++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
@@ -141,7 +141,7 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
 		crtc_state->base.enable ? crtc_state->pipe_src_h : 0;
 
 	if (state->fb && drm_rotation_90_or_270(state->rotation)) {
-		char *format_name;
+		struct drm_format_name_buf format_name;
 
 		if (!(state->fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
 			state->fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED)) {
@@ -157,9 +157,9 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
 		switch (state->fb->pixel_format) {
 		case DRM_FORMAT_C8:
 		case DRM_FORMAT_RGB565:
-			format_name = drm_get_format_name(state->fb->pixel_format);
-			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
+			              drm_get_format_name(state->fb->pixel_format,
+			                                  &format_name));
 			return -EINVAL;
 
 		default:
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index f4e3218..6fd6283 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -12851,7 +12851,7 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 
 	DRM_DEBUG_KMS("planes on this crtc\n");
 	list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
-		char *format_name;
+		struct drm_format_name_buf format_name;
 		intel_plane = to_intel_plane(plane);
 		if (intel_plane->pipe != crtc->pipe)
 			continue;
@@ -12864,12 +12864,11 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 			continue;
 		}
 
-		format_name = drm_get_format_name(fb->pixel_format);
-
 		DRM_DEBUG_KMS("[PLANE:%d:%s] enabled",
 			      plane->base.id, plane->name);
 		DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s",
-			      fb->base.id, fb->width, fb->height, format_name);
+			      fb->base.id, fb->width, fb->height,
+			      drm_get_format_name(fb->pixel_format, &format_name));
 		DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
 			      state->scaler_id,
 			      state->base.src.x1 >> 16,
@@ -12879,8 +12878,6 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
 			      state->base.dst.x1, state->base.dst.y1,
 			      drm_rect_width(&state->base.dst),
 			      drm_rect_height(&state->base.dst));
-
-		kfree(format_name);
 	}
 }
 
@@ -15745,7 +15742,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	unsigned int tiling = i915_gem_object_get_tiling(obj);
 	int ret;
 	u32 pitch_limit, stride_alignment;
-	char *format_name;
+	struct drm_format_name_buf format_name;
 
 	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
 
@@ -15836,18 +15833,16 @@ static int intel_framebuffer_init(struct drm_device *dev,
 		break;
 	case DRM_FORMAT_XRGB1555:
 		if (INTEL_INFO(dev)->gen > 3) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
 			return -EINVAL;
 		}
 		break;
 	case DRM_FORMAT_ABGR8888:
 		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
 		    INTEL_INFO(dev)->gen < 9) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
 			return -EINVAL;
 		}
 		break;
@@ -15855,17 +15850,15 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	case DRM_FORMAT_XRGB2101010:
 	case DRM_FORMAT_XBGR2101010:
 		if (INTEL_INFO(dev)->gen < 4) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
 			return -EINVAL;
 		}
 		break;
 	case DRM_FORMAT_ABGR2101010:
 		if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
 			return -EINVAL;
 		}
 		break;
@@ -15874,16 +15867,14 @@ static int intel_framebuffer_init(struct drm_device *dev,
 	case DRM_FORMAT_YVYU:
 	case DRM_FORMAT_VYUY:
 		if (INTEL_INFO(dev)->gen < 5) {
-			format_name = drm_get_format_name(mode_cmd->pixel_format);
-			DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-			kfree(format_name);
+			DRM_DEBUG("unsupported pixel format: %s\n",
+			          drm_get_format_name(mode_cmd->pixel_format, &format_name));
 			return -EINVAL;
 		}
 		break;
 	default:
-		format_name = drm_get_format_name(mode_cmd->pixel_format);
-		DRM_DEBUG("unsupported pixel format: %s\n", format_name);
-		kfree(format_name);
+		DRM_DEBUG("unsupported pixel format: %s\n",
+		          drm_get_format_name(mode_cmd->pixel_format, &format_name));
 		return -EINVAL;
 	}
 
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index 74f99ba..05f4ebe 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -1156,7 +1156,7 @@ static int dce4_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) {
@@ -1260,9 +1260,8 @@ static int dce4_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;
 	}
 
@@ -1473,7 +1472,7 @@ static int avivo_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) {
@@ -1563,9 +1562,8 @@ static int avivo_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;
 	}
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index c965514..e3f68cc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -985,8 +985,9 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
 
 	info = drm_format_info(mode_cmd2->pixel_format);
 	if (!info || !info->depth) {
+		struct drm_format_name_buf format_name;
 		DRM_ERROR("Unsupported framebuffer format %s\n",
-			  drm_get_format_name(mode_cmd2->pixel_format));
+		          drm_get_format_name(mode_cmd2->pixel_format, &format_name));
 		return ERR_PTR(-EINVAL);
 	}
 
-- 
Cheers,
  Eric

^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2016-11-12  1:16 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20161105012344.GA28349@engestrom.ch>
2016-11-05  1:33 ` [PATCH] drm: move allocation out of drm_get_format_name() Eric Engestrom
2016-11-05  6:56   ` Thomas Hellstrom
2016-11-05 12:11   ` Christian König
2016-11-05 16:38     ` Eric Engestrom
2016-11-05 16:49       ` Rob Clark
2016-11-06  9:47         ` Christian König
2016-11-06 13:03           ` Rob Clark
2016-11-07  0:47             ` Eric Engestrom
2016-11-07  0:48               ` [PATCH v2] " Eric Engestrom
2016-11-07  7:46                 ` Christian König
2016-11-07  8:10                 ` Jani Nikula
2016-11-07 17:12                   ` Eric Engestrom
2016-11-07 17:38                     ` Jani Nikula
2016-11-08 10:15                       ` [Intel-gfx] " Daniel Vetter
2016-11-09  0:17                         ` [PATCH v3] " Eric Engestrom
2016-11-09  1:09                           ` [Intel-gfx] " Daniel Vetter
2016-11-09  1:13                             ` Daniel Vetter
2016-11-09 11:42                               ` Eric Engestrom
2016-11-09 13:13                                 ` Daniel Vetter
2016-11-09 16:59                                   ` Eric Engestrom
2016-11-10 10:03                                     ` Laurent Pinchart
2016-11-10 10:30                                       ` Jani Nikula
2016-11-10 10:59                                         ` Laurent Pinchart
2016-11-10 11:03                                           ` Jani Nikula
2016-11-11  9:26                                     ` Daniel Vetter
2016-11-12  1:12                                       ` [PATCH v4] " Eric Engestrom
2016-11-07 14:45                 ` [PATCH v2] " Rob Clark
2016-11-07 18:12                 ` Sinclair Yeh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).