Skip to content

Commit 717bbf0

Browse files
rbmarlierelag-linaro
authored andcommitted
backlight: lcd: Make lcd_class constant
Since commit 43a7206 ("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. Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org> Link: https://lore.kernel.org/r/2024032809-enchanted-conducive-3677@gregkh Signed-off-by: Lee Jones <lee@kernel.org>
1 parent cda12ba commit 717bbf0

File tree

1 file changed

+13
-10
lines changed
  • drivers/video/backlight

1 file changed

+13
-10
lines changed

drivers/video/backlight/lcd.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ static ssize_t max_contrast_show(struct device *dev,
159159
}
160160
static DEVICE_ATTR_RO(max_contrast);
161161

162-
static struct class *lcd_class;
163-
164162
static void lcd_device_release(struct device *dev)
165163
{
166164
struct lcd_device *ld = to_lcd_device(dev);
@@ -175,6 +173,11 @@ static struct attribute *lcd_device_attrs[] = {
175173
};
176174
ATTRIBUTE_GROUPS(lcd_device);
177175

176+
static const struct class lcd_class = {
177+
.name = "lcd",
178+
.dev_groups = lcd_device_groups,
179+
};
180+
178181
/**
179182
* lcd_device_register - register a new object of lcd_device class.
180183
* @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,
202205
mutex_init(&new_ld->ops_lock);
203206
mutex_init(&new_ld->update_lock);
204207

205-
new_ld->dev.class = lcd_class;
208+
new_ld->dev.class = &lcd_class;
206209
new_ld->dev.parent = parent;
207210
new_ld->dev.release = lcd_device_release;
208211
dev_set_name(&new_ld->dev, "%s", name);
@@ -318,19 +321,19 @@ EXPORT_SYMBOL(devm_lcd_device_unregister);
318321

319322
static void __exit lcd_class_exit(void)
320323
{
321-
class_destroy(lcd_class);
324+
class_unregister(&lcd_class);
322325
}
323326

324327
static int __init lcd_class_init(void)
325328
{
326-
lcd_class = class_create("lcd");
327-
if (IS_ERR(lcd_class)) {
328-
pr_warn("Unable to create backlight class; errno = %ld\n",
329-
PTR_ERR(lcd_class));
330-
return PTR_ERR(lcd_class);
329+
int ret;
330+
331+
ret = class_register(&lcd_class);
332+
if (ret) {
333+
pr_warn("Unable to create backlight class; errno = %d\n", ret);
334+
return ret;
331335
}
332336

333-
lcd_class->dev_groups = lcd_device_groups;
334337
return 0;
335338
}
336339

0 commit comments

Comments
 (0)