[PATCH 04/10] driver: don't crash when dev_name/dev_id is called with NULL dev

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux