Skip to contentSkip to conversation

fbdev: Move framebuffer_{alloc,release}() functions to fbmem.c

RFC PATCH In review Javier Martinez Canillas 1 participant 1 message Aug 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 2/4 fbdev: Move framebuffer_{alloc,release}() functions to fbmem.c

The framebuffer_alloc() and framebuffer_release() functions are much more related with the functions in drivers/fbdev/core/fbmem.c than the ones in drivers/fbdev/core/fbsysfs.c, that are only to manage sysfs attributes.

---

 drivers/video/fbdev/core/fbmem.c   | 65 +++++++++++++++++++++++++++
 drivers/video/fbdev/core/fbsysfs.c | 71 ------------------------------
 2 files changed, 65 insertions(+), 71 deletions(-)
drivers/video/fbdev/core/fbmem.c +65 -0
index d886582c0a4..2b22e46b815 100644
@@ -57,6 +57,71 @@ bool fb_center_logo __read_mostly;
 
 int fb_logo_count __read_mostly = -1;
 
+/**
+ * framebuffer_alloc - creates a new frame buffer info structure
+ *
+ * @size: size of driver private data, can be zero
+ * @dev: pointer to the device for this fb, this can be NULL
+ *
+ * Creates a new frame buffer info structure. Also reserves @size bytes
+ * for driver private data (info->par). info->par (if any) will be
+ * aligned to sizeof(long).
+ *
+ * Returns the new structure, or NULL if an error occurred.
+ *
+ */
+struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
+{
+#define BYTES_PER_LONG (BITS_PER_LONG/8)
+#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
+	int fb_info_size = sizeof(struct fb_info);
+	struct fb_info *info;
+	char *p;
+
+	if (size)
+		fb_info_size += PADDING;
+
+	p = kzalloc(fb_info_size + size, GFP_KERNEL);
+
+	if (!p)
+		return NULL;
+
+	info = (struct fb_info *) p;
+
+	if (size)
+		info->par = p + fb_info_size;
+
+	info->device = dev;
+	info->fbcon_rotate_hint = -1;
+
+#if IS_ENABLED(CONFIG_FB_BACKLIGHT)
+	mutex_init(&info->bl_curve_mutex);
+#endif
+
+	return info;
+#undef PADDING
+#undef BYTES_PER_LONG
+}
+EXPORT_SYMBOL(framebuffer_alloc);
+
+/**
+ * framebuffer_release - marks the structure available for freeing
+ *
+ * @info: frame buffer info structure
+ *
+ * Drop the reference count of the device embedded in the
+ * framebuffer info structure.
+ *
+ */
+void framebuffer_release(struct fb_info *info)
+{
+	if (!info)
+		return;
+	kfree(info->apertures);
+	kfree(info);
+}
+EXPORT_SYMBOL(framebuffer_release);
+
 static struct fb_info *get_fb_info(unsigned int idx)
 {
 	struct fb_info *fb_info;
drivers/video/fbdev/core/fbsysfs.c +0 -71

83 lines not on this page · raw message

Signature · 1 line
2.31.1