video: backlight: make backlight_class constant
Subsystems (2)
PATCH v2 1/2 video: backlight: make backlight_class constant
From: "Ricardo B. Marliere" <[email protected]>
Since commit 43a7206b0963 ("driver core: class: make class_register() take a const *"), the driver core allows for struct class to be in read-only memory, so move the backlight_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time.
---
v2: rebased on 6.9-rc1
drivers/video/backlight/backlight.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
drivers/video/backlight/backlight.c +16 -13
@@ -317,8 +317,6 @@ static ssize_t scale_show(struct device *dev, }static DEVICE_ATTR_RO (scale); -static struct class *backlight_class; -#ifdef CONFIG_PM_SLEEP static int backlight_suspend (struct device *dev) {
@@ -369,6 +367,12 @@ static struct attribute *bl_device_attrs[] = { };ATTRIBUTE_GROUPS (bl_device); +static const struct class backlight_class = { + .name ="backlight" , + .dev_groups = bl_device_groups, + .pm = &backlight_class_dev_pm_ops, +}; +/** * backlight_force_update - tell the backlight subsystem that hardware state * has changed
@@ -418,7 +422,7 @@ struct backlight_device *backlight_device_register(const char *name,mutex_init (&new_bd->update_lock);mutex_init (&new_bd->ops_lock); - new_bd->dev.class = backlight_class; + new_bd->dev.class = &backlight_class; new_bd->dev.parent = parent; new_bd->dev.release = bl_device_release;dev_set_name (&new_bd->dev,"%s" , name);
@@ -510,7 +514,7 @@ struct backlight_device *backlight_device_get_by_name(const char *name) {struct device *dev; - dev =class_find_device_by_name (backlight_class, name); + dev =class_find_device_by_name (&backlight_class, name);return dev ?to_backlight_device (dev) :NULL ; }
@@ -678,7 +682,7 @@ struct backlight_device *of_find_backlight_by_node(struct device_node *node) {struct device *dev; - dev =class_find_device (backlight_class,NULL , node, of_parent_match); + dev =class_find_device (&backlight_class,NULL , node, of_parent_match);return dev ?to_backlight_device (dev) :NULL ; }
@@ -746,20 +750,19 @@ EXPORT_SYMBOL(devm_of_find_backlight); static void __exit backlight_class_exit(void) { -class_destroy (backlight_class); +class_unregister (&backlight_class); }static int __init backlight_class_init (void ) { - backlight_class =class_create ("backlight" ); -if (IS_ERR (backlight_class)) { -pr_warn ("Unable to create backlight class; errno = %ld\n" , -PTR_ERR (backlight_class)); -return PTR_ERR (backlight_class); +int ret; + + ret =class_register (&backlight_class); +if (ret) { +pr_warn ("Unable to create backlight class; errno = %d\n" , ret); +return ret; } - backlight_class->dev_groups = bl_device_groups; - backlight_class->pm = &backlight_class_dev_pm_ops;INIT_LIST_HEAD (&backlight_dev_list);mutex_init (&backlight_dev_list_mutex);BLOCKING_INIT_NOTIFIER_HEAD (&backlight_notifier);
Signature · 1 line
2.44.0
PATCH v2 2/2 video: backlight: lcd: make lcd_class constant
From: "Ricardo B. Marliere" <[email protected]>
Since commit 43a7206b0963 ("driver core: class: make class_register() take a const *"), the driver core allows for struct class to be in read-only memory, so move the lcd_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time.
---
v2: rebased on 6.9-rc1
drivers/video/backlight/lcd.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
drivers/video/backlight/lcd.c +13 -10
@@ -159,8 +159,6 @@ static ssize_t max_contrast_show(struct device *dev, }static DEVICE_ATTR_RO (max_contrast); -static struct class *lcd_class; -static void lcd_device_release (struct device *dev) {struct lcd_device *ld =to_lcd_device (dev);
@@ -175,6 +173,11 @@ static struct attribute *lcd_device_attrs[] = { };ATTRIBUTE_GROUPS (lcd_device); +static const struct class lcd_class = { + .name ="lcd" , + .dev_groups = lcd_device_groups, +}; +/** * lcd_device_register - register a new object of lcd_device class. * @name: the name of the new object(must be the same as the name of the
@@ -202,7 +205,7 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent,mutex_init (&new_ld->ops_lock);mutex_init (&new_ld->update_lock); - new_ld->dev.class = lcd_class; + new_ld->dev.class = &lcd_class; new_ld->dev.parent = parent; new_ld->dev.release = lcd_device_release;dev_set_name (&new_ld->dev,"%s" , name);
@@ -318,19 +321,19 @@ EXPORT_SYMBOL(devm_lcd_device_unregister); static void __exit lcd_class_exit(void) { -class_destroy (lcd_class); +class_unregister (&lcd_class); }static int __init lcd_class_init (void ) { - lcd_class =class_create ("lcd" ); -if (IS_ERR (lcd_class)) { -pr_warn ("Unable to create backlight class; errno = %ld\n" , -PTR_ERR (lcd_class)); -return PTR_ERR (lcd_class); +int ret; + + ret =class_register (&lcd_class); +if (ret) { +pr_warn ("Unable to create backlight class; errno = %d\n" , ret); +return ret; } - lcd_class->dev_groups = lcd_device_groups;return 0 ; }
Signature · 1 line
2.44.0
Quoted 8 lines · Greg Kroah-Hartman
Since commit
43a7206b0963("driver core: class: makeclass_register()take a const *"), the driver core allows for struct class to be in read-only memory, so move thebacklight_classstructure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time.[...]
Applied, thanks!
[1/2] video: backlight: make backlight_class constant
commit: 6683414cff25dc5b6e7dfe9dadf42b718384c892
[2/2] video: backlight: lcd: make lcd_class constant
commit: d51564f749fe4e4efd570b0591f2d23696c90cc7--
Lee Jones [李琼斯]
Lee Jones
maintainerQuoted 8 lines · Lee Jones
Quoted 7 lines · Greg Kroah-Hartman
Since commit
43a7206b0963("driver core: class: makeclass_register()take a const *"), the driver core allows for struct class to be in read-only memory, so move thebacklight_classstructure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time.
Quoted 8 lines
Quoted 1 line
[...]
Applied, thanks!
[1/2] video: backlight: make
backlight_classconstantcommit: 6683414cff25dc5b6e7dfe9dadf42b718384c892 [2/2] video: backlight: lcd: make lcd_class constant commit: d51564f749fe4e4efd570b0591f2d23696c90cc7
I also added Daniel's r/b.
Signature · 1 line
Lee Jones [李琼斯]