From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 06/44] driver: initialize device parameters as part of bobject
Date: Mon, 11 Aug 2025 14:27:46 +0200 [thread overview]
Message-ID: <20250811122824.1667791-7-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250811122824.1667791-1-a.fatoum@barebox.org>
By moving the parameters to the bobjects, we pave the way for building
an OOP system that doesn't require each object to be a device.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/base/driver.c | 5 +++--
include/bobject.h | 20 ++++++++++++++++++++
include/device.h | 8 ++------
include/param.h | 4 ----
lib/bobject.c | 38 ++++++++++++++++++++++++++++++++++++++
lib/parameter.c | 17 ++---------------
6 files changed, 65 insertions(+), 27 deletions(-)
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 4f3ae4909e07..61118385f1df 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -262,11 +262,12 @@ int register_device(struct device *new_device)
list_add_tail(&new_device->list, &device_list);
INIT_LIST_HEAD(&new_device->children);
INIT_LIST_HEAD(&new_device->cdevs);
- INIT_LIST_HEAD(&new_device->parameters);
INIT_LIST_HEAD(&new_device->active);
INIT_LIST_HEAD(&new_device->bus_list);
INIT_LIST_HEAD(&new_device->class_list);
+ bobject_init(&new_device->bobject);
+
if (new_device->bus) {
if (!new_device->parent)
new_device->parent = &new_device->bus->dev;
@@ -295,7 +296,7 @@ int unregister_device(struct device *old_dev)
dev_dbg(old_dev, "unregister\n");
- dev_remove_parameters(old_dev);
+ bobject_del(&old_dev->bobject);
if (old_dev->driver)
device_remove(old_dev);
diff --git a/include/bobject.h b/include/bobject.h
index 783ab64569dc..b159ac875f0c 100644
--- a/include/bobject.h
+++ b/include/bobject.h
@@ -3,14 +3,17 @@
#ifndef __BOBJECT_H_
#define __BOBJECT_H_
+#include <linux/list.h>
#include <linux/compiler.h>
/**
* struct bobject - barebox object
* @name: name of object (must be first member)
+ * @parameters: list of struct param_d parameters
*/
struct bobject {
char *name;
+ struct list_head parameters;
};
struct device;
@@ -23,4 +26,21 @@ typedef union {
__printf(2, 3) int bobject_set_name(bobject_t bobj, const char *name, ...);
+static inline void bobject_init(struct bobject *bobj)
+{
+ /* We have code that iterates over parameters unconditionally,
+ * so initialize it even if !IS_ENABLED(CONFIG_PARAMETER)
+ */
+ INIT_LIST_HEAD(&bobj->parameters);
+}
+
+struct bobject *bobject_alloc(const char *name);
+void bobject_free(struct bobject *bobj);
+
+#ifdef CONFIG_PARAMETER
+void bobject_del(struct bobject *bobj);
+#else
+static inline void bobject_del(struct bobject *bobj) { }
+#endif
+
#endif
diff --git a/include/device.h b/include/device.h
index 1158ec59b5e8..5bb5a28619a2 100644
--- a/include/device.h
+++ b/include/device.h
@@ -55,8 +55,6 @@ struct of_device_id;
* If parent is NULL, the device is a top-level device.
* @pm_domain: Attached power domain.
* @bus: Type of bus device is on.
- * @parameters: The parameters for this device. This is used to carry information
- * of board specific data from the board code to the device driver
* @dma_mask: DMA mask.
* @dma_offset: DMA offset.
* @detect: For devices which take longer to probe, this is called when the driver
@@ -101,8 +99,6 @@ struct device {
struct bus_type *bus;
- struct list_head parameters;
-
struct list_head cdevs;
struct list_head class_list;
@@ -163,9 +159,9 @@ extern struct list_head class_list;
#define class_for_each(class) list_for_each_entry((class), &class_list, list)
#define dev_for_each_param(dev, param) \
- list_for_each_entry((param), &(dev)->parameters, list)
+ list_for_each_entry((param), &(dev)->bobject.parameters, list)
#define dev_for_each_param_safe(dev, param, tmp) \
- list_for_each_entry_safe((param), (tmp), &(dev)->parameters, list)
+ list_for_each_entry_safe((param), (tmp), &(dev)->bobject.parameters, list)
struct device_alias {
struct device *dev;
diff --git a/include/param.h b/include/param.h
index 856f7a52e1b8..bb90d0240828 100644
--- a/include/param.h
+++ b/include/param.h
@@ -107,8 +107,6 @@ struct param_d *dev_add_param_fixed(struct device *dev, const char *name,
void param_remove(struct param_d *p);
-void dev_remove_parameters(struct device *dev);
-
int dev_param_set_generic(struct device *dev, struct param_d *p,
const char *val);
@@ -234,8 +232,6 @@ static inline struct param_d *dev_add_param_fixed(struct device *dev,
static inline void param_remove(struct param_d *p) {}
-static inline void dev_remove_parameters(struct device *dev) {}
-
static inline int dev_param_set_generic(struct device *dev, struct param_d *p,
const char *val)
{
diff --git a/lib/bobject.c b/lib/bobject.c
index a770993b90bd..eb140b90a2d5 100644
--- a/lib/bobject.c
+++ b/lib/bobject.c
@@ -34,3 +34,41 @@ int bobject_set_name(bobject_t bobj, const char *fmt, ...)
return WARN_ON(err < 0) ? err : 0;
}
EXPORT_SYMBOL_GPL(bobject_set_name);
+
+struct bobject *bobject_alloc(const char *name)
+{
+ struct bobject *bobj = xzalloc(sizeof(*bobj));
+
+ bobject_init(bobj);
+ bobject_set_name(bobj, "%s", name);
+
+ return bobj;
+}
+EXPORT_SYMBOL_GPL(bobject_alloc);
+
+void bobject_free(struct bobject *bobj)
+{
+ if (!bobj)
+ return;
+
+ free(bobj->name);
+ bobject_del(bobj);
+ free(bobj);
+}
+EXPORT_SYMBOL_GPL(bobject_free);
+
+#ifdef CONFIG_PARAMETER
+/**
+ * bobject_remove_parameters - remove all parameters from a bobject and free their
+ * memory
+ * @param bobject The barebox object
+ */
+void bobject_del(struct bobject *bobj)
+{
+ struct param_d *p, *n;
+
+ list_for_each_entry_safe(p, n, &bobj->parameters, list)
+ param_remove(p);
+}
+EXPORT_SYMBOL(bobject_del);
+#endif
diff --git a/lib/parameter.c b/lib/parameter.c
index c550de050db0..7f89ac53e0d2 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -53,7 +53,7 @@ struct param_d *get_param_by_name(struct device *dev, const char *name)
{
struct param_d *p;
- list_for_each_entry(p, &dev->parameters, list) {
+ list_for_each_entry(p, &dev->bobject.parameters, list) {
if (!strcmp(p->name, name))
return p;
}
@@ -168,7 +168,7 @@ static int __dev_add_param(struct param_d *param, struct device *dev,
param->flags = flags;
param->dev = dev;
- list_add_sort(¶m->list, &dev->parameters, compare);
+ list_add_sort(¶m->list, &dev->bobject.parameters, compare);
dev_param_init_from_nv(dev, name);
@@ -1017,19 +1017,6 @@ void param_remove(struct param_d *p)
free(p);
}
-/**
- * dev_remove_parameters - remove all parameters from a device and free their
- * memory
- * @param dev The device
- */
-void dev_remove_parameters(struct device *dev)
-{
- struct param_d *p, *n;
-
- dev_for_each_param_safe(dev, p, n)
- param_remove(p);
-}
-
/** @page dev_params Device parameters
@section params_devices Devices can have several parameters.
--
2.39.5
next prev parent reply other threads:[~2025-08-11 12:29 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 ` Ahmad Fatoum [this message]
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 ` [PATCH 14/44] param: make bobject_add_param_fixed variadic Ahmad Fatoum
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-7-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