From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Renaud Barbier <Renaud.Barbier@ametek.com>,
Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH master] drivers: fix buggy comparisons of casted device_get_match_data to zero
Date: Tue, 15 Jul 2025 22:19:08 +0200 [thread overview]
Message-ID: <20250715201908.2515578-1-a.fatoum@barebox.org> (raw)
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
reply other threads:[~2025-07-15 20:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20250715201908.2515578-1-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=Renaud.Barbier@ametek.com \
--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