[PATCH 3/7] firmware: arm_scmi: bus: iterate the id_table

Peng Fan (OSS) posted 7 patches 2 years ago
There is a newer version of this series
[PATCH 3/7] firmware: arm_scmi: bus: iterate the id_table
Posted by Peng Fan (OSS) 2 years ago
From: Peng Fan <peng.fan@nxp.com>

There maybe more entries in driver->id_table, just like platform
driver of_match_table. So iterate the id_table, not only use the 1st
entry.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/firmware/arm_scmi/bus.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index c999edd18cd3..aeb7da841b9d 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -282,14 +282,18 @@ EXPORT_SYMBOL_GPL(scmi_bus_type);
 int scmi_driver_register(struct scmi_driver *driver, struct module *owner,
 			 const char *mod_name)
 {
+	const struct scmi_device_id *id_table = driver->id_table;
 	int retval;
 
 	if (!driver->probe)
 		return -EINVAL;
 
-	retval = scmi_protocol_device_request(driver->id_table);
-	if (retval)
-		return retval;
+	while (id_table->name) {
+		retval = scmi_protocol_device_request(id_table);
+		if (retval)
+			return retval;
+		id_table++;
+	}
 
 	driver->driver.bus = &scmi_bus_type;
 	driver->driver.name = driver->name;

-- 
2.37.1
Re: [PATCH 3/7] firmware: arm_scmi: bus: iterate the id_table
Posted by Cristian Marussi 1 year, 12 months ago
On Fri, Dec 15, 2023 at 07:56:31PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> There maybe more entries in driver->id_table, just like platform
> driver of_match_table. So iterate the id_table, not only use the 1st
> entry.
> 

I understand the need, but you dont consider the unbind/unload part.

Moreover since I needed a similar mechanism for testing (multiple
protocols in a single driver), I posted yesterday a patch that does this
same thing that since I was using since ages but never posted (and it
takes care of unload/unbind too.).

https://lore.kernel.org/all/20231221151129.325749-1-cristian.marussi@arm.com/

Please drop this patch and use the above (that soon should be in -next)

Thanks,
Cristian