summaryrefslogtreecommitdiffstats
path: root/include/driver.h
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 /include/driver.h
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 'include/driver.h')
-rw-r--r--include/driver.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/include/driver.h b/include/driver.h
index c12ca9c2f7..94fddc735e 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -45,6 +45,12 @@ struct device_d {
* be used instead.
*/
char name[MAX_DRIVER_NAME];
+
+ /*! This member is used to store device's unique name as
+ * obtained by calling dev_id(). Internal field, do not
+ * access it directly.
+ */
+ char unique_name[MAX_DRIVER_NAME + 16];
/*! The id is used to uniquely identify a device in the system. The id
* will show up under /dev/ as the device's name. Usually this is
* something like eth0 or nor0. */
@@ -173,7 +179,10 @@ int get_free_deviceid(const char *name_template);
char *deviceid_from_spec_str(const char *str, char **endp);
-extern const char *dev_id(const struct device_d *dev);
+static inline const char *dev_id(const struct device_d *dev)
+{
+ return (dev->id != DEVICE_ID_SINGLE) ? dev->unique_name : dev->name;
+}
static inline const char *dev_name(const struct device_d *dev)
{