From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 14/44] param: make bobject_add_param_fixed variadic
Date: Mon, 11 Aug 2025 14:27:54 +0200 [thread overview]
Message-ID: <20250811122824.1667791-15-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250811122824.1667791-1-a.fatoum@barebox.org>
The upcoming structured I/O support will make heavy use of
bobject_add_param_fixed, so prepare for that by making it receive a
format string and variadic arguments.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
arch/arm/boards/animeo_ip/init.c | 4 +--
arch/arm/boards/at91sam9m10ihd/hw_version.c | 10 ++-----
arch/arm/boards/at91sam9x5ek/hw_version.c | 10 ++-----
common/console.c | 11 ++------
drivers/efi/efi-device.c | 4 +--
drivers/usb/core/usb.c | 6 ++--
fs/fs.c | 3 +-
include/param.h | 25 +++++++++++++----
lib/parameter.c | 31 +++++++++++++++++----
9 files changed, 62 insertions(+), 42 deletions(-)
diff --git a/arch/arm/boards/animeo_ip/init.c b/arch/arm/boards/animeo_ip/init.c
index a0a2007d521d..e46ede939aba 100644
--- a/arch/arm/boards/animeo_ip/init.c
+++ b/arch/arm/boards/animeo_ip/init.c
@@ -82,8 +82,8 @@ static void animeo_ip_detect_version(void)
version = "IO";
}
- dev_add_param_fixed(dev, "model", model);
- dev_add_param_fixed(dev, "version", version);
+ dev_add_param_fixed(dev, "model", "%s", model);
+ dev_add_param_fixed(dev, "version", "%s", version);
}
static struct atmel_nand_data nand_pdata = {
diff --git a/arch/arm/boards/at91sam9m10ihd/hw_version.c b/arch/arm/boards/at91sam9m10ihd/hw_version.c
index 9ae4ccb77c75..b7b231fd0a09 100644
--- a/arch/arm/boards/at91sam9m10ihd/hw_version.c
+++ b/arch/arm/boards/at91sam9m10ihd/hw_version.c
@@ -134,7 +134,6 @@ static void at91sam9m10ihd_devices_detect_one(const char *name)
struct board_info* binfo;
struct vendor_info* vinfo;
struct device *dev = NULL;
- char str[16];
u8 vendor_id = 0;
if (at91sam9m10ihd_read_w1(name, &info))
@@ -180,14 +179,11 @@ static void at91sam9m10ihd_devices_detect_one(const char *name)
dev_add_param_fixed(dev, "vendor", info.vendor_name);
dev_add_param_fixed(dev, "board", info.board_name);
- sprintf(str, "%.2s", info.vendor_country);
- dev_add_param_fixed(dev, "country", str);
+ dev_add_param_fixed(dev, "country", "%.2s", info.vendor_country);
dev_add_param_uint32_fixed(dev, "year", info.year, "%u");
dev_add_param_uint32_fixed(dev, "week", info.week, "%u");
- sprintf(str, "%c", info.revision_code);
- dev_add_param_fixed(dev, "revision_code", str);
- sprintf(str, "%c", info.revision_id);
- dev_add_param_fixed(dev, "revision_id", str);
+ dev_add_param_fixed(dev, "revision_code", "%c", info.revision_code);
+ dev_add_param_fixed(dev, "revision_id", "%c", info.revision_id);
}
void at91sam9m10ihd_devices_detect_hw(void)
diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 9c6bd6866098..55ce409dfdad 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -150,7 +150,6 @@ static void at91sam9x5ek_devices_detect_one(const char *name)
struct board_info* binfo;
struct vendor_info* vinfo;
struct device *dev = NULL;
- char str[16];
u8 vendor_id = 0;
if (at91sam9x5ek_read_w1(name, &info))
@@ -206,14 +205,11 @@ static void at91sam9x5ek_devices_detect_one(const char *name)
dev_add_param_fixed(dev, "vendor", info.vendor_name);
dev_add_param_fixed(dev, "board", info.board_name);
- sprintf(str, "%.2s", info.vendor_country);
- dev_add_param_fixed(dev, "country", str);
+ dev_add_param_fixed(dev, "country", "%.2s", info.vendor_country);
dev_add_param_uint32_fixed(dev, "year", info.year, "%u");
dev_add_param_uint32_fixed(dev, "week", info.week, "%u");
- sprintf(str, "%c", info.revision_code);
- dev_add_param_fixed(dev, "revision_code", str);
- sprintf(str, "%c", info.revision_id);
- dev_add_param_fixed(dev, "revision_id", str);
+ dev_add_param_fixed(dev, "revision_code", "%c", info.revision_code);
+ dev_add_param_fixed(dev, "revision_id", "%c", info.revision_id);
}
#define NODE_NAME_LEN 128
diff --git a/common/console.c b/common/console.c
index 393183a72514..dc552e4c5dac 100644
--- a/common/console.c
+++ b/common/console.c
@@ -222,17 +222,12 @@ static void console_init_early(void)
static void console_add_earlycon_param(struct console_device *cdev, unsigned baudrate)
{
- char *str;
-
if (!cdev->linux_earlycon_name)
return;
- str = basprintf("earlycon=%s,0x%lx", cdev->linux_earlycon_name,
- (ulong)cdev->phys_base);
-
- dev_add_param_fixed(&cdev->class_dev, "linux.bootargs.earlycon", str);
-
- free(str);
+ dev_add_param_fixed(&cdev->class_dev, "linux.bootargs.earlycon",
+ "earlycon=%s,0x%lx", cdev->linux_earlycon_name,
+ (ulong)cdev->phys_base);
}
void console_set_stdoutpath(struct console_device *cdev, unsigned baudrate)
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 0e6f75659f62..15884646dc18 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -197,7 +197,7 @@ static int efi_register_device(struct efi_device *efidev)
dev_path_str = device_path_to_str(efidev->devpath);
if (dev_path_str) {
- dev_add_param_fixed(&efidev->dev, "devpath", dev_path_str);
+ dev_add_param_fixed(&efidev->dev, "devpath", "%s", dev_path_str);
free(dev_path_str);
}
@@ -421,7 +421,7 @@ static int efi_init_devices(void)
bus_register(&efi_bus);
- dev_add_param_fixed(&efi_bus.dev, "fw_vendor", fw_vendor);
+ dev_add_param_fixed(&efi_bus.dev, "fw_vendor", "%s", fw_vendor);
free(fw_vendor);
dev_add_param_uint32_fixed(&efi_bus.dev, "major", sys_major, "%u");
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index ec487107584c..d144e9840916 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -558,9 +558,9 @@ int usb_new_device(struct usb_device *dev)
dev->descriptor->iProduct, "%u");
dev_add_param_uint32_fixed(&dev->dev, "iSerialNumber",
dev->descriptor->iSerialNumber, "%u");
- dev_add_param_fixed(&dev->dev, "Manufacturer", dev->mf);
- dev_add_param_fixed(&dev->dev, "Product", dev->prod);
- dev_add_param_fixed(&dev->dev, "SerialNumber", dev->serial);
+ dev_add_param_fixed(&dev->dev, "Manufacturer", "%s", dev->mf);
+ dev_add_param_fixed(&dev->dev, "Product", "%s", dev->prod);
+ dev_add_param_fixed(&dev->dev, "SerialNumber", "%s", dev->serial);
dev_add_param_uint32_fixed(&dev->dev, "idVendor",
dev->descriptor->idVendor, "%04x");
dev_add_param_uint32_fixed(&dev->dev, "idProduct",
diff --git a/fs/fs.c b/fs/fs.c
index 24c14a590a11..54bd35786857 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1224,7 +1224,8 @@ void fsdev_set_linux_rootarg(struct fs_device *fsdev, const char *str)
{
fsdev->linux_rootarg = xstrdup(str);
- dev_add_param_fixed(&fsdev->dev, "linux.bootargs", fsdev->linux_rootarg);
+ dev_add_param_fixed(&fsdev->dev, "linux.bootargs",
+ "%s", fsdev->linux_rootarg);
}
/**
diff --git a/include/param.h b/include/param.h
index 5f4f87f67c73..1bf04015f266 100644
--- a/include/param.h
+++ b/include/param.h
@@ -6,6 +6,7 @@
#include <linux/types.h>
#include <linux/list.h>
#include <bobject.h>
+#include <stdarg.h>
#define PARAM_FLAG_RO (1 << 0)
#define PARAM_GLOBALVAR_UNQUALIFIED (1 << 1)
@@ -103,8 +104,12 @@ struct param_d *bobject_add_param_file_list(bobject_t bobj, const char *name,
struct file_list **file_list,
void *priv);
+struct param_d *vbobject_add_param_fixed(struct bobject *bobj, const char *name,
+ const char *fmt, va_list ap);
+
struct param_d *bobject_add_param_fixed(bobject_t bobj, const char *name,
- const char *value);
+ const char *fmt, ...)
+ __printf(3, 4);
void param_remove(struct param_d *p);
@@ -224,9 +229,17 @@ static inline struct param_d *bobject_add_param_file_list(bobject_t bobj,
return NULL;
}
-static inline struct param_d *bobject_add_param_fixed(bobject_t bobj,
- const char *name,
- const char *value)
+static inline
+struct param_d *vbobject_add_param_fixed(struct bobject *bobj, const char *name,
+ const char *fmt, va_list ap)
+{
+ return NULL;
+}
+
+static inline __printf(3, 4)
+struct param_d *bobject_add_param_fixed(bobject_t bobj,
+ const char *name,
+ const char *fmt, ...)
{
return NULL;
}
@@ -340,7 +353,7 @@ static inline struct param_d *bobject_add_param_string_fixed(bobject_t bobj,
const char *name,
const char *value)
{
- return bobject_add_param_fixed(bobj, name, value);
+ return bobject_add_param_fixed(bobj, name, "%s", value);
}
static inline struct param_d *bobject_add_param_enum_ro(bobject_t bobj,
@@ -367,6 +380,7 @@ static inline struct param_d *bobject_add_param_bitmask_ro(bobject_t bobj,
#define dev_set_param bobject_set_param
#define dev_add_param bobject_add_param
#define dev_add_param_string bobject_add_param_string
+#define dev_add_param_fixed bobject_add_param_fixed
#define __dev_add_param_int __bobject_add_param_int
#define dev_add_param_enum bobject_add_param_enum
#define dev_add_param_tristate bobject_add_param_tristate
@@ -375,7 +389,6 @@ static inline struct param_d *bobject_add_param_bitmask_ro(bobject_t bobj,
#define dev_add_param_ip bobject_add_param_ip
#define dev_add_param_mac bobject_add_param_mac
#define dev_add_param_file_list bobject_add_param_file_list
-#define dev_add_param_fixed bobject_add_param_fixed
#define dev_param_set_generic bobject_param_set_generic
#define dev_add_param_int bobject_add_param_int
diff --git a/lib/parameter.c b/lib/parameter.c
index ef578d790856..73cc3701b938 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -213,15 +213,14 @@ struct param_d *bobject_add_param(bobject_t _bobj, const char *name,
}
/**
- * bobject_add_param_fixed - add a readonly parameter to a barebox object
+ * vbobject_add_param_fixed - add a readonly parameter to a barebox object
* @param bobj The barebox object
* @param name The name of the parameter
- * @param value The value of the parameter
+ * @param fmt Format string
*/
-struct param_d *bobject_add_param_fixed(bobject_t _bobj, const char *name,
- const char *value)
+struct param_d *vbobject_add_param_fixed(struct bobject *bobj, const char *name,
+ const char *fmt, va_list ap)
{
- struct bobject *bobj = _bobj.bobj;
struct param_d *param;
int ret;
@@ -233,7 +232,27 @@ struct param_d *bobject_add_param_fixed(bobject_t _bobj, const char *name,
return ERR_PTR(ret);
}
- param->value = strdup(value);
+ param->value = fmt ? bvasprintf(fmt, ap) : NULL;
+
+ return param;
+}
+
+/**
+ * bobject_add_param_fixed - add a readonly parameter to a barebox object
+ * @param bobj The barebox object
+ * @param name The name of the parameter
+ * @param fmt Format string
+ */
+struct param_d *bobject_add_param_fixed(bobject_t _bobj, const char *name,
+ const char *fmt, ...)
+{
+ struct bobject *bobj = _bobj.bobj;
+ struct param_d *param;
+ va_list ap;
+
+ va_start(ap, fmt);
+ param = vbobject_add_param_fixed(bobj, name, fmt, ap);
+ va_end(ap);
return param;
}
--
2.39.5
next prev parent reply other threads:[~2025-08-11 12:30 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 12:27 [PATCH 00/44] commands: add bfetch/buds of command redirection Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 01/44] driver: move device name definition into device.h Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 02/44] driver: introduce common struct bobject Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 03/44] lib: param: rename dev_remove_param to param_remove Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 04/44] param: implement dev_remove_parameters using param_remove Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 05/44] lib: param: add dev_for_each_param helpers Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 06/44] driver: initialize device parameters as part of bobject Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 07/44] param: operate on bobjects instead of full devices Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 08/44] commands: version: print value of CONFIG_NAME Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 09/44] treewide: populate CONFIG_NAME for all configs in-tree Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 10/44] test: py: change barebox_config from set to dict Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 11/44] test: add heuristic for guessing labgrid environment YAML Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 12/44] usb: drop dead iSerialNumber parameter addition Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 13/44] drivers: use dev_add_param_uint32_fixed for IDs Ahmad Fatoum
2025-08-11 12:27 ` Ahmad Fatoum [this message]
2025-08-11 12:27 ` [PATCH 15/44] param: handle NULL gracefully in bobject_get_param Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 16/44] common: introduce structured I/O Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 17/44] ARM: cpuinfo: support structio output Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 18/44] commands: uptime: enable structured I/O Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 19/44] string: implement strv_length helper Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 20/44] ARM: psci: client: add PSCI version/method parameters Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 21/44] net: move netmask_to_prefix into header Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 22/44] stringlist: implement string_list_empty Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 23/44] optee: add revision info to tee devinfo output Ahmad Fatoum
2025-08-12 9:35 ` Sascha Hauer
2025-08-12 9:44 ` Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 24/44] tee: enable structured I/O in devinfo handler Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 25/44] mtd: add devices to new mtd class Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 26/44] nvmem: add devices to new nvmem class Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 27/44] nvmem: export functions to query NVMEM size Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 28/44] video: add devices to new fb class Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 29/44] security: blobgen: add easy way to check for existent providers Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 30/44] pmdomain: add easy way to check for provider support Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 31/44] bbu: add easy way to check for existent providers Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 32/44] firmware: " Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 33/44] rtc: export rtc_class in header Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 34/44] driver: featctrl: export of_feature_controllers Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 35/44] net: dsa: export dsa_switch_list Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 36/44] usb: export usb_host_list Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 37/44] pstore: export pstore_is_ready Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 38/44] pinctrl: export pinctrl_list Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 39/44] clk: implement clk_have_nonfixed_providers Ahmad Fatoum
2025-08-13 5:38 ` Sascha Hauer
2025-08-11 12:28 ` [PATCH 40/44] driver: bus: export get_bus_by_name Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 41/44] fimware: arm_scmi: export scmi_list Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 42/44] block: define BLK_TYPE_COUNT as last enum blk_type value Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 43/44] commands: introduce bfetch command Ahmad Fatoum
2025-08-12 10:39 ` Sascha Hauer
2025-08-12 11:09 ` Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 44/44] configs: enable bfetch in some popular defconfigs Ahmad Fatoum
2025-08-12 10:29 ` [PATCH 00/44] commands: add bfetch/buds of command redirection Sascha Hauer
2025-08-12 11:23 ` Ahmad Fatoum
2025-08-13 5:48 ` (subset) " Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250811122824.1667791-15-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox