mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] drivers: base: Check all compatible strings for modalias match
@ 2021-05-31 14:54 Trent Piepho
  2021-06-16  8:26 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Trent Piepho @ 2021-05-31 14:54 UTC (permalink / raw)
  To: barebox; +Cc: Trent Piepho

When attempting a modalias match in device_match_of_modalias(), only the
first string in the compatible property, which is a list of strings, was
used.

A modalias (which is a bit of a misnomer in Barebox) match is used when
a driver does not have an of_compatible match table, e.g. the at24
driver.  The compatible string after the comma is matched against the
driver's id table.

Extend modalias match to try all strings in from the OF node's
compatible property.  This will cause a compatible like
"rohm,br24g04-3", "atmel,24c04" to match against the "24c04" ID in the
at24 driver.  Or "isil,isl12057", "dallas,ds1337" will match the ds1307
driver's table, which doesn't know about isl12057 in Barebox.

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
---
 drivers/base/bus.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 1038d20a1..aac5b69f3 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -75,7 +75,7 @@ int device_match_of_modalias(struct device_d *dev, struct driver_d *drv)
 {
 	const struct platform_device_id *id = drv->id_table;
 	const char *of_modalias = NULL, *p;
-	int cplen;
+	const struct property *prop;
 	const char *compat;
 
 	if (!device_match(dev, drv))
@@ -84,25 +84,16 @@ int device_match_of_modalias(struct device_d *dev, struct driver_d *drv)
 	if (!id || !IS_ENABLED(CONFIG_OFDEVICE) || !dev->device_node)
 		return -1;
 
-	compat = of_get_property(dev->device_node, "compatible", &cplen);
-	if (!compat)
-		return -1;
-
-	p = strchr(compat, ',');
-	of_modalias = p ? p + 1 : compat;
-
-	while (id->name) {
-		if (!strcmp(id->name, dev->name)) {
-			dev->id_entry = id;
-			return 0;
-		}
+	of_property_for_each_string(dev->device_node, "compatible", prop, compat) {
+		p = strchr(compat, ',');
+		of_modalias = p ? p + 1 : compat;
 
-		if (of_modalias && !strcmp(id->name, of_modalias)) {
-			dev->id_entry = id;
-			return 0;
+		for (id = drv->id_table; id->name; id++) {
+			if (!strcmp(id->name, dev->name) || !strcmp(id->name, of_modalias)) {
+				dev->id_entry = id;
+				return 0;
+			}
 		}
-
-		id++;
 	}
 
 	return -1;
-- 
2.26.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers: base: Check all compatible strings for modalias match
  2021-05-31 14:54 [PATCH] drivers: base: Check all compatible strings for modalias match Trent Piepho
@ 2021-06-16  8:26 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2021-06-16  8:26 UTC (permalink / raw)
  To: Trent Piepho; +Cc: barebox

On Mon, May 31, 2021 at 07:54:14AM -0700, Trent Piepho wrote:
> When attempting a modalias match in device_match_of_modalias(), only the
> first string in the compatible property, which is a list of strings, was
> used.
> 
> A modalias (which is a bit of a misnomer in Barebox) match is used when
> a driver does not have an of_compatible match table, e.g. the at24
> driver.  The compatible string after the comma is matched against the
> driver's id table.
> 
> Extend modalias match to try all strings in from the OF node's
> compatible property.  This will cause a compatible like
> "rohm,br24g04-3", "atmel,24c04" to match against the "24c04" ID in the
> at24 driver.  Or "isil,isl12057", "dallas,ds1337" will match the ds1307
> driver's table, which doesn't know about isl12057 in Barebox.
> 
> Signed-off-by: Trent Piepho <tpiepho@gmail.com>
> ---
>  drivers/base/bus.c | 27 +++++++++------------------
>  1 file changed, 9 insertions(+), 18 deletions(-)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-16  8:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-31 14:54 [PATCH] drivers: base: Check all compatible strings for modalias match Trent Piepho
2021-06-16  8:26 ` Sascha Hauer

mail archive of the barebox mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lore.barebox.org/barebox/0 barebox/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 barebox barebox/ https://lore.barebox.org/barebox \
		barebox@lists.infradead.org
	public-inbox-index barebox

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git