diff mbox series

[4.4.y-cip,01/11] base: soc: Early register bus when needed

Message ID 20201130141916.8211-2-prabhakar.mahadev-lad.rj@bp.renesas.com (mailing list archive)
State Changes Requested
Delegated to: Nobuhiro Iwamatsu
Headers show
Series Renesas RZ/G1x add SoC detection support | expand

Commit Message

Lad Prabhakar Nov. 30, 2020, 2:19 p.m. UTC
From: Geert Uytterhoeven <geert+renesas@glider.be>

commit 1da1b3628df34a2a5e38b70c8551770aadce969d upstream.

If soc_device_register() is called before soc_bus_register(), it crashes
with a NULL pointer dereference.

soc_bus_register() is already a core_initcall(), but drivers/base/ is
entered later than e.g. drivers/pinctrl/ and drivers/soc/. Hence there
are several subsystems that may need to know SoC revision information,
while it's not so easy to initialize the SoC bus even earlier using an

To fix this, let soc_device_register() register the bus early if that
hasn't happened yet.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
 drivers/base/soc.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series


diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 84242e6b2897..c9fd0ee2ba50 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -114,6 +114,12 @@  struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
 	struct soc_device *soc_dev;
 	int ret;
+	if (!soc_bus_type.p) {
+		ret = bus_register(&soc_bus_type);
+		if (ret)
+			goto out1;
+	}
 	soc_dev = kzalloc(sizeof(*soc_dev), GFP_KERNEL);
 	if (!soc_dev) {
 		ret = -ENOMEM;
@@ -159,6 +165,9 @@  EXPORT_SYMBOL_GPL(soc_device_unregister);
 static int __init soc_bus_register(void)
+	if (soc_bus_type.p)
+		return 0;
 	return bus_register(&soc_bus_type);