From: Brian Norris <briannorris@chromium.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Maxime Ripard <mripard@kernel.org>,
linux-acpi@vger.kernel.org, Rae Moar <rmoar@google.com>,
Rob Herring <robh@kernel.org>, David Gow <davidgow@google.com>,
linux-kselftest@vger.kernel.org,
"Rafael J. Wysocki" <rafael@kernel.org>,
kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org,
Brian Norris <briannorris@chromium.org>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Subject: [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc
Date: Mon, 16 Dec 2024 12:11:42 -0800 [thread overview]
Message-ID: <20241216201148.535115-2-briannorris@chromium.org> (raw)
In-Reply-To: <20241216201148.535115-1-briannorris@chromium.org>
of_find_device_by_node(), bus_find_device_by_of_node(),
bus_find_device_by_fwnode(), ..., all produce arbitrary results when
provided with a NULL of_node, fwnode, ACPI handle, etc. This is
counterintuitive, and the source of a few bugs, such as the one fixed by
commit 5c8418cf4025 ("PCI/pwrctrl: Unregister platform device only if
one actually exists").
It's hard to imagine a good reason that these device_match_*() APIs
should return 'true' for a NULL argument. Augment these to return 0
(false).
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Brian Norris <briannorris@chromium.org>
---
Changes in v3:
* Add Rafael's Acked-by
Changes in v2:
* Add Rob's Reviewed-by
drivers/base/core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 94865c9d8adc..2b7b13fc36d7 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);
@@ -5264,13 +5264,13 @@ EXPORT_SYMBOL_GPL(device_match_devt);
int device_match_acpi_dev(struct device *dev, const void *adev)
{
- return ACPI_COMPANION(dev) == adev;
+ return adev && ACPI_COMPANION(dev) == adev;
}
EXPORT_SYMBOL(device_match_acpi_dev);
int device_match_acpi_handle(struct device *dev, const void *handle)
{
- return ACPI_HANDLE(dev) == handle;
+ return handle && ACPI_HANDLE(dev) == handle;
}
EXPORT_SYMBOL(device_match_acpi_handle);
--
2.47.1.613.gc27f4b7a9f-goog
next prev parent reply other threads:[~2024-12-16 20:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-16 20:11 [PATCH v3 0/3] drivers: base: Don't match device with NULL of_node/fwnode/etc + tests Brian Norris
2024-12-16 20:11 ` Brian Norris [this message]
2024-12-19 5:45 ` [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc David Gow
2024-12-20 17:33 ` Shuah Khan
2024-12-20 17:44 ` Greg Kroah-Hartman
2024-12-16 20:11 ` [PATCH v3 2/3] drivers: base: test: Enable device model tests with KUNIT_ALL_TESTS Brian Norris
2024-12-17 7:41 ` Maxime Ripard
2024-12-19 5:45 ` David Gow
2024-12-16 20:11 ` [PATCH v3 3/3] drivers: base: test: Add ...find_device_by...(... NULL) tests Brian Norris
2024-12-19 5:45 ` David Gow
2024-12-20 17:34 ` Shuah Khan
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=20241216201148.535115-2-briannorris@chromium.org \
--to=briannorris@chromium.org \
--cc=davidgow@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mripard@kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=rafael@kernel.org \
--cc=rmoar@google.com \
--cc=robh@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
all inboxes | Powered by JetHome®