Skip to content

Commit

Permalink
rpmsg: core: Make rpmsg_class constant
Browse files Browse the repository at this point in the history
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 <gregkh@linuxfoundation.org>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
Link: https://lore.kernel.org/r/20240305-class_cleanup-remoteproc-v1-1-19373374e003@marliere.net
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
  • Loading branch information
rbmarliere authored and mathieupoirier committed Mar 26, 2024
1 parent 4cece76 commit 193d0c4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion drivers/rpmsg/rpmsg_char.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ static struct rpmsg_eptdev *rpmsg_chrdev_eptdev_alloc(struct rpmsg_device *rpdev
init_waitqueue_head(&eptdev->readq);

device_initialize(dev);
dev->class = rpmsg_class;
dev->class = &rpmsg_class;
dev->parent = parent;
dev->groups = rpmsg_eptdev_groups;
dev_set_drvdata(dev, eptdev);
Expand Down
16 changes: 9 additions & 7 deletions drivers/rpmsg/rpmsg_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

#include "rpmsg_internal.h"

struct class *rpmsg_class;
const struct class rpmsg_class = {
.name = "rpmsg",
};
EXPORT_SYMBOL(rpmsg_class);

/**
Expand Down Expand Up @@ -715,16 +717,16 @@ static int __init rpmsg_init(void)
{
int ret;

rpmsg_class = class_create("rpmsg");
if (IS_ERR(rpmsg_class)) {
pr_err("failed to create rpmsg class\n");
return PTR_ERR(rpmsg_class);
ret = class_register(&rpmsg_class);
if (ret) {
pr_err("failed to register rpmsg class\n");
return ret;
}

ret = bus_register(&rpmsg_bus);
if (ret) {
pr_err("failed to register rpmsg bus: %d\n", ret);
class_destroy(rpmsg_class);
class_destroy(&rpmsg_class);
}
return ret;
}
Expand All @@ -733,7 +735,7 @@ postcore_initcall(rpmsg_init);
static void __exit rpmsg_fini(void)
{
bus_unregister(&rpmsg_bus);
class_destroy(rpmsg_class);
class_destroy(&rpmsg_class);
}
module_exit(rpmsg_fini);

Expand Down
2 changes: 1 addition & 1 deletion drivers/rpmsg/rpmsg_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static int rpmsg_ctrldev_probe(struct rpmsg_device *rpdev)
dev = &ctrldev->dev;
device_initialize(dev);
dev->parent = &rpdev->dev;
dev->class = rpmsg_class;
dev->class = &rpmsg_class;

mutex_init(&ctrldev->ctrl_lock);
cdev_init(&ctrldev->cdev, &rpmsg_ctrldev_fops);
Expand Down
2 changes: 1 addition & 1 deletion drivers/rpmsg/rpmsg_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define to_rpmsg_device(d) container_of(d, struct rpmsg_device, dev)
#define to_rpmsg_driver(d) container_of(d, struct rpmsg_driver, drv)

extern struct class *rpmsg_class;
extern const struct class rpmsg_class;

/**
* struct rpmsg_device_ops - indirection table for the rpmsg_device operations
Expand Down

0 comments on commit 193d0c4

Please sign in to comment.