[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250312154507.10881-1-oushixiong1025@163.com>
Date: Wed, 12 Mar 2025 23:45:06 +0800
From: Shixiong Ou <oushixiong1025@....com>
To: Simona Vetter <simona@...ll.ch>
Cc: Helge Deller <deller@....de>,
Jocelyn Falempe <jfalempe@...hat.com>,
Samuel Thibault <samuel.thibault@...-lyon.org>,
Thomas Zimmermann <tzimmermann@...e.de>,
linux-fbdev@...r.kernel.org,
dri-devel@...ts.freedesktop.org,
linux-kernel@...r.kernel.org,
Shixiong Ou <oushixiong@...inos.cn>
Subject: [PATCH v2 1/2] fbcon: Register sysfs groups through device_add_group
From: Shixiong Ou <oushixiong@...inos.cn>
Use device_add_group() to simplify creation and removal.
Signed-off-by: Shixiong Ou <oushixiong@...inos.cn>
---
v1->v2:
fix build error.
drivers/video/fbdev/core/fbcon.c | 49 ++++++++++++++------------------
1 file changed, 22 insertions(+), 27 deletions(-)
diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index e8b4e8c119b5..9ee5f8492249 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -3157,7 +3157,7 @@ static const struct consw fb_con = {
.con_debug_leave = fbcon_debug_leave,
};
-static ssize_t store_rotate(struct device *device,
+static ssize_t rotate_store(struct device *device,
struct device_attribute *attr, const char *buf,
size_t count)
{
@@ -3179,7 +3179,7 @@ static ssize_t store_rotate(struct device *device,
return count;
}
-static ssize_t store_rotate_all(struct device *device,
+static ssize_t rotate_all_store(struct device *device,
struct device_attribute *attr,const char *buf,
size_t count)
{
@@ -3201,7 +3201,7 @@ static ssize_t store_rotate_all(struct device *device,
return count;
}
-static ssize_t show_rotate(struct device *device,
+static ssize_t rotate_show(struct device *device,
struct device_attribute *attr,char *buf)
{
struct fb_info *info;
@@ -3220,7 +3220,7 @@ static ssize_t show_rotate(struct device *device,
return sysfs_emit(buf, "%d\n", rotate);
}
-static ssize_t show_cursor_blink(struct device *device,
+static ssize_t cursor_blink_show(struct device *device,
struct device_attribute *attr, char *buf)
{
struct fb_info *info;
@@ -3245,7 +3245,7 @@ static ssize_t show_cursor_blink(struct device *device,
return sysfs_emit(buf, "%d\n", blink);
}
-static ssize_t store_cursor_blink(struct device *device,
+static ssize_t cursor_blink_store(struct device *device,
struct device_attribute *attr,
const char *buf, size_t count)
{
@@ -3279,32 +3279,30 @@ static ssize_t store_cursor_blink(struct device *device,
return count;
}
-static struct device_attribute device_attrs[] = {
- __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
- __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
- __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
- store_cursor_blink),
+static DEVICE_ATTR_RW(rotate);
+static DEVICE_ATTR_WO(rotate_all);
+static DEVICE_ATTR_RW(cursor_blink);
+
+static struct attribute *fbcon_device_attrs[] = {
+ &dev_attr_rotate.attr,
+ &dev_attr_rotate_all.attr,
+ &dev_attr_cursor_blink.attr,
+ NULL,
+};
+
+static const struct attribute_group fbcon_device_attr_group = {
+ .attrs = fbcon_device_attrs,
};
static int fbcon_init_device(void)
{
- int i, error = 0;
+ int ret;
fbcon_has_sysfs = 1;
- for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
- error = device_create_file(fbcon_device, &device_attrs[i]);
-
- if (error)
- break;
- }
-
- if (error) {
- while (--i >= 0)
- device_remove_file(fbcon_device, &device_attrs[i]);
-
+ ret = device_add_group(fbcon_device, &fbcon_device_attr_group);
+ if (ret)
fbcon_has_sysfs = 0;
- }
return 0;
}
@@ -3387,11 +3385,8 @@ void __init fb_console_init(void)
static void __exit fbcon_deinit_device(void)
{
- int i;
-
if (fbcon_has_sysfs) {
- for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
- device_remove_file(fbcon_device, &device_attrs[i]);
+ device_remove_group(fbcon_device, &fbcon_device_attr_group);
fbcon_has_sysfs = 0;
}
--
2.43.0
Powered by blists - more mailing lists