Skip to content

Commit 608edd9

Browse files
arnopoandersson
authored andcommitted
rpmsg: Create the rpmsg class in core instead of in rpmsg char
Migrate the creation of the rpmsg class from the rpmsg_char to the core that the class is usable by the rpmsg_char and the future rpmsg_ctrl module. Suggested-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Link: https://lore.kernel.org/r/20220124102524.295783-3-arnaud.pouliquen@foss.st.com
1 parent 69265bc commit 608edd9

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

drivers/rpmsg/rpmsg_char.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
#include <uapi/linux/rpmsg.h>
2828

2929
#include "rpmsg_char.h"
30+
#include "rpmsg_internal.h"
3031

3132
#define RPMSG_DEV_MAX (MINORMASK + 1)
3233

3334
static dev_t rpmsg_major;
34-
static struct class *rpmsg_class;
3535

3636
static DEFINE_IDA(rpmsg_ctrl_ida);
3737
static DEFINE_IDA(rpmsg_ept_ida);
@@ -550,17 +550,9 @@ static int rpmsg_chrdev_init(void)
550550
return ret;
551551
}
552552

553-
rpmsg_class = class_create(THIS_MODULE, "rpmsg");
554-
if (IS_ERR(rpmsg_class)) {
555-
pr_err("failed to create rpmsg class\n");
556-
unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX);
557-
return PTR_ERR(rpmsg_class);
558-
}
559-
560553
ret = register_rpmsg_driver(&rpmsg_chrdev_driver);
561554
if (ret < 0) {
562555
pr_err("failed to register rpmsg driver\n");
563-
class_destroy(rpmsg_class);
564556
unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX);
565557
}
566558

@@ -571,7 +563,6 @@ postcore_initcall(rpmsg_chrdev_init);
571563
static void rpmsg_chrdev_exit(void)
572564
{
573565
unregister_rpmsg_driver(&rpmsg_chrdev_driver);
574-
class_destroy(rpmsg_class);
575566
unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX);
576567
}
577568
module_exit(rpmsg_chrdev_exit);

drivers/rpmsg/rpmsg_core.c

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

2121
#include "rpmsg_internal.h"
2222

23+
struct class *rpmsg_class;
24+
EXPORT_SYMBOL(rpmsg_class);
25+
2326
/**
2427
* rpmsg_create_channel() - create a new rpmsg channel
2528
* using its name and address info.
@@ -662,17 +665,25 @@ static int __init rpmsg_init(void)
662665
{
663666
int ret;
664667

668+
rpmsg_class = class_create(THIS_MODULE, "rpmsg");
669+
if (IS_ERR(rpmsg_class)) {
670+
pr_err("failed to create rpmsg class\n");
671+
return PTR_ERR(rpmsg_class);
672+
}
673+
665674
ret = bus_register(&rpmsg_bus);
666-
if (ret)
675+
if (ret) {
667676
pr_err("failed to register rpmsg bus: %d\n", ret);
668-
677+
class_destroy(rpmsg_class);
678+
}
669679
return ret;
670680
}
671681
postcore_initcall(rpmsg_init);
672682

673683
static void __exit rpmsg_fini(void)
674684
{
675685
bus_unregister(&rpmsg_bus);
686+
class_destroy(rpmsg_class);
676687
}
677688
module_exit(rpmsg_fini);
678689

drivers/rpmsg/rpmsg_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
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;
22+
2123
/**
2224
* struct rpmsg_device_ops - indirection table for the rpmsg_device operations
2325
* @create_channel: create backend-specific channel, optional

0 commit comments

Comments
 (0)