Skip to contentSkip to conversation

staging: fbtft: convert sysfs attributes to use ATTRIBUTE_GROUPS

PATCH In review Harshit Shaw 3 participants 3 messages May 13

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

PATCH v4 1/1 staging: fbtft: convert sysfs attributes to use ATTRIBUTE_GROUPS

Replace direct device_create_file() calls with the correct ATTRIBUTE_GROUPS() macro. Add fbtft_groups as dev_groups in the driver structure so the driver core automatically adds and removes the sysfs attributes when a device is bound or unbound.

---
v4: Fix build error - add extern declaration of fbtft_groups in
fbtft.h so all drivers using FBTFT_REGISTER_DRIVER macro can see the symbol
v3: Remove stray blank line in fbtft_attrs[] array
v2: - Use DEVICE_ATTR_RW() macro instead of DEVICE_ATTR()
- Move DEVICE_ATTR_RW() definitions closer to their callbacks
- Remove trailing comma after NULL in attribute array
- Use ATTRIBUTE_GROUPS() macro and add dev_groups to driver structure as suggested by Greg KH and Andy Shevchenko
- Compile tested with: make M=drivers/staging/fbtft modules

 drivers/staging/fbtft/fbtft-core.c  |  3 --
 drivers/staging/fbtft/fbtft-sysfs.c | 81 +++++++++++------------------
 drivers/staging/fbtft/fbtft.h       |  6 +++
 drivers/staging/fbtft/internal.h    |  2 -
 4 files changed, 36 insertions(+), 56 deletions(-)
drivers/staging/fbtft/fbtft-core.c +0 -3
index 3da42c8ca6e3..e6d33127cecc 100644
@@ -782,8 +782,6 @@ int fbtft_register_framebuffer(struct fb_info *fb_info)
 	if (ret < 0)
 		goto reg_fail;
 
-	fbtft_sysfs_init(par);
-
 	if (par->txbuf.buf && par->txbuf.len >= 1024)
 		sprintf(text1, ", %zu KiB buffer memory", par->txbuf.len >> 10);
 	if (spi)
@@ -826,7 +824,6 @@ int fbtft_unregister_framebuffer(struct fb_info *fb_info)
 
 	if (par->fbtftops.unregister_backlight)
 		par->fbtftops.unregister_backlight(par);
-	fbtft_sysfs_exit(par);
 	unregister_framebuffer(fb_info);
 
 	return 0;
drivers/staging/fbtft/fbtft-sysfs.c +30 -51

104 lines not on this page · raw message

drivers/staging/fbtft/fbtft.h +6 -0
index 317be17b95c1..1a3b9691f24a 100644
@@ -8,6 +8,7 @@
 #include <linux/spinlock.h>
 #include <linux/spi/spi.h>
 #include <linux/platform_device.h>
+#include <linux/sysfs.h>
 
 #define FBTFT_ONBOARD_BACKLIGHT 2
 
@@ -274,6 +275,9 @@ void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...);
 void fbtft_write_reg16_bus8(struct fbtft_par *par, int len, ...);
 void fbtft_write_reg16_bus16(struct fbtft_par *par, int len, ...);
 
+/* fbtft-sysfs.c */
+extern const struct attribute_group *fbtft_groups[];
+
 #define FBTFT_DT_TABLE(_compatible)						\
 static const struct of_device_id dt_ids[] = {					\
 	{ .compatible = _compatible },						\
@@ -299,6 +303,7 @@ static struct spi_driver fbtft_driver_spi_driver = {				\
 	.driver = {								\
 		.name = _name,							\
 		.of_match_table = dt_ids,					\
+		.dev_groups = fbtft_groups,					\
 	},									\
 	.id_table = _spi_ids,							\
 	.probe = fbtft_driver_probe_spi,					\
@@ -328,6 +333,7 @@ static struct platform_driver fbtft_driver_platform_driver = {             \
 		.name   = _name,                                           \
 		.owner  = THIS_MODULE,                                     \
 		.of_match_table = dt_ids,                                  \
+		.dev_groups = fbtft_groups,                                \
 	},                                                                 \
 	.probe  = fbtft_driver_probe_pdev,                                 \
 	.remove = fbtft_driver_remove_pdev,				   \
drivers/staging/fbtft/internal.h +0 -2
index ae2ff4a4a472..7869cf8dbf2a 100644
@@ -4,8 +4,6 @@
 #ifndef __LINUX_FBTFT_INTERNAL_H
 #define __LINUX_FBTFT_INTERNAL_H
 
-void fbtft_sysfs_init(struct fbtft_par *par);
-void fbtft_sysfs_exit(struct fbtft_par *par);
 void fbtft_expand_debug_value(unsigned long *debug);
 int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves,
 			  const char *str, int size);
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 7 lines · Harshit Shaw

Replace direct device_create_file() calls with the correct ATTRIBUTE_GROUPS() macro. Add fbtft_groups as dev_groups in the driver structure so the driver core automatically adds and removes the sysfs attributes when a device is bound or unbound.

Quoted 11 lines

---
v4: Fix build error - add extern declaration of fbtft_groups in
fbtft.h so all drivers using FBTFT_REGISTER_DRIVER macro can see the symbol
v3: Remove stray blank line in fbtft_attrs[] array
v2: - Use DEVICE_ATTR_RW() macro instead of DEVICE_ATTR()
- Move DEVICE_ATTR_RW() definitions closer to their callbacks
- Remove trailing comma after NULL in attribute array
- Use ATTRIBUTE_GROUPS() macro and add dev_groups to driver structure as suggested by Greg KH and Andy Shevchenko
- Compile tested with: make M=drivers/staging/fbtft modules

I see too many v4 versions on the list for there really to be just 1 v4 :(

Please wait a bit, take some time, and resubmit a new version after a few days making sure it's all correct. There is no rush or deadline here.

thanks,

greg k-h

#2 lore raw

A correction coming so quickly... I've only just started my day, and this is 4th v4.

--
Samet

Quoted 33 lines

2026. 5. 13. 오후 1:39, Greg KH <[email protected]> 작성:

Quoted 7 lines · Harshit Shaw

Replace direct device_create_file() calls with the correct ATTRIBUTE_GROUPS() macro. Add fbtft_groups as dev_groups in the driver structure so the driver core automatically adds and removes the sysfs attributes when a device is bound or unbound.

Quoted 11 lines

---
v4: Fix build error - add extern declaration of fbtft_groups in
fbtft.h so all drivers using FBTFT_REGISTER_DRIVER macro can see the symbol
v3: Remove stray blank line in fbtft_attrs[] array
v2: - Use DEVICE_ATTR_RW() macro instead of DEVICE_ATTR()
- Move DEVICE_ATTR_RW() definitions closer to their callbacks
- Remove trailing comma after NULL in attribute array
- Use ATTRIBUTE_GROUPS() macro and add dev_groups to driver structure as suggested by Greg KH and Andy Shevchenko
- Compile tested with: make M=drivers/staging/fbtft modules

I see too many v4 versions on the list for there really to be just 1 v4 :(

Please wait a bit, take some time, and resubmit a new version after a few days making sure it's all correct. There is no rush or deadline here.

thanks,

greg k-h