summaryrefslogtreecommitdiffstats
path: root/drivers/base/soc.c
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2016-09-27 11:10:29 -0400
committerGeert Uytterhoeven <geert+renesas@glider.be>2016-11-10 04:10:25 -0500
commit1da1b3628df34a2a5e38b70c8551770aadce969d (patch)
treeba730b41516efc7d3d1d31bc8ccc9284da13838a /drivers/base/soc.c
parent1001354ca34179f3db924eb66672442a173147dc (diff)
base: soc: Early register bus when needed
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 initcall. 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>
Diffstat (limited to 'drivers/base/soc.c')
-rw-r--r--drivers/base/soc.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index b63f23e6ad61..028cef377fd4 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -113,6 +113,12 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
113 struct soc_device *soc_dev; 113 struct soc_device *soc_dev;
114 int ret; 114 int ret;
115 115
116 if (!soc_bus_type.p) {
117 ret = bus_register(&soc_bus_type);
118 if (ret)
119 goto out1;
120 }
121
116 soc_dev = kzalloc(sizeof(*soc_dev), GFP_KERNEL); 122 soc_dev = kzalloc(sizeof(*soc_dev), GFP_KERNEL);
117 if (!soc_dev) { 123 if (!soc_dev) {
118 ret = -ENOMEM; 124 ret = -ENOMEM;
@@ -156,6 +162,9 @@ void soc_device_unregister(struct soc_device *soc_dev)
156 162
157static int __init soc_bus_register(void) 163static int __init soc_bus_register(void)
158{ 164{
165 if (soc_bus_type.p)
166 return 0;
167
159 return bus_register(&soc_bus_type); 168 return bus_register(&soc_bus_type);
160} 169}
161core_initcall(soc_bus_register); 170core_initcall(soc_bus_register);