Skip to contentSkip to conversation

usb: typec: intel_pmc_mux: Don't leak the ACPI device reference count

PATCH In review Andy Shevchenko 2 participants 4 messages Jan 2, 2023 – Jan 3, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 usb: typec: intel_pmc_mux: Don't leak the ACPI device reference count

When acpi_dev_get_memory_resources() fails, the reference count is left bumped. Drop it as it's done in the other error paths.

Fixes 43d596e32276 ("usb: typec: intel_pmc_mux: Check the port status before connect")
---
 drivers/usb/typec/mux/intel_pmc_mux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/typec/mux/intel_pmc_mux.c +3 -1
index fdbf3694e21f..87e2c9130607 100644
@@ -614,8 +614,10 @@ static int pmc_usb_probe_iom(struct pmc_usb *pmc)
 
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_memory_resources(adev, &resource_list);
-	if (ret < 0)
+	if (ret < 0) {
+		acpi_dev_put(adev);
 		return ret;
+	}
 
 	rentry = list_first_entry_or_null(&resource_list, struct resource_entry, node);
 	if (rentry)
Signature · 1 line
2.35.1
#1 lore raw

PATCH 2/2 usb: typec: intel_pmc_mux: Deduplicate ACPI matching in probe

There is no need to call acpi_dev_present() followed by acpi_dev_get_first_match_dev() as they both do the same with only difference in the returning value. Instead, call the latter and check its result.

---
 drivers/usb/typec/mux/intel_pmc_mux.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/usb/typec/mux/intel_pmc_mux.c +4 -5
index 87e2c9130607..34e4188a40ff 100644
@@ -602,16 +602,15 @@ static int pmc_usb_probe_iom(struct pmc_usb *pmc)
 	int ret;
 
 	for (dev_id = &iom_acpi_ids[0]; dev_id->id[0]; dev_id++) {
-		if (acpi_dev_present(dev_id->id, NULL, -1)) {
-			pmc->iom_port_status_offset = (u32)dev_id->driver_data;
-			adev = acpi_dev_get_first_match_dev(dev_id->id, NULL, -1);
+		adev = acpi_dev_get_first_match_dev(dev_id->id, NULL, -1);
+		if (adev)
 			break;
-		}
 	}
-
 	if (!adev)
 		return -ENODEV;
 
+	pmc->iom_port_status_offset = (u32)dev_id->driver_data;
+
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_memory_resources(adev, &resource_list);
 	if (ret < 0) {
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH v1 2/2] usb: typec: intel_pmc_mux: Deduplicate ACPI matching in probe

Quoted 6 lines · Andy Shevchenko

There is no need to call acpi_dev_present() followed by acpi_dev_get_first_match_dev() as they both do the same with only difference in the returning value. Instead, call the latter and check its result.

Quoted 31 lines
---
 drivers/usb/typec/mux/intel_pmc_mux.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/usb/typec/mux/intel_pmc_mux.c +4 -5
index 87e2c9130607..34e4188a40ff 100644
@@ -602,16 +602,15 @@ static int pmc_usb_probe_iom(struct pmc_usb *pmc)
 	int ret;
 
 	for (dev_id = &iom_acpi_ids[0]; dev_id->id[0]; dev_id++) {
-		if (acpi_dev_present(dev_id->id, NULL, -1)) {
-			pmc->iom_port_status_offset = (u32)dev_id->driver_data;
-			adev = acpi_dev_get_first_match_dev(dev_id->id, NULL, -1);
+		adev = acpi_dev_get_first_match_dev(dev_id->id, NULL, -1);
+		if (adev)
 			break;
-		}
 	}
-
 	if (!adev)
 		return -ENODEV;
 
+	pmc->iom_port_status_offset = (u32)dev_id->driver_data;
+
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_memory_resources(adev, &resource_list);
 	if (ret < 0) {
Signature · 1 line
2.35.1
Signature · 1 line
heikki
maintainer Reviewed-by on v1 1/2
#3 lore raw
In reply to Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

When acpi_dev_get_memory_resources() fails, the reference count is left bumped. Drop it as it's done in the other error paths.

Fixes 43d596e32276 ("usb: typec: intel_pmc_mux: Check the port status before connect")
Quoted 22 lines
---
 drivers/usb/typec/mux/intel_pmc_mux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/typec/mux/intel_pmc_mux.c +3 -1
index fdbf3694e21f..87e2c9130607 100644
@@ -614,8 +614,10 @@ static int pmc_usb_probe_iom(struct pmc_usb *pmc)
 
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_memory_resources(adev, &resource_list);
-	if (ret < 0)
+	if (ret < 0) {
+		acpi_dev_put(adev);
 		return ret;
+	}
 
 	rentry = list_first_entry_or_null(&resource_list, struct resource_entry, node);
 	if (rentry)
Signature · 1 line
2.35.1

thanks,

Signature · 1 line
heikki