drivers/video/fbdev/core/fbmem.c | 30 ++++++++++++++++++++++++++++++ include/linux/fb.h | 1 + 2 files changed, 31 insertions(+)
Introduce a device-managed variant of register_framebuffer() which
automatically unregisters the framebuffer on device destruction.
This can simplify the error handling and resource management in drivers.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
This is a fixed resend of [0], which was broken.
Thanks to Bert [1], and Chaitanya Kumar [2]
for reporting the issue.
[0] https://lore.kernel.org/lkml/20240827-efifb-sysfs-v1-3-c9cc3e052180@weissschuh.net/
[1] https://lore.kernel.org/lkml/20240829224124.2978-1-spasswolf@web.de/
[2] https://lore.kernel.org/lkml/SJ1PR11MB612925C1C533C09F8F62F7CBB9972@SJ1PR11MB6129.namprd11.prod.outlook.com/
Helge, I didn't document the function devm_unregister_framebuffer() as
it is only an internal helper and will ever only used by one user,
similar to other helpers in fbmem.c.
---
drivers/video/fbdev/core/fbmem.c | 30 ++++++++++++++++++++++++++++++
include/linux/fb.h | 1 +
2 files changed, 31 insertions(+)
diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
index 4c4ad0a86a50..3c568cff2913 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -544,6 +544,36 @@ unregister_framebuffer(struct fb_info *fb_info)
}
EXPORT_SYMBOL(unregister_framebuffer);
+static void devm_unregister_framebuffer(void *data)
+{
+ struct fb_info *info = data;
+
+ unregister_framebuffer(info);
+}
+
+/**
+ * devm_register_framebuffer - resource-managed frame buffer device registration
+ * @dev: device the framebuffer belongs to
+ * @fb_info: frame buffer info structure
+ *
+ * Registers a frame buffer device @fb_info to device @dev.
+ *
+ * Returns negative errno on error, or zero for success.
+ *
+ */
+int
+devm_register_framebuffer(struct device *dev, struct fb_info *fb_info)
+{
+ int ret;
+
+ ret = register_framebuffer(fb_info);
+ if (ret)
+ return ret;
+
+ return devm_add_action_or_reset(dev, devm_unregister_framebuffer, fb_info);
+}
+EXPORT_SYMBOL(devm_register_framebuffer);
+
/**
* fb_set_suspend - low level driver signals suspend
* @info: framebuffer affected
diff --git a/include/linux/fb.h b/include/linux/fb.h
index db7d97b10964..abf6643ebcaf 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -601,6 +601,7 @@ extern ssize_t fb_sys_write(struct fb_info *info, const char __user *buf,
/* fbmem.c */
extern int register_framebuffer(struct fb_info *fb_info);
extern void unregister_framebuffer(struct fb_info *fb_info);
+extern int devm_register_framebuffer(struct device *dev, struct fb_info *fb_info);
extern char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size);
extern void fb_pad_unaligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 idx,
u32 height, u32 shift_high, u32 shift_low, u32 mod);
---
base-commit: 20371ba120635d9ab7fc7670497105af8f33eb08
change-id: 20240830-fbdev-devm_register_framebuffer-647e9c103b9a
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
On 8/30/24 11:45, Thomas Weißschuh wrote: > Introduce a device-managed variant of register_framebuffer() which > automatically unregisters the framebuffer on device destruction. > This can simplify the error handling and resource management in drivers. > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > --- > This is a fixed resend of [0], which was broken. > Thanks to Bert [1], and Chaitanya Kumar [2] > for reporting the issue. > > [0] https://lore.kernel.org/lkml/20240827-efifb-sysfs-v1-3-c9cc3e052180@weissschuh.net/ > [1] https://lore.kernel.org/lkml/20240829224124.2978-1-spasswolf@web.de/ > [2] https://lore.kernel.org/lkml/SJ1PR11MB612925C1C533C09F8F62F7CBB9972@SJ1PR11MB6129.namprd11.prod.outlook.com/ I've applied this patch to the fbdev git tree. Please double check at https://git.kernel.org/pub/scm/linux/kernel/git/deller/linux-fbdev.git/log/?h=for-next Can you please check if this fixes this new report too: https://marc.info/?l=linux-fbdev&m=172500784802901&w=2 > Helge, I didn't document the function devm_unregister_framebuffer() as > it is only an internal helper and will ever only used by one user, > similar to other helpers in fbmem.c. Ok. Helge
On 2024-08-30 12:16:46+0000, Helge Deller wrote: > On 8/30/24 11:45, Thomas Weißschuh wrote: > > Introduce a device-managed variant of register_framebuffer() which > > automatically unregisters the framebuffer on device destruction. > > This can simplify the error handling and resource management in drivers. > > > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > > --- > > This is a fixed resend of [0], which was broken. > > Thanks to Bert [1], and Chaitanya Kumar [2] > > for reporting the issue. > > > > [0] https://lore.kernel.org/lkml/20240827-efifb-sysfs-v1-3-c9cc3e052180@weissschuh.net/ > > [1] https://lore.kernel.org/lkml/20240829224124.2978-1-spasswolf@web.de/ > > [2] https://lore.kernel.org/lkml/SJ1PR11MB612925C1C533C09F8F62F7CBB9972@SJ1PR11MB6129.namprd11.prod.outlook.com/ > > I've applied this patch to the fbdev git tree. > Please double check at > https://git.kernel.org/pub/scm/linux/kernel/git/deller/linux-fbdev.git/log/?h=for-next Looks good. Sorry for the extra effort necessary. > Can you please check if this fixes this new report too: > https://marc.info/?l=linux-fbdev&m=172500784802901&w=2 I double check it and am decently sure it's the same issue. It tries to unregister the framebuffer but then notices that it never was registered in the first place. > > Helge, I didn't document the function devm_unregister_framebuffer() as > > it is only an internal helper and will ever only used by one user, > > similar to other helpers in fbmem.c. > > Ok. > > Helge
On 8/30/24 12:16, Helge Deller wrote: > On 8/30/24 11:45, Thomas Weißschuh wrote: >> Introduce a device-managed variant of register_framebuffer() which >> automatically unregisters the framebuffer on device destruction. >> This can simplify the error handling and resource management in drivers. >> >> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> >> --- >> This is a fixed resend of [0], which was broken. >> Thanks to Bert [1], and Chaitanya Kumar [2] >> for reporting the issue. >> >> [0] https://lore.kernel.org/lkml/20240827-efifb-sysfs-v1-3-c9cc3e052180@weissschuh.net/ >> [1] https://lore.kernel.org/lkml/20240829224124.2978-1-spasswolf@web.de/ >> [2] https://lore.kernel.org/lkml/SJ1PR11MB612925C1C533C09F8F62F7CBB9972@SJ1PR11MB6129.namprd11.prod.outlook.com/ > > I've applied this patch to the fbdev git tree. > Please double check at > https://git.kernel.org/pub/scm/linux/kernel/git/deller/linux-fbdev.git/log/?h=for-next > > Can you please check if this fixes this new report too: > https://marc.info/?l=linux-fbdev&m=172500784802901&w=2 Please ignore this ^^^. You already mentioned this one above. Helge >> Helge, I didn't document the function devm_unregister_framebuffer() as >> it is only an internal helper and will ever only used by one user, >> similar to other helpers in fbmem.c. > > Ok. > > Helge
© 2016 - 2026 Red Hat, Inc.