summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/barebox-state/state.c2
-rw-r--r--src/dt/common.h26
2 files changed, 27 insertions, 1 deletions
diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c
index d5b1ddd..fd3cbbc 100644
--- a/src/barebox-state/state.c
+++ b/src/barebox-state/state.c
@@ -178,7 +178,7 @@ static struct state *state_new(const char *name)
int ret;
state = xzalloc(sizeof(*state));
- safe_strncpy(state->dev.name, name, MAX_DRIVER_NAME);
+ dev_set_name(&state->dev, name);
state->name = state->dev.name;
state->dev.id = DEVICE_ID_SINGLE;
INIT_LIST_HEAD(&state->variables);
diff --git a/src/dt/common.h b/src/dt/common.h
index cbe17ce..de8d293 100644
--- a/src/dt/common.h
+++ b/src/dt/common.h
@@ -406,6 +406,32 @@ static inline struct param_d *dev_add_param_uint32(struct device_d *dev, const c
return NULL;
}
+/**
+ * dev_set_name - set a device name
+ * @dev: device
+ * @fmt: format string for the device's name
+ */
+static inline int dev_set_name(struct device_d *dev, const char *fmt, ...)
+{
+ char newname[MAX_DRIVER_NAME];
+ va_list vargs;
+ int err;
+
+ va_start(vargs, fmt);
+ err = vsnprintf(newname, MAX_DRIVER_NAME, fmt, vargs);
+ va_end(vargs);
+
+ /*
+ * Copy new name into dev structure, we do this after vsnprintf call in
+ * case old device name was in one of vargs
+ */
+ safe_strncpy(dev->name, newname, MAX_DRIVER_NAME);
+
+ WARN_ON(err < 0);
+
+ return err;
+}
+
struct driver_d;
static inline int register_driver(struct driver_d *d)