fbdev: Make CONFIG_FB_DEVICE optional for drivers
Subsystems (4)
v2 cover fbdev: Make CONFIG_FB_DEVICE optional for drivers
This series makes CONFIG_FB_DEVICE optional for fbdev drivers that use it only for sysfs interfaces, addressing Thomas Zimmermann’s TODO to remove hard FB_DEVICE dependencies.
The series introduces a small helper, dev_of_fbinfo(), which returns NULL when CONFIG_FB_DEVICE=n. This allows sysfs code paths to be skipped via runtime checks, avoids #ifdef CONFIG_FB_DEVICE clutter, and keeps full compile-time syntax checking.
Changes in v2:
Add dev_of_fbinfo() helper (suggested by Geert Uytterhoeven) Replace #ifdef CONFIG_FB_DEVICE blocks with runtime NULL checks Switch to fb_dbg() / fb_info() logging (suggested by Thomas Zimmermann)
Chintan Patel (4):
fb: Add dev_of_fbinfo() helper for optional sysfs support
staging: fbtft: Make FB_DEVICE dependency optional
fbdev: omapfb: Make FB_DEVICE dependency optional
fbdev: sh_mobile_lcdc: Make FB_DEVICE dependency optional
drivers/staging/fbtft/Kconfig | 5 ++++- drivers/staging/fbtft/fbtft-sysfs.c | 18 ++++++++++++++---- drivers/video/fbdev/omap2/omapfb/Kconfig | 3 ++- .../video/fbdev/omap2/omapfb/omapfb-sysfs.c | 16 ++++++++++++---- drivers/video/fbdev/sh_mobile_lcdcfb.c | 9 +++++++++ include/linux/fb.h | 9 +++++++++ 6 files changed, 50 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/4 fb: Add dev_of_fbinfo() helper for optional sysfs support
Add dev_of_fbinfo() to return the framebuffer struct device when CONFIG_FB_DEVICE is enabled, or NULL otherwise.
This allows fbdev drivers to use sysfs interfaces via runtime checks instead of CONFIG_FB_DEVICE ifdefs, keeping the code clean while remaining fully buildable.
--- include/linux/fb.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/fb.h +9 -0
@@ -628,6 +628,15 @@ static inline void unlock_fb_info(struct fb_info *info)mutex_unlock (&info->lock); } +static inline struct device *dev_of_fbinfo (const struct fb_info *info) +{ +#ifdef CONFIG_FB_DEVICE +return info->dev; +#else +return NULL ; +#endif +} +static inline void __fb_pad_aligned_buffer (u8 *dst,u32 d_pitch,u8 *src,u32 s_pitch,u32 height) {
Signature · 1 line
2.43.0
Re: [PATCH v2 1/4] fb: Add dev_of_fbinfo() helper for optional sysfs support
Quoted 7 lines · Chintan Patel
Add
dev_of_fbinfo()to return the framebuffer struct device whenCONFIG_FB_DEVICEis enabled, or NULL otherwise.This allows fbdev drivers to use sysfs interfaces via runtime checks instead of
CONFIG_FB_DEVICEifdefs, keeping the code clean while remaining fully buildable.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 2/4 staging: fbtft: Make FB_DEVICE dependency optional
In reply to Chintan Patelfbtft provides sysfs interfaces for debugging and gamma configuration, but these are not required for the core driver.
Drop the hard dependency on CONFIG_FB_DEVICE and make sysfs support optional by using dev_of_fbinfo() at runtime. When FB_DEVICE is disabled, sysfs operations are skipped while the code remains buildable and type-checked.
v2:
- Replace CONFIG_FB_DEVICE ifdefs with runtime checks
- Use dev_of_fbinfo() to guard sysfs creation and removal
--- drivers/staging/fbtft/Kconfig | 5 ++++- drivers/staging/fbtft/fbtft-sysfs.c | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-)
drivers/staging/fbtft/Kconfig +4 -1
@@ -2,11 +2,14 @@ menuconfig FB_TFT tristate "Support for small TFT LCD display modules" depends on FB && SPI - depends on FB_DEVICE depends on BACKLIGHT_CLASS_DEVICE depends on GPIOLIB || COMPILE_TEST select FB_BACKLIGHT select FB_SYSMEM_HELPERS_DEFERRED + help + Support for small TFT LCD display modules over SPI bus. FB_DEVICE + is not required, but if enabled, provides sysfs interface for debugging + and gamma curve configuration. if FB_TFT
drivers/staging/fbtft/fbtft-sysfs.c +14 -4
@@ -203,14 +203,24 @@ static struct device_attribute debug_device_attr =void fbtft_sysfs_init (struct fbtft_par *par) { -device_create_file (par->info->dev, &debug_device_attr); +struct device *dev =dev_of_fbinfo (par->info); + +if (!dev) +return ; + +device_create_file (dev, &debug_device_attr);if (par->gamma.curves && par->fbtftops.set_gamma) -device_create_file (par->info->dev, &gamma_device_attrs[0 ]); +device_create_file (dev, &gamma_device_attrs[0 ]); }void fbtft_sysfs_exit (struct fbtft_par *par) { -device_remove_file (par->info->dev, &debug_device_attr); +struct device *dev =dev_of_fbinfo (par->info); + +if (!dev) +return ; + +device_remove_file (dev, &debug_device_attr);if (par->gamma.curves && par->fbtftops.set_gamma) -device_remove_file (par->info->dev, &gamma_device_attrs[0 ]); +device_remove_file (dev, &gamma_device_attrs[0 ]); }
Signature · 1 line
2.43.0
Re: [PATCH v2 2/4] staging: fbtft: Make FB_DEVICE dependency optional
Quoted 77 lines · Chintan Patel
fbtft provides sysfs interfaces for debugging and gamma configuration, but these are not required for the core driver.
Drop the hard dependency on
CONFIG_FB_DEVICEand make sysfs support optional by usingdev_of_fbinfo()at runtime. WhenFB_DEVICEis disabled, sysfs operations are skipped while the code remains buildable and type-checked.v2:
- ReplaceCONFIG_FB_DEVICEifdefs with runtime checks
- Usedev_of_fbinfo()to guard sysfs creation and removalSuggested-by Thomas Zimmermann <[email protected]>Suggested-by Helge Deller <[email protected]>Signed-off-by Chintan Patel <[email protected]>--- drivers/staging/fbtft/Kconfig | 5 ++++- drivers/staging/fbtft/fbtft-sysfs.c | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-)drivers/staging/fbtft/Kconfig +4
-1@@ -2,11 +2,14 @@ menuconfig FB_TFT tristate "Support for small TFT LCD display modules" depends on FB && SPI - depends on FB_DEVICE depends on BACKLIGHT_CLASS_DEVICE depends on GPIOLIB || COMPILE_TEST select FB_BACKLIGHT select FB_SYSMEM_HELPERS_DEFERRED + help + Support for small TFT LCD display modules over SPI bus. FB_DEVICE + is not required, but if enabled, provides sysfs interface for debugging + and gamma curve configuration. if FB_TFTdrivers/staging/fbtft/fbtft-sysfs.c +14
-5@@ -203,14 +203,24 @@ static struct device_attribute debug_device_attr =void fbtft_sysfs_init (struct fbtft_par *par) { -device_create_file (par->info->dev, &debug_device_attr); +struct device *dev =dev_of_fbinfo (par->info); + +if (!dev) +return ; + +device_create_file (dev, &debug_device_attr);if (par->gamma.curves && par->fbtftops.set_gamma) -device_create_file (par->info->dev, &gamma_device_attrs[0 ]); +device_create_file (dev, &gamma_device_attrs[0 ]); }void fbtft_sysfs_exit (struct fbtft_par *par) { -device_remove_file (par->info->dev, &debug_device_attr); +struct device *dev =dev_of_fbinfo (par->info); + +if (!dev) +return ; + +device_remove_file (dev, &debug_device_attr);if (par->gamma.curves && par->fbtftops.set_gamma) -device_remove_file (par->info->dev, &gamma_device_attrs[0 ]); +device_remove_file (dev, &gamma_device_attrs[0 ]); } --2.43.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/4] staging: fbtft: Make FB_DEVICE dependency optional
In reply to Chintan PatelQuoted 4 lines · Chintan Patel
fbtft provides sysfs interfaces for debugging and gamma configuration, but these are not required for the core driver.
Quoted 8 lines
Drop the hard dependency on
CONFIG_FB_DEVICEand make sysfs support optional by usingdev_of_fbinfo()at runtime. WhenFB_DEVICEis disabled, sysfs operations are skipped while the code remains buildable and type-checked.v2:
- ReplaceCONFIG_FB_DEVICEifdefs with runtime checks
- Usedev_of_fbinfo()to guard sysfs creation and removal
The place for the change log is either a cover letter, or...
Quoted 4 lines
Suggested-by Thomas Zimmermann <[email protected]>Suggested-by Helge Deller <[email protected]>Signed-off-by Chintan Patel <[email protected]>---
...a comment block here. It's not so important to be in the Git history since we have a lore.kernel.org archive.
Quoted 2 lines
drivers/staging/fbtft/Kconfig | 5 ++++- drivers/staging/fbtft/fbtft-sysfs.c | 18 ++++++++++++++----
...
drivers/staging/fbtft/fbtft-sysfs.c static struct device_attribute debug_device_attr = · line 209
Quoted 7 lines
void
fbtft_sysfs_init(struct fbtft_par *par)
{drivers/staging/fbtft/fbtft-sysfs.c +4
-1-device_create_file (par->info->dev, &debug_device_attr); +struct device *dev =dev_of_fbinfo (par->info); + +if (!dev) +return ;
The better way is to decouple the definition and the assignment in the cases when it's followed by a conditional (validation check). In this case any new code added in between doesn't affect readability and maintenance efforts.
struct device *dev;
dev = dev_of_fbinfo(par->info);
if (!dev)
return;drivers/staging/fbtft/fbtft-sysfs.c static struct device_attribute debug_device_attr = · line 214
Quoted 5 lines
drivers/staging/fbtft/fbtft-sysfs.c +2
-1+device_create_file (dev, &debug_device_attr);if (par->gamma.curves && par->fbtftops.set_gamma) -device_create_file (par->info->dev, &gamma_device_attrs[0 ]); +device_create_file (dev, &gamma_device_attrs[0 ]); }
Ditto for the rest.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/4] staging: fbtft: Make FB_DEVICE dependency optional
Hi Andy,
Quoted 16 lines · Andy Shevchenko
Quoted 4 lines · Chintan Patel
fbtft provides sysfs interfaces for debugging and gamma configuration, but these are not required for the core driver.
Quoted 8 lines
Drop the hard dependency on
CONFIG_FB_DEVICEand make sysfs support optional by usingdev_of_fbinfo()at runtime. WhenFB_DEVICEis disabled, sysfs operations are skipped while the code remains buildable and type-checked.v2:
- ReplaceCONFIG_FB_DEVICEifdefs with runtime checks
- Usedev_of_fbinfo()to guard sysfs creation and removalThe place for the change log is either a cover letter, or...
Quoted 7 lines
Quoted 4 lines
Suggested-by Thomas Zimmermann <[email protected]>Suggested-by Helge Deller <[email protected]>Signed-off-by Chintan Patel <[email protected]>---
...a comment block here. It's not so important to be in the Git history since we have a lore.kernel.org archive.
Thank you for suggestion! Will move to coverletter.
Quoted 25 lines
Quoted 2 lines
drivers/staging/fbtft/Kconfig | 5 ++++- drivers/staging/fbtft/fbtft-sysfs.c | 18 ++++++++++++++----...
drivers/staging/fbtft/fbtft-sysfs.c static struct device_attribute debug_device_attr = · line 209
Quoted 7 lines
void fbtft_sysfs_init(struct fbtft_par *par) {drivers/staging/fbtft/fbtft-sysfs.c +4
-1-device_create_file (par->info->dev, &debug_device_attr); +struct device *dev =dev_of_fbinfo (par->info); + +if (!dev) +return ;The better way is to decouple the definition and the assignment in the cases when it's followed by a conditional (validation check). In this case any new code added in between doesn't affect readability and maintenance efforts.
struct device *dev; dev = dev_of_fbinfo(par->info); if (!dev) return;
Quoted 7 lines
drivers/staging/fbtft/fbtft-sysfs.c static struct device_attribute debug_device_attr = · line 214
Quoted 5 lines
drivers/staging/fbtft/fbtft-sysfs.c +2
-1+device_create_file (dev, &debug_device_attr);if (par->gamma.curves && par->fbtftops.set_gamma) -device_create_file (par->info->dev, &gamma_device_attrs[0 ]); +device_create_file (dev, &gamma_device_attrs[0 ]); }Ditto for the rest.
Will do v3 and re-send. Thanks for reviews!
PATCH v2 3/4 fbdev: omapfb: Make FB_DEVICE dependency optional
In reply to Chintan Patelomapfb provides several sysfs interfaces for framebuffer configuration and debugging, but these are not required for the core driver.
Remove the hard dependency on CONFIG_FB_DEVICE and make sysfs support optional by using dev_of_fbinfo() to obtain the backing device at runtime. When FB_DEVICE is disabled, sysfs operations are skipped while the code still builds and is type-checked.
v2:
- Replace CONFIG_FB_DEVICE ifdefs and stubs with runtime checks
- Use dev_of_fbinfo() to skip sysfs when unavailable
--- drivers/video/fbdev/omap2/omapfb/Kconfig | 3 ++- drivers/video/fbdev/omap2/omapfb/omapfb-sysfs.c | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-)
drivers/video/fbdev/omap2/omapfb/Kconfig +2 -1
@@ -5,7 +5,6 @@ config OMAP2_VRFB menuconfig FB_OMAP2 tristate "OMAP2+ frame buffer support" depends on FB - depends on FB_DEVICE depends on DRM_OMAP = n depends on GPIOLIB select FB_OMAP2_DSS
@@ -13,6 +12,8 @@ menuconfig FB_OMAP2 select FB_IOMEM_HELPERS help Frame buffer driver for OMAP2+ based boards. + FB_DEVICE is not required, but if enabled, provides sysfs interface + for framebuffer configuration and debugging. if FB_OMAP2
drivers/video/fbdev/omap2/omapfb/omapfb-sysfs.c +12 -4
@@ -558,10 +558,14 @@ int omapfb_create_sysfs(struct omapfb2_device *fbdev)DBG ("create sysfs for fbs\n" );for (i =0 ; i < fbdev->num_fbs; i++) { +struct device *dev =dev_of_fbinfo (fbdev->fbs[i]);int t; + +if (!dev) +continue ; +for (t =0 ; t <ARRAY_SIZE (omapfb_attrs); t++) { - r =device_create_file (fbdev->fbs[i]->dev, - &omapfb_attrs[t]); + r =device_create_file (dev, &omapfb_attrs[t]);if (r) { dev_err(fbdev->dev, "failed to create sysfs "
@@ -580,9 +584,13 @@ void omapfb_remove_sysfs(struct omapfb2_device *fbdev)DBG ("remove sysfs for fbs\n" );for (i =0 ; i < fbdev->num_fbs; i++) { +struct device *dev =dev_of_fbinfo (fbdev->fbs[i]); + +if (!dev) +continue ; +for (t =0 ; t <ARRAY_SIZE (omapfb_attrs); t++) -device_remove_file (fbdev->fbs[i]->dev, - &omapfb_attrs[t]); +device_remove_file (dev, &omapfb_attrs[t]); } }
Signature · 1 line
2.43.0
PATCH v2 4/4 fbdev: sh_mobile_lcdc: Make FB_DEVICE dependency optional
In reply to Chintan PatelThe sh_mobile_lcdc driver exposes overlay configuration via sysfs, but the core driver does not require CONFIG_FB_DEVICE.
Make sysfs support optional by defining overlay_sysfs_groups as NULL when FB_DEVICE is disabled. The driver always sets .dev_groups, and the kernel naturally skips NULL attribute groups while the code remains buildable and type-checked.
v2:
- Replace CONFIG_FB_DEVICE ifdefs with NULL overlay_sysfs_groups
- Always populate .dev_groups
--- drivers/video/fbdev/sh_mobile_lcdcfb.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/video/fbdev/sh_mobile_lcdcfb.c +9 -0
@@ -1350,7 +1350,16 @@ static struct attribute *overlay_sysfs_attrs[] = { &dev_attr_overlay_rop3.attr, NULL, }; + +#ifdef CONFIG_FB_DEVICE ATTRIBUTE_GROUPS (overlay_sysfs); +#else +/* +* When CONFIG_FB_DEVICE is disabled, define overlay_sysfs_groups as NULL. +* The compiler will optimize out the sysfs code paths when dev_groups is NULL. +*/ +static const struct attribute_group *overlay_sysfs_groups[] = {NULL }; +#endif static const struct fb_fix_screeninfo sh_mobile_lcdc_overlay_fix = { .id = "SH Mobile LCDC",
Signature · 1 line
2.43.0
Re: [PATCH v2 4/4] fbdev: sh_mobile_lcdc: Make FB_DEVICE dependency optional
Quoted 4 lines · Chintan Patel
The
sh_mobile_lcdcdriver exposes overlay configuration via sysfs, but the core driver does not requireCONFIG_FB_DEVICE.
Quoted 8 lines
Make sysfs support optional by defining
overlay_sysfs_groupsas NULL whenFB_DEVICEis disabled. The driver always sets .dev_groups, and the kernel naturally skips NULL attribute groups while the code remains buildable and type-checked.v2:
- ReplaceCONFIG_FB_DEVICEifdefs with NULLoverlay_sysfs_groups
- Always populate .dev_groups
Same comment about the changelog in the commit messages.
...
drivers/video/fbdev/sh_mobile_lcdcfb.c static struct attribute *overlay_sysfs_attrs[] = { · line 1362
Quoted 9 lines
drivers/video/fbdev/sh_mobile_lcdcfb.c +8
-0+#ifdef CONFIG_FB_DEVICE ATTRIBUTE_GROUPS (overlay_sysfs); +#else +/* +* When CONFIG_FB_DEVICE is disabled, define overlay_sysfs_groups as NULL. +* The compiler will optimize out the sysfs code paths when dev_groups is NULL. +*/ +static const struct attribute_group *overlay_sysfs_groups[] = {NULL }; +#endif
Hmm... I'm wondering if PTR_IF() can anyhow help here.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Chintan Patel
This series makes
CONFIG_FB_DEVICEoptional for fbdev drivers that use it only for sysfs interfaces, addressing Thomas Zimmermann’s TODO to remove hardFB_DEVICEdependencies.The series introduces a small helper,
dev_of_fbinfo(), which returns NULL whenCONFIG_FB_DEVICE=n. This allows sysfs code paths to be skipped via runtime checks, avoids #ifdefCONFIG_FB_DEVICEclutter, and keeps full compile-time syntax checking.
Please, address my comments and I give a tag for v3. I pretty much like the series, thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko