* [PATCH v3 0/3] drivers: base: Don't match device with NULL of_node/fwnode/etc + tests
@ 2024-12-16 20:11 Brian Norris
2024-12-16 20:11 ` [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc Brian Norris
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Brian Norris @ 2024-12-16 20:11 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Maxime Ripard, linux-acpi, Rae Moar, Rob Herring, David Gow,
linux-kselftest, Rafael J. Wysocki, kunit-dev, linux-kernel,
Brian Norris
This series:
1. makes the behavior of_find_device_by_node(),
bus_find_device_by_of_node(), bus_find_device_by_fwnode(), etc., more
consistent when provided with a NULL node/handle;
2. adds kunit tests to validate the new NULL-argument behavior; and
3. makes some related improvements and refactoring for the drivers/base/
kunit tests.
This series aims to prevent problems like the ones resolved in commit
5c8418cf4025 ("PCI/pwrctrl: Unregister platform device only if one
actually exists").
Changes in v3:
* Fix potential leak in test error case
Changes in v2:
* CC LKML (oops!)
* Keep "devm" and "match" tests in separate suites
Brian Norris (3):
drivers: base: Don't match devices with NULL of_node/fwnode/etc
drivers: base: test: Enable device model tests with KUNIT_ALL_TESTS
drivers: base: test: Add ...find_device_by...(... NULL) tests
drivers/base/core.c | 8 ++---
drivers/base/test/Kconfig | 1 +
drivers/base/test/platform-device-test.c | 41 +++++++++++++++++++++++-
3 files changed, 45 insertions(+), 5 deletions(-)
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc 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 2024-12-19 5:45 ` David Gow 2024-12-16 20:11 ` [PATCH v3 2/3] drivers: base: test: Enable device model tests with KUNIT_ALL_TESTS Brian Norris 2024-12-16 20:11 ` [PATCH v3 3/3] drivers: base: test: Add ...find_device_by...(... NULL) tests Brian Norris 2 siblings, 1 reply; 11+ messages in thread From: Brian Norris @ 2024-12-16 20:11 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Maxime Ripard, linux-acpi, Rae Moar, Rob Herring, David Gow, linux-kselftest, Rafael J. Wysocki, kunit-dev, linux-kernel, Brian Norris, Rafael J. Wysocki 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 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc 2024-12-16 20:11 ` [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc Brian Norris @ 2024-12-19 5:45 ` David Gow 2024-12-20 17:33 ` Shuah Khan 0 siblings, 1 reply; 11+ messages in thread From: David Gow @ 2024-12-19 5:45 UTC (permalink / raw) To: Brian Norris Cc: Greg Kroah-Hartman, Maxime Ripard, linux-acpi, Rae Moar, Rob Herring, linux-kselftest, Rafael J. Wysocki, kunit-dev, linux-kernel, Rafael J. Wysocki [-- Attachment #1: Type: text/plain, Size: 2319 bytes --] On Tue, 17 Dec 2024 at 04:12, Brian Norris <briannorris@chromium.org> wrote: > > 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> > --- Seems sensible enough to me. Acked-by: David Gow <davidgow@google.com> I assume this series (including the KUnit test changes) will go in via Greg. Cheers, -- David > > 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 > [-- Attachment #2: S/MIME Cryptographic Signature --] [-- Type: application/pkcs7-signature, Size: 5294 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc 2024-12-19 5:45 ` David Gow @ 2024-12-20 17:33 ` Shuah Khan 2024-12-20 17:44 ` Greg Kroah-Hartman 0 siblings, 1 reply; 11+ messages in thread From: Shuah Khan @ 2024-12-20 17:33 UTC (permalink / raw) To: David Gow, Brian Norris Cc: Greg Kroah-Hartman, Maxime Ripard, linux-acpi, Rae Moar, Rob Herring, linux-kselftest, Rafael J. Wysocki, kunit-dev, linux-kernel, Rafael J. Wysocki, Shuah Khan On 12/18/24 22:45, David Gow wrote: > On Tue, 17 Dec 2024 at 04:12, Brian Norris <briannorris@chromium.org> wrote: >> >> 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> >> --- > > Seems sensible enough to me. > > Acked-by: David Gow <davidgow@google.com> > > I assume this series (including the KUnit test changes) will go in via Greg. > Works for me. Acked-by: Shuah Khan <skhan@linuxfoundation.org> thanks, -- Shuah ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc 2024-12-20 17:33 ` Shuah Khan @ 2024-12-20 17:44 ` Greg Kroah-Hartman 0 siblings, 0 replies; 11+ messages in thread From: Greg Kroah-Hartman @ 2024-12-20 17:44 UTC (permalink / raw) To: Shuah Khan Cc: David Gow, Brian Norris, Maxime Ripard, linux-acpi, Rae Moar, Rob Herring, linux-kselftest, Rafael J. Wysocki, kunit-dev, linux-kernel, Rafael J. Wysocki On Fri, Dec 20, 2024 at 10:33:51AM -0700, Shuah Khan wrote: > On 12/18/24 22:45, David Gow wrote: > > On Tue, 17 Dec 2024 at 04:12, Brian Norris <briannorris@chromium.org> wrote: > > > > > > 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> > > > --- > > > > Seems sensible enough to me. > > > > Acked-by: David Gow <davidgow@google.com> > > > > I assume this series (including the KUnit test changes) will go in via Greg. > > > > Works for me. > > Acked-by: Shuah Khan <skhan@linuxfoundation.org> Thanks, I'll take these in a few days. greg k-h ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 2/3] drivers: base: test: Enable device model tests with KUNIT_ALL_TESTS 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 ` [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc Brian Norris @ 2024-12-16 20:11 ` 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 2 siblings, 2 replies; 11+ messages in thread From: Brian Norris @ 2024-12-16 20:11 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Maxime Ripard, linux-acpi, Rae Moar, Rob Herring, David Gow, linux-kselftest, Rafael J. Wysocki, kunit-dev, linux-kernel, Brian Norris Per commit bebe94b53eb7 ("drivers: base: default KUNIT_* fragments to KUNIT_ALL_TESTS"), it seems like we should default to KUNIT_ALL_TESTS. This enables these platform_device tests for common configurations, such as with: ./tools/testing/kunit/kunit.py run Signed-off-by: Brian Norris <briannorris@chromium.org> --- (no changes since v1) drivers/base/test/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/base/test/Kconfig b/drivers/base/test/Kconfig index 5c7fac80611c..2756870615cc 100644 --- a/drivers/base/test/Kconfig +++ b/drivers/base/test/Kconfig @@ -12,6 +12,7 @@ config TEST_ASYNC_DRIVER_PROBE config DM_KUNIT_TEST tristate "KUnit Tests for the device model" if !KUNIT_ALL_TESTS depends on KUNIT + default KUNIT_ALL_TESTS config DRIVER_PE_KUNIT_TEST tristate "KUnit Tests for property entry API" if !KUNIT_ALL_TESTS -- 2.47.1.613.gc27f4b7a9f-goog ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/3] drivers: base: test: Enable device model tests with KUNIT_ALL_TESTS 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 1 sibling, 0 replies; 11+ messages in thread From: Maxime Ripard @ 2024-12-17 7:41 UTC (permalink / raw) To: Brian Norris Cc: kunit-dev, linux-acpi, linux-kernel, linux-kselftest, David Gow, Greg Kroah-Hartman, Maxime Ripard, Rae Moar, "Rafael J. Wysocki", Rob Herring On Mon, 16 Dec 2024 12:11:43 -0800, Brian Norris wrote: > Per commit bebe94b53eb7 ("drivers: base: default KUNIT_* fragments to > KUNIT_ALL_TESTS"), it seems like we should default to KUNIT_ALL_TESTS. > > This enables these platform_device tests for common configurations, such > as with: > > [ ... ] Reviewed-by: Maxime Ripard <mripard@kernel.org> Thanks! Maxime ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/3] drivers: base: test: Enable device model tests with KUNIT_ALL_TESTS 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 1 sibling, 0 replies; 11+ messages in thread From: David Gow @ 2024-12-19 5:45 UTC (permalink / raw) To: Brian Norris Cc: Greg Kroah-Hartman, Maxime Ripard, linux-acpi, Rae Moar, Rob Herring, linux-kselftest, Rafael J. Wysocki, kunit-dev, linux-kernel [-- Attachment #1: Type: text/plain, Size: 1128 bytes --] On Tue, 17 Dec 2024 at 04:12, Brian Norris <briannorris@chromium.org> wrote: > > Per commit bebe94b53eb7 ("drivers: base: default KUNIT_* fragments to > KUNIT_ALL_TESTS"), it seems like we should default to KUNIT_ALL_TESTS. > > This enables these platform_device tests for common configurations, such > as with: > ./tools/testing/kunit/kunit.py run > > Signed-off-by: Brian Norris <briannorris@chromium.org> > --- Excellent! Reviewed-by: David Gow <davidgow@google.com> Cheers, -- David > > (no changes since v1) > > drivers/base/test/Kconfig | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/base/test/Kconfig b/drivers/base/test/Kconfig > index 5c7fac80611c..2756870615cc 100644 > --- a/drivers/base/test/Kconfig > +++ b/drivers/base/test/Kconfig > @@ -12,6 +12,7 @@ config TEST_ASYNC_DRIVER_PROBE > config DM_KUNIT_TEST > tristate "KUnit Tests for the device model" if !KUNIT_ALL_TESTS > depends on KUNIT > + default KUNIT_ALL_TESTS > > config DRIVER_PE_KUNIT_TEST > tristate "KUnit Tests for property entry API" if !KUNIT_ALL_TESTS > -- > 2.47.1.613.gc27f4b7a9f-goog > [-- Attachment #2: S/MIME Cryptographic Signature --] [-- Type: application/pkcs7-signature, Size: 5294 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 3/3] drivers: base: test: Add ...find_device_by...(... NULL) tests 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 ` [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc Brian Norris 2024-12-16 20:11 ` [PATCH v3 2/3] drivers: base: test: Enable device model tests with KUNIT_ALL_TESTS Brian Norris @ 2024-12-16 20:11 ` Brian Norris 2024-12-19 5:45 ` David Gow 2 siblings, 1 reply; 11+ messages in thread From: Brian Norris @ 2024-12-16 20:11 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Maxime Ripard, linux-acpi, Rae Moar, Rob Herring, David Gow, linux-kselftest, Rafael J. Wysocki, kunit-dev, linux-kernel, Brian Norris We recently updated these device_match*() (and therefore, various *find_device_by*()) functions to return a consistent 'false' value when trying to match a NULL handle. Add tests for this. This provides regression-testing coverage for the sorts of bugs that underly commit 5c8418cf4025 ("PCI/pwrctrl: Unregister platform device only if one actually exists"). Reviewed-by: Maxime Ripard <mripard@kernel.org> Signed-off-by: Brian Norris <briannorris@chromium.org> --- Changes in v3: * Fix potential leak in test error case * Add Maxime's Reviewed-by Changes in v2: * Keep "devm" and "match" tests in separate suites drivers/base/test/platform-device-test.c | 41 +++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/base/test/platform-device-test.c b/drivers/base/test/platform-device-test.c index ea05b8785743..6355a2231b74 100644 --- a/drivers/base/test/platform-device-test.c +++ b/drivers/base/test/platform-device-test.c @@ -1,8 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 +#include <kunit/platform_device.h> #include <kunit/resource.h> #include <linux/device.h> +#include <linux/device/bus.h> +#include <linux/of_platform.h> #include <linux/platform_device.h> #define DEVICE_NAME "test" @@ -217,7 +220,43 @@ static struct kunit_suite platform_device_devm_test_suite = { .test_cases = platform_device_devm_tests, }; -kunit_test_suite(platform_device_devm_test_suite); +static void platform_device_find_by_null_test(struct kunit *test) +{ + struct platform_device *pdev; + int ret; + + pdev = kunit_platform_device_alloc(test, DEVICE_NAME, PLATFORM_DEVID_NONE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev); + + ret = kunit_platform_device_add(test, pdev); + KUNIT_ASSERT_EQ(test, ret, 0); + + KUNIT_EXPECT_PTR_EQ(test, of_find_device_by_node(NULL), NULL); + + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_of_node(&platform_bus_type, NULL), NULL); + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_fwnode(&platform_bus_type, NULL), NULL); + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_acpi_dev(&platform_bus_type, NULL), NULL); + + KUNIT_EXPECT_FALSE(test, device_match_of_node(&pdev->dev, NULL)); + KUNIT_EXPECT_FALSE(test, device_match_fwnode(&pdev->dev, NULL)); + KUNIT_EXPECT_FALSE(test, device_match_acpi_dev(&pdev->dev, NULL)); + KUNIT_EXPECT_FALSE(test, device_match_acpi_handle(&pdev->dev, NULL)); +} + +static struct kunit_case platform_device_match_tests[] = { + KUNIT_CASE(platform_device_find_by_null_test), + {} +}; + +static struct kunit_suite platform_device_match_test_suite = { + .name = "platform-device-match", + .test_cases = platform_device_match_tests, +}; + +kunit_test_suites( + &platform_device_devm_test_suite, + &platform_device_match_test_suite, +); MODULE_DESCRIPTION("Test module for platform devices"); MODULE_AUTHOR("Maxime Ripard <mripard@kernel.org>"); -- 2.47.1.613.gc27f4b7a9f-goog ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 3/3] drivers: base: test: Add ...find_device_by...(... NULL) tests 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 0 siblings, 1 reply; 11+ messages in thread From: David Gow @ 2024-12-19 5:45 UTC (permalink / raw) To: Brian Norris Cc: Greg Kroah-Hartman, Maxime Ripard, linux-acpi, Rae Moar, Rob Herring, linux-kselftest, Rafael J. Wysocki, kunit-dev, linux-kernel [-- Attachment #1: Type: text/plain, Size: 3339 bytes --] On Tue, 17 Dec 2024 at 04:12, Brian Norris <briannorris@chromium.org> wrote: > > We recently updated these device_match*() (and therefore, various > *find_device_by*()) functions to return a consistent 'false' value when > trying to match a NULL handle. Add tests for this. > > This provides regression-testing coverage for the sorts of bugs that > underly commit 5c8418cf4025 ("PCI/pwrctrl: Unregister platform device > only if one actually exists"). > > Reviewed-by: Maxime Ripard <mripard@kernel.org> > Signed-off-by: Brian Norris <briannorris@chromium.org> > --- > Thanks. This looks good to me. Reviewed-by: David Gow <davidgow@google.com> -- David > Changes in v3: > * Fix potential leak in test error case > * Add Maxime's Reviewed-by > > Changes in v2: > * Keep "devm" and "match" tests in separate suites > > drivers/base/test/platform-device-test.c | 41 +++++++++++++++++++++++- > 1 file changed, 40 insertions(+), 1 deletion(-) > > diff --git a/drivers/base/test/platform-device-test.c b/drivers/base/test/platform-device-test.c > index ea05b8785743..6355a2231b74 100644 > --- a/drivers/base/test/platform-device-test.c > +++ b/drivers/base/test/platform-device-test.c > @@ -1,8 +1,11 @@ > // SPDX-License-Identifier: GPL-2.0 > > +#include <kunit/platform_device.h> > #include <kunit/resource.h> > > #include <linux/device.h> > +#include <linux/device/bus.h> > +#include <linux/of_platform.h> > #include <linux/platform_device.h> > > #define DEVICE_NAME "test" > @@ -217,7 +220,43 @@ static struct kunit_suite platform_device_devm_test_suite = { > .test_cases = platform_device_devm_tests, > }; > > -kunit_test_suite(platform_device_devm_test_suite); > +static void platform_device_find_by_null_test(struct kunit *test) > +{ > + struct platform_device *pdev; > + int ret; > + > + pdev = kunit_platform_device_alloc(test, DEVICE_NAME, PLATFORM_DEVID_NONE); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev); > + > + ret = kunit_platform_device_add(test, pdev); > + KUNIT_ASSERT_EQ(test, ret, 0); > + > + KUNIT_EXPECT_PTR_EQ(test, of_find_device_by_node(NULL), NULL); > + > + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_of_node(&platform_bus_type, NULL), NULL); > + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_fwnode(&platform_bus_type, NULL), NULL); > + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_acpi_dev(&platform_bus_type, NULL), NULL); > + > + KUNIT_EXPECT_FALSE(test, device_match_of_node(&pdev->dev, NULL)); > + KUNIT_EXPECT_FALSE(test, device_match_fwnode(&pdev->dev, NULL)); > + KUNIT_EXPECT_FALSE(test, device_match_acpi_dev(&pdev->dev, NULL)); > + KUNIT_EXPECT_FALSE(test, device_match_acpi_handle(&pdev->dev, NULL)); > +} > + > +static struct kunit_case platform_device_match_tests[] = { > + KUNIT_CASE(platform_device_find_by_null_test), > + {} > +}; > + > +static struct kunit_suite platform_device_match_test_suite = { > + .name = "platform-device-match", > + .test_cases = platform_device_match_tests, > +}; > + > +kunit_test_suites( > + &platform_device_devm_test_suite, > + &platform_device_match_test_suite, > +); > > MODULE_DESCRIPTION("Test module for platform devices"); > MODULE_AUTHOR("Maxime Ripard <mripard@kernel.org>"); > -- > 2.47.1.613.gc27f4b7a9f-goog > [-- Attachment #2: S/MIME Cryptographic Signature --] [-- Type: application/pkcs7-signature, Size: 5294 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 3/3] drivers: base: test: Add ...find_device_by...(... NULL) tests 2024-12-19 5:45 ` David Gow @ 2024-12-20 17:34 ` Shuah Khan 0 siblings, 0 replies; 11+ messages in thread From: Shuah Khan @ 2024-12-20 17:34 UTC (permalink / raw) To: David Gow, Brian Norris Cc: Greg Kroah-Hartman, Maxime Ripard, linux-acpi, Rae Moar, Rob Herring, linux-kselftest, Rafael J. Wysocki, kunit-dev, linux-kernel, Shuah Khan On 12/18/24 22:45, David Gow wrote: > On Tue, 17 Dec 2024 at 04:12, Brian Norris <briannorris@chromium.org> wrote: >> >> We recently updated these device_match*() (and therefore, various >> *find_device_by*()) functions to return a consistent 'false' value when >> trying to match a NULL handle. Add tests for this. >> >> This provides regression-testing coverage for the sorts of bugs that >> underly commit 5c8418cf4025 ("PCI/pwrctrl: Unregister platform device >> only if one actually exists"). >> >> Reviewed-by: Maxime Ripard <mripard@kernel.org> >> Signed-off-by: Brian Norris <briannorris@chromium.org> >> --- >> > > Thanks. This looks good to me. > > Reviewed-by: David Gow <davidgow@google.com> > > > This one also can go through Greg's drivers tree: Acked-by: Shuah Khan <skhan@linuxfoundation.org> thanks, -- Shuah ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-12-20 17:44 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 ` [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc Brian Norris 2024-12-19 5:45 ` 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox