From: "Rob Herring (Arm)" <robh@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] driver core: Don't match device with NULL of_node/fwnode
Date: Tue, 3 Dec 2024 18:02:59 -0600 [thread overview]
Message-ID: <20241204000259.2699841-1-robh@kernel.org> (raw)
It recently came up that of_find_device_by_node() will match a device
with a NULL of_node pointer. This is not desired behavior. The returned
struct device is also not deterministic.
Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
---
It would be a bit more efficient to check this up front before we
iterate thru devices, but there's a number of users of these functions
and this isn't really a hot path.
I think at least device_match_acpi_dev() and device_match_acpi_handle()
should also be fixed, but am not sure about the ACPI side.
---
drivers/base/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 94865c9d8adc..87d50c5f710f 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -5246,13 +5246,13 @@ EXPORT_SYMBOL_GPL(device_match_name);
int device_match_of_node(struct device *dev, const void *np)
{
- return dev->of_node == np;
+ return np && (dev->of_node == np);
}
EXPORT_SYMBOL_GPL(device_match_of_node);
int device_match_fwnode(struct device *dev, const void *fwnode)
{
- return dev_fwnode(dev) == fwnode;
+ return fwnode && (dev_fwnode(dev) == fwnode);
}
EXPORT_SYMBOL_GPL(device_match_fwnode);
--
2.45.2
next reply other threads:[~2024-12-04 0:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-04 0:02 Rob Herring (Arm) [this message]
2024-12-04 9:37 ` [PATCH] driver core: Don't match device with NULL of_node/fwnode Greg Kroah-Hartman
2024-12-09 23:47 ` Brian Norris
2024-12-10 12:33 ` Rob Herring
2024-12-10 19:17 ` Brian Norris
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=20241204000259.2699841-1-robh@kernel.org \
--to=robh@kernel.org \
--cc=bhelgaas@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.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