Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

driver core: soc: remove layering violation for the soc_bus

The soc_bus code pokes around in the internal bus structures assuming
that it "knows" if a field is not set that it has not been registered
yet. That isn't a safe assumption, so just remove the layering
violation entirely and keep track if the bus has been registered or not
ourselves.

Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20230130171059.1784057-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+3 -1
+3 -1
drivers/base/soc.c
··· 30 30 static struct bus_type soc_bus_type = { 31 31 .name = "soc", 32 32 }; 33 + static bool soc_bus_registered; 33 34 34 35 static DEVICE_ATTR(machine, 0444, soc_info_show, NULL); 35 36 static DEVICE_ATTR(family, 0444, soc_info_show, NULL); ··· 118 117 const struct attribute_group **soc_attr_groups; 119 118 int ret; 120 119 121 - if (!soc_bus_type.p) { 120 + if (!soc_bus_registered) { 122 121 if (early_soc_dev_attr) 123 122 return ERR_PTR(-EBUSY); 124 123 early_soc_dev_attr = soc_dev_attr; ··· 184 183 ret = bus_register(&soc_bus_type); 185 184 if (ret) 186 185 return ret; 186 + soc_bus_registered = true; 187 187 188 188 if (early_soc_dev_attr) 189 189 return PTR_ERR(soc_device_register(early_soc_dev_attr));