[PATCH 4/8] drm/fb-helper: Allocate a drm_file

Noralf Trønnes
2017-09-11T14:31:58Z

Allocate a drm_file so drivers can use drm_framebuffer_create_dumb()
to create a buffer. The framebuffer is reaped automtically in
drm_fb_helper_fini().

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
drivers/gpu/drm/drm_fb_helper.c | 22 ++++++++++++++++++++--
include/drm/drm_fb_helper.h | 9 +++++++++
2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 6a31d13..a04bdf9 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -35,6 +35,7 @@
#include <linux/slab.h>
#include <linux/module.h>
#include <drm/drmP.h>
+#include <drm/drm_auth.h>
#include <drm/drm_crtc.h>
#include <drm/drm_fb_helper.h>
#include <drm/drm_crtc_helper.h>
@@ -902,6 +903,7 @@ EXPORT_SYMBOL(drm_fb_helper_unregister_fbi);
*
* This cleans up all remaining resources associated with @fb_helper. Must be
* called after drm_fb_helper_unlink_fbi() was called.
+ * drm_framebuffer_create_dumb() created framebuffers will be destroyed.
*/
void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
{
@@ -932,6 +934,7 @@ void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
mutex_destroy(&fb_helper->lock);
drm_fb_helper_crtc_free(fb_helper);

+ drm_file_free(fb_helper->file);
}
EXPORT_SYMBOL(drm_fb_helper_fini);

@@ -2465,6 +2468,16 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper,
unsigned int width, height;
int ret;

+ fb_helper->file = drm_file_alloc(dev->primary);
+ if (IS_ERR(fb_helper->file)) {
+ ret = PTR_ERR(fb_helper->file);
+ fb_helper->file = NULL;
+ mutex_unlock(&fb_helper->lock);
+ return ret;
+ }
+
+ drm_dropmaster_ioctl(dev, NULL, fb_helper->file);
+
width = dev->mode_config.max_width;
height = dev->mode_config.max_height;

@@ -2478,7 +2491,7 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper,
}
mutex_unlock(&fb_helper->lock);

- return ret;
+ goto err_free_file;
}
drm_setup_crtcs_fb(fb_helper);

@@ -2494,7 +2507,7 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper,

ret = register_framebuffer(info);
if (ret < 0)
- return ret;
+ goto err_free_file;

dev_info(dev->dev, "fb%d: %s frame buffer device\n",
info->node, info->fix.id);
@@ -2507,6 +2520,11 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper,
mutex_unlock(&kernel_fb_helper_lock);

return 0;
+
+err_free_file:
+ drm_file_free(fb_helper->file);
+
+ return ret;
}

/**
diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h
index 33fe959..89757ff 100644
--- a/include/drm/drm_fb_helper.h
+++ b/include/drm/drm_fb_helper.h
@@ -154,6 +154,15 @@ struct drm_fb_helper_connector {
struct drm_fb_helper {
struct drm_framebuffer *fb;
struct drm_device *dev;
+
+ /**
+ * @file:
+ *
+ * DRM file that can be used with drm_framebuffer_create_dumb() to
+ * create a framebuffer to back fbdev.
+ */
+ struct drm_file *file;
+
int crtc_count;
struct drm_fb_helper_crtc *crtc_info;
int connector_count;