fbdev: Register sysfs groups through device_add_group

Use device_add_group() to simplify creation.

Signed-off-by: Shixiong Ou <oushixiong@kylinos.cn>
Signed-off-by: Helge Deller <deller@gmx.de>
This commit is contained in:
Shixiong Ou 2025-02-20 17:59:35 +08:00 committed by Helge Deller
parent a979182a24
commit 5fc830d6ac

View File

@ -416,55 +416,64 @@ static ssize_t show_bl_curve(struct device *device,
/* When cmap is added back in it should be a binary attribute /* When cmap is added back in it should be a binary attribute
* not a text one. Consideration should also be given to converting * not a text one. Consideration should also be given to converting
* fbdev to use configfs instead of sysfs */ * fbdev to use configfs instead of sysfs */
static struct device_attribute device_attrs[] = { static DEVICE_ATTR(bits_per_pixel, 0644, show_bpp, store_bpp);
__ATTR(bits_per_pixel, S_IRUGO|S_IWUSR, show_bpp, store_bpp), static DEVICE_ATTR(blank, 0644, show_blank, store_blank);
__ATTR(blank, S_IRUGO|S_IWUSR, show_blank, store_blank), static DEVICE_ATTR(console, 0644, show_console, store_console);
__ATTR(console, S_IRUGO|S_IWUSR, show_console, store_console), static DEVICE_ATTR(cursor, 0644, show_cursor, store_cursor);
__ATTR(cursor, S_IRUGO|S_IWUSR, show_cursor, store_cursor), static DEVICE_ATTR(mode, 0644, show_mode, store_mode);
__ATTR(mode, S_IRUGO|S_IWUSR, show_mode, store_mode), static DEVICE_ATTR(modes, 0644, show_modes, store_modes);
__ATTR(modes, S_IRUGO|S_IWUSR, show_modes, store_modes), static DEVICE_ATTR(pan, 0644, show_pan, store_pan);
__ATTR(pan, S_IRUGO|S_IWUSR, show_pan, store_pan), static DEVICE_ATTR(virtual_size, 0644, show_virtual, store_virtual);
__ATTR(virtual_size, S_IRUGO|S_IWUSR, show_virtual, store_virtual), static DEVICE_ATTR(name, 0444, show_name, NULL);
__ATTR(name, S_IRUGO, show_name, NULL), static DEVICE_ATTR(stride, 0444, show_stride, NULL);
__ATTR(stride, S_IRUGO, show_stride, NULL), static DEVICE_ATTR(rotate, 0644, show_rotate, store_rotate);
__ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate), static DEVICE_ATTR(state, 0644, show_fbstate, store_fbstate);
__ATTR(state, S_IRUGO|S_IWUSR, show_fbstate, store_fbstate),
#if IS_ENABLED(CONFIG_FB_BACKLIGHT) #if IS_ENABLED(CONFIG_FB_BACKLIGHT)
__ATTR(bl_curve, S_IRUGO|S_IWUSR, show_bl_curve, store_bl_curve), static DEVICE_ATTR(bl_curve, 0644, show_bl_curve, store_bl_curve);
#endif #endif
static struct attribute *fb_device_attrs[] = {
&dev_attr_bits_per_pixel.attr,
&dev_attr_blank.attr,
&dev_attr_console.attr,
&dev_attr_cursor.attr,
&dev_attr_mode.attr,
&dev_attr_modes.attr,
&dev_attr_pan.attr,
&dev_attr_virtual_size.attr,
&dev_attr_name.attr,
&dev_attr_stride.attr,
&dev_attr_rotate.attr,
&dev_attr_state.attr,
#if IS_ENABLED(CONFIG_FB_BACKLIGHT)
&dev_attr_bl_curve.attr,
#endif
NULL,
};
static const struct attribute_group fb_device_attr_group = {
.attrs = fb_device_attrs,
}; };
static int fb_init_device(struct fb_info *fb_info) static int fb_init_device(struct fb_info *fb_info)
{ {
int i, error = 0; int ret;
dev_set_drvdata(fb_info->dev, fb_info); dev_set_drvdata(fb_info->dev, fb_info);
fb_info->class_flag |= FB_SYSFS_FLAG_ATTR; fb_info->class_flag |= FB_SYSFS_FLAG_ATTR;
for (i = 0; i < ARRAY_SIZE(device_attrs); i++) { ret = device_add_group(fb_info->dev, &fb_device_attr_group);
error = device_create_file(fb_info->dev, &device_attrs[i]); if (ret)
if (error)
break;
}
if (error) {
while (--i >= 0)
device_remove_file(fb_info->dev, &device_attrs[i]);
fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR; fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
}
return 0; return 0;
} }
static void fb_cleanup_device(struct fb_info *fb_info) static void fb_cleanup_device(struct fb_info *fb_info)
{ {
unsigned int i;
if (fb_info->class_flag & FB_SYSFS_FLAG_ATTR) { if (fb_info->class_flag & FB_SYSFS_FLAG_ATTR) {
for (i = 0; i < ARRAY_SIZE(device_attrs); i++) device_remove_group(fb_info->dev, &fb_device_attr_group);
device_remove_file(fb_info->dev, &device_attrs[i]);
fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR; fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
} }