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_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
Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
Suggested-by: Helge Deller <deller@gmx.de>
Signed-off-by: Chintan Patel <chintanlike@gmail.com>
---
drivers/staging/fbtft/Kconfig | 5 ++++-
drivers/staging/fbtft/fbtft-sysfs.c | 18 ++++++++++++++----
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/fbtft/Kconfig b/drivers/staging/fbtft/Kconfig
index c2655768209a..578412a2f379 100644
--- a/drivers/staging/fbtft/Kconfig
+++ b/drivers/staging/fbtft/Kconfig
@@ -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
diff --git a/drivers/staging/fbtft/fbtft-sysfs.c b/drivers/staging/fbtft/fbtft-sysfs.c
index e45c90a03a90..848702fc871a 100644
--- a/drivers/staging/fbtft/fbtft-sysfs.c
+++ b/drivers/staging/fbtft/fbtft-sysfs.c
@@ -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
On Fri, Dec 19, 2025 at 7:43 AM Chintan Patel <chintanlike@gmail.com> wrote:
>
> 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_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
The place for the change log is either a cover letter, or...
> Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
> Suggested-by: Helge Deller <deller@gmx.de>
> Signed-off-by: Chintan Patel <chintanlike@gmail.com>
> ---
...a comment block here. It's not so important to be in the Git
history since we have a lore.kernel.org archive.
> drivers/staging/fbtft/Kconfig | 5 ++++-
> drivers/staging/fbtft/fbtft-sysfs.c | 18 ++++++++++++++----
...
> 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;
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;
> + 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.
--
With Best Regards,
Andy Shevchenko
Hi Andy,
On 12/27/25 06:19, Andy Shevchenko wrote:
> On Fri, Dec 19, 2025 at 7:43 AM Chintan Patel <chintanlike@gmail.com> wrote:
>>
>> 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_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
>
> The place for the change log is either a cover letter, or...
>
>> Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Suggested-by: Helge Deller <deller@gmx.de>
>> Signed-off-by: Chintan Patel <chintanlike@gmail.com>
>> ---
>
> ...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.
>> drivers/staging/fbtft/Kconfig | 5 ++++-
>> drivers/staging/fbtft/fbtft-sysfs.c | 18 ++++++++++++++----
>
> ...
>
>> 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;
>
>
> 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;
>
>> + 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!
On Fri, Dec 19, 2025 at 7:43 AM Chintan Patel <chintanlike@gmail.com> wrote:
>
> 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_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
>
> Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
> Suggested-by: Helge Deller <deller@gmx.de>
> Signed-off-by: Chintan Patel <chintanlike@gmail.com>
> ---
> drivers/staging/fbtft/Kconfig | 5 ++++-
> drivers/staging/fbtft/fbtft-sysfs.c | 18 ++++++++++++++----
> 2 files changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/staging/fbtft/Kconfig b/drivers/staging/fbtft/Kconfig
> index c2655768209a..578412a2f379 100644
> --- a/drivers/staging/fbtft/Kconfig
> +++ b/drivers/staging/fbtft/Kconfig
> @@ -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
>
> diff --git a/drivers/staging/fbtft/fbtft-sysfs.c b/drivers/staging/fbtft/fbtft-sysfs.c
> index e45c90a03a90..848702fc871a 100644
> --- a/drivers/staging/fbtft/fbtft-sysfs.c
> +++ b/drivers/staging/fbtft/fbtft-sysfs.c
> @@ -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
>
--
With Best Regards,
Andy Shevchenko
© 2016 - 2026 Red Hat, Inc.