* [PATCH master] drivers: fix buggy comparisons of casted device_get_match_data to zero
@ 2025-07-15 20:19 Ahmad Fatoum
2025-08-05 8:19 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-07-15 20:19 UTC (permalink / raw)
To: barebox; +Cc: Renaud Barbier, Ahmad Fatoum
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@ametek.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH master] drivers: fix buggy comparisons of casted device_get_match_data to zero
2025-07-15 20:19 [PATCH master] drivers: fix buggy comparisons of casted device_get_match_data to zero Ahmad Fatoum
@ 2025-08-05 8:19 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2025-08-05 8:19 UTC (permalink / raw)
To: barebox, Ahmad Fatoum; +Cc: Renaud Barbier
On Tue, 15 Jul 2025 22:19:08 +0200, Ahmad Fatoum wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] drivers: fix buggy comparisons of casted device_get_match_data to zero
https://git.pengutronix.de/cgit/barebox/commit/?id=964a91e4427f (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-05 9:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-15 20:19 [PATCH master] drivers: fix buggy comparisons of casted device_get_match_data to zero Ahmad Fatoum
2025-08-05 8:19 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox