Skip to content

Commit

Permalink
base: soc: populate machine name in soc_device_register if empty
Browse files Browse the repository at this point in the history
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>
Acked-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Link: https://lore.kernel.org/r/6dbdf458-9f46-613e-de58-b4a56a6cdd9f@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Heiner Kallweit authored and Greg Kroah-Hartman committed Mar 29, 2023
1 parent 7b884b7 commit 3f84aa5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions drivers/base/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 3f84aa5

Please sign in to comment.