Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drivers: base: test: Add ...find_device_by...(... NULL) tests

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>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: David Gow <davidgow@google.com>
Link: https://lore.kernel.org/r/20241216201148.535115-4-briannorris@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Brian Norris and committed by
Greg Kroah-Hartman
86a5f32e 55b7aee9

+40 -1
+40 -1
drivers/base/test/platform-device-test.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 + #include <kunit/platform_device.h> 3 4 #include <kunit/resource.h> 4 5 5 6 #include <linux/device.h> 7 + #include <linux/device/bus.h> 8 + #include <linux/of_platform.h> 6 9 #include <linux/platform_device.h> 7 10 8 11 #define DEVICE_NAME "test" ··· 220 217 .test_cases = platform_device_devm_tests, 221 218 }; 222 219 223 - kunit_test_suite(platform_device_devm_test_suite); 220 + static void platform_device_find_by_null_test(struct kunit *test) 221 + { 222 + struct platform_device *pdev; 223 + int ret; 224 + 225 + pdev = kunit_platform_device_alloc(test, DEVICE_NAME, PLATFORM_DEVID_NONE); 226 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev); 227 + 228 + ret = kunit_platform_device_add(test, pdev); 229 + KUNIT_ASSERT_EQ(test, ret, 0); 230 + 231 + KUNIT_EXPECT_PTR_EQ(test, of_find_device_by_node(NULL), NULL); 232 + 233 + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_of_node(&platform_bus_type, NULL), NULL); 234 + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_fwnode(&platform_bus_type, NULL), NULL); 235 + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_acpi_dev(&platform_bus_type, NULL), NULL); 236 + 237 + KUNIT_EXPECT_FALSE(test, device_match_of_node(&pdev->dev, NULL)); 238 + KUNIT_EXPECT_FALSE(test, device_match_fwnode(&pdev->dev, NULL)); 239 + KUNIT_EXPECT_FALSE(test, device_match_acpi_dev(&pdev->dev, NULL)); 240 + KUNIT_EXPECT_FALSE(test, device_match_acpi_handle(&pdev->dev, NULL)); 241 + } 242 + 243 + static struct kunit_case platform_device_match_tests[] = { 244 + KUNIT_CASE(platform_device_find_by_null_test), 245 + {} 246 + }; 247 + 248 + static struct kunit_suite platform_device_match_test_suite = { 249 + .name = "platform-device-match", 250 + .test_cases = platform_device_match_tests, 251 + }; 252 + 253 + kunit_test_suites( 254 + &platform_device_devm_test_suite, 255 + &platform_device_match_test_suite, 256 + ); 224 257 225 258 MODULE_DESCRIPTION("Test module for platform devices"); 226 259 MODULE_AUTHOR("Maxime Ripard <mripard@kernel.org>");