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: Don't match devices with NULL of_node/fwnode/etc

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

authored by

Brian Norris and committed by
Greg Kroah-Hartman
1b1bb7b2 5ab5a377

+4 -4
+4 -4
drivers/base/core.c
··· 5246 5246 5247 5247 int device_match_of_node(struct device *dev, const void *np) 5248 5248 { 5249 - return dev->of_node == np; 5249 + return np && dev->of_node == np; 5250 5250 } 5251 5251 EXPORT_SYMBOL_GPL(device_match_of_node); 5252 5252 5253 5253 int device_match_fwnode(struct device *dev, const void *fwnode) 5254 5254 { 5255 - return dev_fwnode(dev) == fwnode; 5255 + return fwnode && dev_fwnode(dev) == fwnode; 5256 5256 } 5257 5257 EXPORT_SYMBOL_GPL(device_match_fwnode); 5258 5258 ··· 5264 5264 5265 5265 int device_match_acpi_dev(struct device *dev, const void *adev) 5266 5266 { 5267 - return ACPI_COMPANION(dev) == adev; 5267 + return adev && ACPI_COMPANION(dev) == adev; 5268 5268 } 5269 5269 EXPORT_SYMBOL(device_match_acpi_dev); 5270 5270 5271 5271 int device_match_acpi_handle(struct device *dev, const void *handle) 5272 5272 { 5273 - return ACPI_HANDLE(dev) == handle; 5273 + return handle && ACPI_HANDLE(dev) == handle; 5274 5274 } 5275 5275 EXPORT_SYMBOL(device_match_acpi_handle); 5276 5276