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:
parent
fc9b8100c7
commit
5b36a01a67
2 changed files with 9 additions and 1 deletions
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue