[PATCH] rpmsg: specify dependency between virtio rpmsg and virtio_ns

From: Arnaud Pouliquen
Date: Mon Nov 16 2020 - 09:07:14 EST


The rpmsg_ns service has to be registered before the first
message reception. When used as module, this imply and
dependency of the rpmsg virtio on the rpmsg_ns module.
this patch solve the dependency issue.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@xxxxxx>
---
drivers/rpmsg/Kconfig | 1 +
drivers/rpmsg/rpmsg_ns.c | 2 +-
drivers/rpmsg/virtio_rpmsg_bus.c | 22 ++++++++++++++++++++++
3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig
index c3fc75e6514b..1394114782d2 100644
--- a/drivers/rpmsg/Kconfig
+++ b/drivers/rpmsg/Kconfig
@@ -71,5 +71,6 @@ config RPMSG_VIRTIO
depends on HAS_DMA
select RPMSG
select VIRTIO
+ select RPMSG_NS

endmenu
diff --git a/drivers/rpmsg/rpmsg_ns.c b/drivers/rpmsg/rpmsg_ns.c
index 5bda7cb44618..f19f3cbd2526 100644
--- a/drivers/rpmsg/rpmsg_ns.c
+++ b/drivers/rpmsg/rpmsg_ns.c
@@ -104,5 +104,5 @@ module_exit(rpmsg_ns_exit);

MODULE_DESCRIPTION("Name service announcement rpmsg Driver");
MODULE_AUTHOR("Arnaud Pouliquen <arnaud.pouliquen@xxxxxx>");
-MODULE_ALIAS("rpmsg_ns");
+MODULE_ALIAS("rpmsg:rpmsg_ns");
MODULE_LICENSE("GPL v2");
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 338f16c6563d..f032e6c3f9a9 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -1001,6 +1001,28 @@ static int __init rpmsg_init(void)
{
int ret;

+#ifdef MODULE
+ static const char name[] = "rpmsg_ns";
+ struct module *ns;
+
+ /*
+ * Make sur that the rpmsg ns module is loaded in case of module.
+ * This ensures that the rpmsg_ns driver is probed immediately when the
+ * associated device is registered during the rpmsg virtio probe.
+ */
+ mutex_lock(&module_mutex);
+ ns = find_module(name);
+ mutex_unlock(&module_mutex);
+
+ if (!ns) {
+ ret = request_module(name);
+ if (ret) {
+ pr_err("can not find %s module (err %d)\n", name, ret);
+ return ret;
+ }
+ }
+#endif
+
ret = register_virtio_driver(&virtio_ipc_driver);
if (ret)
pr_err("failed to register virtio driver: %d\n", ret);
--
2.17.1