public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thunderbolt: handle possible NULL pointer from get_device()
@ 2023-06-09  6:16 Dmitry Antipov
  2023-06-09  6:30 ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry Antipov @ 2023-06-09  6:16 UTC (permalink / raw)
  To: Michael Jamet; +Cc: linux-usb, lvc-project, Dmitry Antipov

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@yandex.ru>
---
 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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-06-09  9:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-09  6:16 [PATCH] thunderbolt: handle possible NULL pointer from get_device() Dmitry Antipov
2023-06-09  6:30 ` Greg KH
2023-06-09  7:15   ` Dmitry Antipov
2023-06-09  7:46     ` Greg KH
2023-06-09  8:05       ` Dmitry Antipov
2023-06-09  8:20         ` Greg KH
2023-06-09  9:19           ` Dmitry Antipov
2023-06-09  9:30             ` Greg KH
2023-06-09  8:32         ` [lvc-project] " Alexey Khoroshilov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox