driver core: soc: remove layering violation for the soc_bus
Greg Kroah-Hartman
maintainerPATCH 1/1 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.
--- drivers/base/soc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/soc.c +3 -1
@@ -30,6 +30,7 @@ struct soc_device {static struct bus_type soc_bus_type = { .name ="soc" , }; +static bool soc_bus_registered; static DEVICE_ATTR(machine, 0444, soc_info_show, NULL); static DEVICE_ATTR(family, 0444, soc_info_show, NULL);
@@ -117,7 +118,7 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attrconst struct attribute_group **soc_attr_groups;int ret; -if (!soc_bus_type.p) { +if (!soc_bus_registered) {if (early_soc_dev_attr)return ERR_PTR (-EBUSY ); early_soc_dev_attr = soc_dev_attr;
@@ -183,6 +184,7 @@ static int __init soc_bus_register(void) ret =bus_register (&soc_bus_type);if (ret)return ret; + soc_bus_registered = true;if (early_soc_dev_attr)return PTR_ERR (soc_device_register (early_soc_dev_attr));
Signature · 1 line
2.39.1
Quoted 8 lines · Greg Kroah-Hartman
The
soc_buscode 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.Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 36 lines
--- drivers/base/soc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/base/soc.c +3
-2@@ -30,6 +30,7 @@ struct soc_device {static struct bus_type soc_bus_type = { .name ="soc" , }; +static bool soc_bus_registered; static DEVICE_ATTR(machine, 0444, soc_info_show, NULL); static DEVICE_ATTR(family, 0444, soc_info_show, NULL);@@ -117,7 +118,7 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attrconst struct attribute_group **soc_attr_groups;int ret; -if (!soc_bus_type.p) { +if (!soc_bus_registered) {if (early_soc_dev_attr)return ERR_PTR (-EBUSY ); early_soc_dev_attr = soc_dev_attr;@@ -183,6 +184,7 @@ static int __init soc_bus_register(void) ret =bus_register (&soc_bus_type);if (ret)return ret; + soc_bus_registered = true;if (early_soc_dev_attr)return PTR_ERR (soc_device_register (early_soc_dev_attr)); --2.39.1
Greg Kroah-Hartman
maintainerQuoted 9 lines · Rafael J. Wysocki
Quoted 7 lines · Greg Kroah-Hartman
The
soc_buscode 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.
Quoted 3 lines
Quoted 1 line
Signed-off-by Greg Kroah-Hartman <[email protected]>Reviewed-by Rafael J. Wysocki <[email protected]>
Thanks for the quick review!