device: binding lookup should return null for unsupported names

A null device name should map to a null device.  So should a name that
is empty.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2021-02-12 06:19:08 -06:00 committed by Kumar Gala
commit 5b36a01a67
2 changed files with 9 additions and 1 deletions

View file

@ -313,7 +313,8 @@ struct device {
* it can use this function to retrieve the device structure of the lower level
* driver by the name the driver exposes to the system.
*
* @param name device name to search for.
* @param name device name to search for. A null pointer, or a pointer to an
* empty string, will cause NULL to be returned.
*
* @return pointer to device structure; NULL if not found or cannot be used.
*/

View file

@ -79,6 +79,13 @@ const struct device *z_impl_device_get_binding(const char *name)
{
const struct device *dev;
/* A null string identifies no device. So does an empty
* string.
*/
if ((name == NULL) || (*name == 0)) {
return NULL;
}
/* Split the search into two loops: in the common scenario, where
* device names are stored in ROM (and are referenced by the user
* with CONFIG_* macros), only cheap pointer comparisons will be