Skip to content

Commit 43a707a

Browse files
ivanorlov2206lag-linaro
authored andcommitted
leds: Make leds_class a static const structure
Now that the driver core allows for struct class to be in read-only memory, move the leds_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Suggested-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Ivan Orlov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 3d590af commit 43a707a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

drivers/leds/led-class.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <linux/of.h>
2323
#include "leds.h"
2424

25-
static struct class *leds_class;
2625
static DEFINE_MUTEX(leds_lookup_lock);
2726
static LIST_HEAD(leds_lookup_list);
2827

@@ -248,6 +247,12 @@ static struct led_classdev *led_module_get(struct device *led_dev)
248247
return led_cdev;
249248
}
250249

250+
static const struct class leds_class = {
251+
.name = "leds",
252+
.dev_groups = led_groups,
253+
.pm = &leds_class_dev_pm_ops,
254+
};
255+
251256
/**
252257
* of_led_get() - request a LED device via the LED framework
253258
* @np: device node to get the LED device from
@@ -265,7 +270,7 @@ struct led_classdev *of_led_get(struct device_node *np, int index)
265270
if (!led_node)
266271
return ERR_PTR(-ENOENT);
267272

268-
led_dev = class_find_device_by_of_node(leds_class, led_node);
273+
led_dev = class_find_device_by_of_node(&leds_class, led_node);
269274
of_node_put(led_node);
270275
put_device(led_dev);
271276

@@ -360,7 +365,7 @@ struct led_classdev *led_get(struct device *dev, char *con_id)
360365
if (!provider)
361366
return ERR_PTR(-ENOENT);
362367

363-
led_dev = class_find_device_by_name(leds_class, provider);
368+
led_dev = class_find_device_by_name(&leds_class, provider);
364369
kfree_const(provider);
365370

366371
return led_module_get(led_dev);
@@ -451,7 +456,7 @@ static int led_classdev_next_name(const char *init_name, char *name,
451456
strscpy(name, init_name, len);
452457

453458
while ((ret < len) &&
454-
(dev = class_find_device_by_name(leds_class, name))) {
459+
(dev = class_find_device_by_name(&leds_class, name))) {
455460
put_device(dev);
456461
ret = snprintf(name, len, "%s_%u", init_name, ++i);
457462
}
@@ -518,8 +523,8 @@ int led_classdev_register_ext(struct device *parent,
518523

519524
mutex_init(&led_cdev->led_access);
520525
mutex_lock(&led_cdev->led_access);
521-
led_cdev->dev = device_create_with_groups(leds_class, parent, 0,
522-
led_cdev, led_cdev->groups, "%s", final_name);
526+
led_cdev->dev = device_create_with_groups(&leds_class, parent, 0,
527+
led_cdev, led_cdev->groups, "%s", final_name);
523528
if (IS_ERR(led_cdev->dev)) {
524529
mutex_unlock(&led_cdev->led_access);
525530
return PTR_ERR(led_cdev->dev);
@@ -676,17 +681,12 @@ EXPORT_SYMBOL_GPL(devm_led_classdev_unregister);
676681

677682
static int __init leds_init(void)
678683
{
679-
leds_class = class_create("leds");
680-
if (IS_ERR(leds_class))
681-
return PTR_ERR(leds_class);
682-
leds_class->pm = &leds_class_dev_pm_ops;
683-
leds_class->dev_groups = led_groups;
684-
return 0;
684+
return class_register(&leds_class);
685685
}
686686

687687
static void __exit leds_exit(void)
688688
{
689-
class_destroy(leds_class);
689+
class_unregister(&leds_class);
690690
}
691691

692692
subsys_initcall(leds_init);

0 commit comments

Comments
 (0)