summaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-10-16 12:15:41 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-10-18 09:02:24 +0200
commite317adeeb7c50a5eeb0a88da39857c7cc6f9b366 (patch)
treebbed744c1fe36c8ca44c1c39aa090628064842eb /drivers/base
parent05683764a77ff91419cabe0c26e537589b8a28ff (diff)
downloadbarebox-e317adeeb7c50a5eeb0a88da39857c7cc6f9b366.tar.gz
barebox-e317adeeb7c50a5eeb0a88da39857c7cc6f9b366.tar.xz
base: Don't use shared buffer for results of dev_id()
Using shared memory buffer to return results of dev_id() leads to incorrect results when used as follows: dev_info(..., "... %s ...\n", ..., dev_name(foo), ...); since result returned for dev_name(foo) will be overwritten by dev_name() call that will happen as a part of dev_* logging functions. To prevent that allocate a dedicated field "unique_name" in struct device_d and use it to store unique name returned by dev_id()/dev_name(). Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/driver.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index c9e6e6ddd6..b7720f31ab 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -183,6 +183,13 @@ int register_device(struct device_d *new_device)
}
}
+ if (new_device->id != DEVICE_ID_SINGLE)
+ snprintf(new_device->unique_name,
+ sizeof(new_device->unique_name),
+ FORMAT_DRIVER_NAME_ID,
+ new_device->name,
+ new_device->id);
+
debug ("register_device: %s\n", dev_name(new_device));
list_add_tail(&new_device->list, &device_list);
@@ -466,18 +473,6 @@ int dummy_probe(struct device_d *dev)
}
EXPORT_SYMBOL(dummy_probe);
-const char *dev_id(const struct device_d *dev)
-{
- static char buf[MAX_DRIVER_NAME + 16];
-
- if (dev->id != DEVICE_ID_SINGLE)
- snprintf(buf, sizeof(buf), FORMAT_DRIVER_NAME_ID, dev->name, dev->id);
- else
- snprintf(buf, sizeof(buf), "%s", dev->name);
-
- return buf;
-}
-
/**
* dev_set_name - set a device name
* @dev: device