[PATCH 04/10] driver: don't crash when dev_name/dev_id is called with NULL dev
Ahmad Fatoum
a.fatoum at pengutronix.de
Sun Oct 9 23:11:16 PDT 2022
cdev->dev being NULL is normal for virtual device files like /dev/null,
but can trip developers over. Ensure dev_name(cdev->dev) returns NULL
instead of crashing for more robustness.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
include/driver.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/driver.h b/include/driver.h
index 543287a27638..c81aa8587c13 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -184,6 +184,8 @@ char *deviceid_from_spec_str(const char *str, char **endp);
static inline const char *dev_id(const struct device_d *dev)
{
+ if (!dev)
+ return NULL;
return (dev->id != DEVICE_ID_SINGLE) ? dev->unique_name : dev->name;
}
--
2.30.2
More information about the barebox
mailing list