diff mbox

[1/2] drm: add field in drm_framebuffer to identify internally owned fbs

Message ID 20171207030142.2954-1-gurchetansingh@chromium.org (mailing list archive)
State New, archived
Headers show

Commit Message

Gurchetan Singh Dec. 7, 2017, 3:01 a.m. UTC
We create an internal framebuffer when using the legacy cursor ioctls, but
using the legacy API, userspace has no way of freeing this resource. This
patch introduces a field in struct drm_framebuffer to keep track of
internally owned framebuffers.

Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
---
 drivers/gpu/drm/drm_crtc_internal.h | 3 ++-
 drivers/gpu/drm/drm_framebuffer.c   | 7 +++++--
 drivers/gpu/drm/drm_plane.c         | 4 +++-
 include/drm/drm_framebuffer.h       | 5 +++++
 4 files changed, 15 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
index 9ebb8841778c..338c583b3d60 100644
--- a/drivers/gpu/drm/drm_crtc_internal.h
+++ b/drivers/gpu/drm/drm_crtc_internal.h
@@ -153,7 +153,8 @@  int drm_mode_getconnector(struct drm_device *dev,
 struct drm_framebuffer *
 drm_internal_framebuffer_create(struct drm_device *dev,
 				const struct drm_mode_fb_cmd2 *r,
-				struct drm_file *file_priv);
+				struct drm_file *file_priv,
+				bool internal);
 void drm_framebuffer_free(struct kref *kref);
 int drm_framebuffer_check_src_coords(uint32_t src_x, uint32_t src_y,
 				     uint32_t src_w, uint32_t src_h,
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index d63d4c2ac4c8..bcd9d3004064 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -262,7 +262,8 @@  static int framebuffer_check(struct drm_device *dev,
 struct drm_framebuffer *
 drm_internal_framebuffer_create(struct drm_device *dev,
 				const struct drm_mode_fb_cmd2 *r,
-				struct drm_file *file_priv)
+				struct drm_file *file_priv,
+				bool internal)
 {
 	struct drm_mode_config *config = &dev->mode_config;
 	struct drm_framebuffer *fb;
@@ -300,6 +301,8 @@  drm_internal_framebuffer_create(struct drm_device *dev,
 		return fb;
 	}
 
+	fb->internal = internal;
+
 	return fb;
 }
 
@@ -327,7 +330,7 @@  int drm_mode_addfb2(struct drm_device *dev,
 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
 		return -EINVAL;
 
-	fb = drm_internal_framebuffer_create(dev, r, file_priv);
+	fb = drm_internal_framebuffer_create(dev, r, file_priv, false);
 	if (IS_ERR(fb))
 		return PTR_ERR(fb);
 
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 19404e34cd59..f2d1fba4c6d8 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -757,7 +757,9 @@  static int drm_mode_cursor_universal(struct drm_crtc *crtc,
 	 */
 	if (req->flags & DRM_MODE_CURSOR_BO) {
 		if (req->handle) {
-			fb = drm_internal_framebuffer_create(dev, &fbreq, file_priv);
+			fb = drm_internal_framebuffer_create(dev, &fbreq,
+							     file_priv,
+							     true);
 			if (IS_ERR(fb)) {
 				DRM_DEBUG_KMS("failed to wrap cursor buffer in drm framebuffer\n");
 				return PTR_ERR(fb);
diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h
index dccb897951ba..7fe856d403c5 100644
--- a/include/drm/drm_framebuffer.h
+++ b/include/drm/drm_framebuffer.h
@@ -187,6 +187,11 @@  struct drm_framebuffer {
 	 */
 	int hot_y;
 	/**
+	 * @internal: Indicates the framebuffer was created internally and not
+	 * as the result of the drm_mode_fb_cmd* ioctl.
+	 */
+	bool internal;
+	/**
 	 * @filp_head: Placed on &drm_file.fbs, protected by &drm_file.fbs_lock.
 	 */
 	struct list_head filp_head;