[PATCH] thunderbolt: handle possible NULL pointer from get_device()

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

 



Handle possible NULL pointer returned by 'get_device()'
in 'tb_xdomain_alloc()' and 'remove_unplugged_switch()'.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Dmitry Antipov <dmantipov@xxxxxxxxx>
---
 drivers/thunderbolt/icm.c     | 5 +++++
 drivers/thunderbolt/xdomain.c | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c
index 86521ebb2579..40ab6104a437 100644
--- a/drivers/thunderbolt/icm.c
+++ b/drivers/thunderbolt/icm.c
@@ -2035,6 +2035,11 @@ static void remove_unplugged_switch(struct tb_switch *sw)
 {
 	struct device *parent = get_device(sw->dev.parent);
 
+	if (!parent) {
+		tb_warn(sw->tb, "no parent of switch %pUb\n", sw->uuid);
+		return;
+	}
+
 	pm_runtime_get_sync(parent);
 
 	/*
diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
index e2b54887d331..a0ee683d752e 100644
--- a/drivers/thunderbolt/xdomain.c
+++ b/drivers/thunderbolt/xdomain.c
@@ -1883,6 +1883,8 @@ struct tb_xdomain *tb_xdomain_alloc(struct tb *tb, struct device *parent,
 
 	device_initialize(&xd->dev);
 	xd->dev.parent = get_device(parent);
+	if (!xd->dev.parent)
+		goto err_free_remote_uuid;
 	xd->dev.bus = &tb_bus_type;
 	xd->dev.type = &tb_xdomain_type;
 	xd->dev.groups = xdomain_attr_groups;
@@ -1902,6 +1904,8 @@ struct tb_xdomain *tb_xdomain_alloc(struct tb *tb, struct device *parent,
 
 	return xd;
 
+err_free_remote_uuid:
+	kfree(xd->remote_uuid);
 err_free_local_uuid:
 	kfree(xd->local_uuid);
 err_free:
-- 
2.40.1




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux