[PATCH master] drivers: fix buggy comparisons of casted device_get_match_data to zero

Ahmad Fatoum a.fatoum at barebox.org
Tue Jul 15 13:19:08 PDT 2025


device_get_match_data returns NULL when no match data is available,
which a cast to uintptr_t turns into a zero.

Most drivers either put valid pointers into the match data or they
reserve a literal value of zero to be "unknown".

Three drivers don't do that though and use 0 as valid value for the
match data and thus the check against zero breaks probing drivers with
the corresponding match data.

As device_get_match_data() would only fail anyway when manually
allocating platform devices that match by name or when adding new matches
without match data, it's perfectly fine to just skip the check and
assume the match data to be zero in that case to fix the breakage.

Fixes: 20d87123a638 ("treewide: replace dev_get_drvdata with device_get_match_data")
Reported-by: Renaud Barbier <Renaud.Barbier at ametek.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 drivers/eeprom/at24.c    | 2 --
 drivers/net/fsl-fman.c   | 2 --
 drivers/rtc/rtc-ds1307.c | 2 --
 3 files changed, 6 deletions(-)

diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c
index 3054709ec055..ffd3376a1566 100644
--- a/drivers/eeprom/at24.c
+++ b/drivers/eeprom/at24.c
@@ -381,8 +381,6 @@ static int at24_probe(struct device *dev)
 		u32 page_size;
 
 		magic = (uintptr_t)device_get_match_data(dev);
-		if (!magic)
-			return -ENODEV;
 
 		chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN));
 		magic >>= AT24_SIZE_BYTELEN;
diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
index 84e7f2033037..bde054d7513f 100644
--- a/drivers/net/fsl-fman.c
+++ b/drivers/net/fsl-fman.c
@@ -1091,8 +1091,6 @@ static int fsl_fman_port_probe(struct device *dev)
 	dev_dbg(dev, "probe\n");
 
 	type = (uintptr_t)device_get_match_data(dev);
-	if (!type)
-		return -ENODEV;
 
 	iores = dev_request_mem_resource(dev, 0);
 	if (IS_ERR(iores))
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 86b0709dc217..0fee67961a9a 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -291,8 +291,6 @@ static int ds1307_probe(struct device *dev)
 	const struct device_node *np = dev->of_node;
 
 	driver_data = (uintptr_t)device_get_match_data(dev);
-	if (!driver_data)
-		return -ENODEV;
 
 	ds1307 = xzalloc(sizeof(struct ds1307));
 
-- 
2.39.5




More information about the barebox mailing list