Skip to content

Commit 193d0c4

Browse files
rbmarlieremathieupoirier
authored andcommitted
rpmsg: core: Make rpmsg_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 rpmsg_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 <[email protected]> Suggested-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Ricardo B. Marliere <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mathieu Poirier <[email protected]>
1 parent 4cece76 commit 193d0c4

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

drivers/rpmsg/rpmsg_char.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ static struct rpmsg_eptdev *rpmsg_chrdev_eptdev_alloc(struct rpmsg_device *rpdev
423423
init_waitqueue_head(&eptdev->readq);
424424

425425
device_initialize(dev);
426-
dev->class = rpmsg_class;
426+
dev->class = &rpmsg_class;
427427
dev->parent = parent;
428428
dev->groups = rpmsg_eptdev_groups;
429429
dev_set_drvdata(dev, eptdev);

drivers/rpmsg/rpmsg_core.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
#include "rpmsg_internal.h"
2222

23-
struct class *rpmsg_class;
23+
const struct class rpmsg_class = {
24+
.name = "rpmsg",
25+
};
2426
EXPORT_SYMBOL(rpmsg_class);
2527

2628
/**
@@ -715,16 +717,16 @@ static int __init rpmsg_init(void)
715717
{
716718
int ret;
717719

718-
rpmsg_class = class_create("rpmsg");
719-
if (IS_ERR(rpmsg_class)) {
720-
pr_err("failed to create rpmsg class\n");
721-
return PTR_ERR(rpmsg_class);
720+
ret = class_register(&rpmsg_class);
721+
if (ret) {
722+
pr_err("failed to register rpmsg class\n");
723+
return ret;
722724
}
723725

724726
ret = bus_register(&rpmsg_bus);
725727
if (ret) {
726728
pr_err("failed to register rpmsg bus: %d\n", ret);
727-
class_destroy(rpmsg_class);
729+
class_destroy(&rpmsg_class);
728730
}
729731
return ret;
730732
}
@@ -733,7 +735,7 @@ postcore_initcall(rpmsg_init);
733735
static void __exit rpmsg_fini(void)
734736
{
735737
bus_unregister(&rpmsg_bus);
736-
class_destroy(rpmsg_class);
738+
class_destroy(&rpmsg_class);
737739
}
738740
module_exit(rpmsg_fini);
739741

drivers/rpmsg/rpmsg_ctrl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static int rpmsg_ctrldev_probe(struct rpmsg_device *rpdev)
150150
dev = &ctrldev->dev;
151151
device_initialize(dev);
152152
dev->parent = &rpdev->dev;
153-
dev->class = rpmsg_class;
153+
dev->class = &rpmsg_class;
154154

155155
mutex_init(&ctrldev->ctrl_lock);
156156
cdev_init(&ctrldev->cdev, &rpmsg_ctrldev_fops);

drivers/rpmsg/rpmsg_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define to_rpmsg_device(d) container_of(d, struct rpmsg_device, dev)
1919
#define to_rpmsg_driver(d) container_of(d, struct rpmsg_driver, drv)
2020

21-
extern struct class *rpmsg_class;
21+
extern const struct class rpmsg_class;
2222

2323
/**
2424
* struct rpmsg_device_ops - indirection table for the rpmsg_device operations

0 commit comments

Comments
 (0)