Skip to contentSkip to conversation

thunderbolt: Fix to check return value of ida_simple_get

PATCH Applied Aditya Pakki 2 participants 2 messages Mar 20, 2019 – Mar 22, 2019 Thunderbolt driver

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 thunderbolt: Fix to check return value of ida_simple_get

In enumerate_services, ida_simple_get on failure can return an error and leaks memory. The patch ensures that the dev_set_name is set on non failure cases, and releases memory during failure.

---
v2: Remove kfree in device_register failure
v1: Missed cleanup of svc in case of allocation failure and device_register failure.

---
 drivers/thunderbolt/xdomain.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/thunderbolt/xdomain.c +7 -1
index e27dd8beb94b..e0642dcb8b9b 100644
@@ -740,6 +740,7 @@ static void enumerate_services(struct tb_xdomain *xd)
 	struct tb_service *svc;
 	struct tb_property *p;
 	struct device *dev;
+	int id;
 
 	/*
 	 * First remove all services that are not available anymore in
@@ -768,7 +769,12 @@ static void enumerate_services(struct tb_xdomain *xd)
 			break;
 		}
 
-		svc->id = ida_simple_get(&xd->service_ids, 0, 0, GFP_KERNEL);
+		id = ida_simple_get(&xd->service_ids, 0, 0, GFP_KERNEL);
+		if (id < 0) {
+			kfree(svc);
+			break;
+		}
+		svc->id = id;
 		svc->dev.bus = &tb_bus_type;
 		svc->dev.type = &tb_service_type;
 		svc->dev.parent = &xd->dev;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 5 lines · Aditya Pakki

In enumerate_services, ida_simple_get on failure can return an error and leaks memory. The patch ensures that the dev_set_name is set on non failure cases, and releases memory during failure.

Applied, thanks!