diff mbox series

[1/2] base: soc: populate machine name in soc_device_register if empty

Message ID 6dbdf458-9f46-613e-de58-b4a56a6cdd9f@gmail.com (mailing list archive)
State New, archived
Headers show
Series base: soc: populate machine name in soc_device_register if empty | expand

Commit Message

Heiner Kallweit March 17, 2023, 12:36 p.m. UTC
Several SoC drivers use the same of-based mechanism to populate the machine
name. Therefore move this to the core and try to populate the machine name
in soc_device_register if it's not set yet.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/base/soc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Martin Blumenstingl March 20, 2023, 3:39 p.m. UTC | #1
On Fri, Mar 17, 2023 at 1:37 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
[...]
> +static void soc_device_get_machine(struct soc_device_attribute *soc_dev_attr)
> +{
> +       struct device_node *np;
> +
> +       if (soc_dev_attr->machine)
> +               return;
> +
> +       np = of_find_node_by_path("/");
> +       of_property_read_string(np, "model", &soc_dev_attr->machine);
> +       of_node_put(np);
At first I thought there's a problem with non-OF machines here.
But if CONFIG_OF is disabled the code above is a no-op because we're
not checking any error/return codes.

So this gets my:
Acked-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
diff mbox series

Patch

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 0fb1d4ab9..8dec5228f 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -7,6 +7,7 @@ 
 
 #include <linux/sysfs.h>
 #include <linux/init.h>
+#include <linux/of.h>
 #include <linux/stat.h>
 #include <linux/slab.h>
 #include <linux/idr.h>
@@ -110,6 +111,18 @@  static void soc_release(struct device *dev)
 	kfree(soc_dev);
 }
 
+static void soc_device_get_machine(struct soc_device_attribute *soc_dev_attr)
+{
+	struct device_node *np;
+
+	if (soc_dev_attr->machine)
+		return;
+
+	np = of_find_node_by_path("/");
+	of_property_read_string(np, "model", &soc_dev_attr->machine);
+	of_node_put(np);
+}
+
 static struct soc_device_attribute *early_soc_dev_attr;
 
 struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr)
@@ -118,6 +131,8 @@  struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
 	const struct attribute_group **soc_attr_groups;
 	int ret;
 
+	soc_device_get_machine(soc_dev_attr);
+
 	if (!soc_bus_registered) {
 		if (early_soc_dev_attr)
 			return ERR_PTR(-EBUSY);