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@xxxxxxxxxxxxxx> --- 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