From bc3c57c13256c748a4e71d2ea7481d0c953e88e1 Mon Sep 17 00:00:00 2001 From: "Andrew F. Davis" Date: Wed, 4 May 2016 17:01:36 -0500 Subject: [PATCH 1/4] rpmsg: add THIS_MODULE to rpmsg_driver in rpmsg core Add register_rpmsg_driver helper macro that adds THIS_MODULE to rpmsg_driver for the registering driver. We rename and modify the existing register_rpmsg_driver to enable this. Signed-off-by: Andrew F. Davis Acked-by: Suman Anna Signed-off-by: Bjorn Andersson --- drivers/rpmsg/virtio_rpmsg_bus.c | 8 +++++--- include/linux/rpmsg.h | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 1fcd27c1f183..fe03b2aef450 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -436,17 +436,19 @@ static struct bus_type rpmsg_bus = { }; /** - * register_rpmsg_driver() - register an rpmsg driver with the rpmsg bus + * __register_rpmsg_driver() - register an rpmsg driver with the rpmsg bus * @rpdrv: pointer to a struct rpmsg_driver + * @owner: owning module/driver * * Returns 0 on success, and an appropriate error value on failure. */ -int register_rpmsg_driver(struct rpmsg_driver *rpdrv) +int __register_rpmsg_driver(struct rpmsg_driver *rpdrv, struct module *owner) { rpdrv->drv.bus = &rpmsg_bus; + rpdrv->drv.owner = owner; return driver_register(&rpdrv->drv); } -EXPORT_SYMBOL(register_rpmsg_driver); +EXPORT_SYMBOL(__register_rpmsg_driver); /** * unregister_rpmsg_driver() - unregister an rpmsg driver from the rpmsg bus diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 82a673905edb..7ff5790c185a 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -169,7 +169,7 @@ struct rpmsg_driver { int register_rpmsg_device(struct rpmsg_channel *dev); void unregister_rpmsg_device(struct rpmsg_channel *dev); -int register_rpmsg_driver(struct rpmsg_driver *drv); +int __register_rpmsg_driver(struct rpmsg_driver *drv, struct module *owner); void unregister_rpmsg_driver(struct rpmsg_driver *drv); void rpmsg_destroy_ept(struct rpmsg_endpoint *); struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_channel *, @@ -177,6 +177,10 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_channel *, int rpmsg_send_offchannel_raw(struct rpmsg_channel *, u32, u32, void *, int, bool); +/* use a macro to avoid include chaining to get THIS_MODULE */ +#define register_rpmsg_driver(drv) \ + __register_rpmsg_driver(drv, THIS_MODULE) + /** * rpmsg_send() - send a message across to the remote processor * @rpdev: the rpmsg channel From 9122bf1839c039a0052c0a75a3c4daf9277b5dd5 Mon Sep 17 00:00:00 2001 From: "Andrew F. Davis" Date: Wed, 4 May 2016 17:01:37 -0500 Subject: [PATCH 2/4] rpmsg: drop owner assignment from rpmsg_drivers An rpmsg_driver does not need to set an owner, it will be populated by the driver core. Signed-off-by: Andrew F. Davis Signed-off-by: Bjorn Andersson --- Documentation/rpmsg.txt | 1 - samples/rpmsg/rpmsg_client_sample.c | 1 - 2 files changed, 2 deletions(-) diff --git a/Documentation/rpmsg.txt b/Documentation/rpmsg.txt index f7edc3aa1e92..1d884269e40c 100644 --- a/Documentation/rpmsg.txt +++ b/Documentation/rpmsg.txt @@ -249,7 +249,6 @@ MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table); static struct rpmsg_driver rpmsg_sample_client = { .drv.name = KBUILD_MODNAME, - .drv.owner = THIS_MODULE, .id_table = rpmsg_driver_sample_id_table, .probe = rpmsg_sample_probe, .callback = rpmsg_sample_cb, diff --git a/samples/rpmsg/rpmsg_client_sample.c b/samples/rpmsg/rpmsg_client_sample.c index 59b13440813d..82ed288dcf07 100644 --- a/samples/rpmsg/rpmsg_client_sample.c +++ b/samples/rpmsg/rpmsg_client_sample.c @@ -77,7 +77,6 @@ MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table); static struct rpmsg_driver rpmsg_sample_client = { .drv.name = KBUILD_MODNAME, - .drv.owner = THIS_MODULE, .id_table = rpmsg_driver_sample_id_table, .probe = rpmsg_sample_probe, .callback = rpmsg_sample_cb, From f3d9f1ce079370d19b34fc9927b8b1355ac98503 Mon Sep 17 00:00:00 2001 From: "Andrew F. Davis" Date: Wed, 4 May 2016 17:01:38 -0500 Subject: [PATCH 3/4] rpmsg: add helper macro module_rpmsg_driver This patch introduces the module_rpmsg_driver macro which is a convenience macro for rpmsg driver modules similar to module_platform_driver. It is intended to be used by drivers which init/exit section does nothing but register/unregister the rpmsg driver. By using this macro it is possible to eliminate a few lines of boilerplate code per rpmsg driver. Signed-off-by: Andrew F. Davis Signed-off-by: Bjorn Andersson --- include/linux/rpmsg.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 7ff5790c185a..ada50ff36da0 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -181,6 +181,18 @@ rpmsg_send_offchannel_raw(struct rpmsg_channel *, u32, u32, void *, int, bool); #define register_rpmsg_driver(drv) \ __register_rpmsg_driver(drv, THIS_MODULE) +/** + * module_rpmsg_driver() - Helper macro for registering an rpmsg driver + * @__rpmsg_driver: rpmsg_driver struct + * + * Helper macro for rpmsg drivers which do not do anything special in module + * init/exit. This eliminates a lot of boilerplate. Each module may only + * use this macro once, and calling it replaces module_init() and module_exit() + */ +#define module_rpmsg_driver(__rpmsg_driver) \ + module_driver(__rpmsg_driver, register_rpmsg_driver, \ + unregister_rpmsg_driver) + /** * rpmsg_send() - send a message across to the remote processor * @rpdev: the rpmsg channel From b4f78259d593858feb85e02c195cf374f932feef Mon Sep 17 00:00:00 2001 From: "Andrew F. Davis" Date: Wed, 4 May 2016 17:01:39 -0500 Subject: [PATCH 4/4] rpmsg: use module_rpmsg_driver in existing drivers and examples Existing drivers and examples are updated to use the module_rpmsg_driver helper macro. Signed-off-by: Andrew F. Davis Signed-off-by: Bjorn Andersson --- Documentation/rpmsg.txt | 13 +------------ samples/rpmsg/rpmsg_client_sample.c | 13 +------------ 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/Documentation/rpmsg.txt b/Documentation/rpmsg.txt index 1d884269e40c..a95e36a43288 100644 --- a/Documentation/rpmsg.txt +++ b/Documentation/rpmsg.txt @@ -254,18 +254,7 @@ static struct rpmsg_driver rpmsg_sample_client = { .callback = rpmsg_sample_cb, .remove = rpmsg_sample_remove, }; - -static int __init init(void) -{ - return register_rpmsg_driver(&rpmsg_sample_client); -} -module_init(init); - -static void __exit fini(void) -{ - unregister_rpmsg_driver(&rpmsg_sample_client); -} -module_exit(fini); +module_rpmsg_driver(rpmsg_sample_client); Note: a similar sample which can be built and loaded can be found in samples/rpmsg/. diff --git a/samples/rpmsg/rpmsg_client_sample.c b/samples/rpmsg/rpmsg_client_sample.c index 82ed288dcf07..d0e249c90668 100644 --- a/samples/rpmsg/rpmsg_client_sample.c +++ b/samples/rpmsg/rpmsg_client_sample.c @@ -82,18 +82,7 @@ static struct rpmsg_driver rpmsg_sample_client = { .callback = rpmsg_sample_cb, .remove = rpmsg_sample_remove, }; - -static int __init rpmsg_client_sample_init(void) -{ - return register_rpmsg_driver(&rpmsg_sample_client); -} -module_init(rpmsg_client_sample_init); - -static void __exit rpmsg_client_sample_fini(void) -{ - unregister_rpmsg_driver(&rpmsg_sample_client); -} -module_exit(rpmsg_client_sample_fini); +module_rpmsg_driver(rpmsg_sample_client); MODULE_DESCRIPTION("Remote processor messaging sample client driver"); MODULE_LICENSE("GPL v2");