Skip to contentSkip to conversation

usb: typec: Two fixes

PATCH In review Heikki Krogerus 2 participants 4 messages Jan 24, 2022

Subsystems (2)
lore
Share & tools
lore

Heikki Krogerus

author maintainer
#0 lore raw

cover usb: typec: Two fixes

Hi,

The commit 730b49aac426 ("usb: typec: port-mapper: Convert to the component framework") had two issues. These fix them.

thanks,

Heikki Krogerus (2):
usb: typec: Only attempt to link USB ports if there is fwnode
usb: typec: Don't try to register component master without components

 drivers/usb/typec/port-mapper.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/2 usb: typec: Only attempt to link USB ports if there is fwnode

The code that creates the links to the USB ports attached to a connector inside the system assumed that the ACPI nodes (fwnodes) always exist for the connectors, but it can not do that.

There is no guarantee that every USB Type-C connector has ACPI device node representing it in the ACPI tables, and even if there are the nodes in the ACPI tables, the _STA method in those nodes may still return 0 (which means the device does not exist from ACPI PoW).

This fixes NULL pointer dereference that happens if the nodes are missing.

Fixes 730b49aac426 ("usb: typec: port-mapper: Convert to the component framework")
---
 drivers/usb/typec/port-mapper.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/typec/port-mapper.c +5 -1
index 07d307418b470..b6e0c6acc628c 100644
@@ -56,6 +56,9 @@ int typec_link_ports(struct typec_port *con)
 {
 	struct each_port_arg arg = { .port = con, .match = NULL };
 
+	if (!has_acpi_companion(&con->dev))
+		return 0;
+
 	bus_for_each_dev(&acpi_bus_type, NULL, &arg, typec_port_match);
 
 	/*
@@ -74,5 +77,6 @@ int typec_link_ports(struct typec_port *con)
 
 void typec_unlink_ports(struct typec_port *con)
 {
-	component_master_del(&con->dev, &typec_aggregate_ops);
+	if (has_acpi_companion(&con->dev))
+		component_master_del(&con->dev, &typec_aggregate_ops);
 }
Signature · 1 line
2.34.1
Acked-by Tested-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] usb: typec: Only attempt to link USB ports if there is fwnode

Quoted 38 lines · Heikki Krogerus

The code that creates the links to the USB ports attached to a connector inside the system assumed that the ACPI nodes (fwnodes) always exist for the connectors, but it can not do that.

There is no guarantee that every USB Type-C connector has ACPI device node representing it in the ACPI tables, and even if there are the nodes in the ACPI tables, the _STA method in those nodes may still return 0 (which means the device does not exist from ACPI PoW).

This fixes NULL pointer dereference that happens if the nodes are missing.

Fixes 730b49aac426 ("usb: typec: port-mapper: Convert to the

component framework")

---
 drivers/usb/typec/port-mapper.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/typec/port-mapper.c +3 -0
index 07d307418b470..b6e0c6acc628c 100644
@@ -56,6 +56,9 @@ int typec_link_ports(struct typec_port *con)
 {
 	struct each_port_arg arg = { .port = con, .match = NULL };
 
+	if (!has_acpi_companion(&con->dev))
+		return 0;
+
 	bus_for_each_dev(&acpi_bus_type, NULL, &arg, typec_port_match);
 
 	/*

drivers/usb/typec/port-mapper.c int typec_link_ports(struct typec_port *con) · line 82

Quoted 7 lines
drivers/usb/typec/port-mapper.c +2 -1
@@ -74,5 +77,6 @@ int typec_link_ports(struct typec_port *con)
 
 void typec_unlink_ports(struct typec_port *con)
 {
-	component_master_del(&con->dev, &typec_aggregate_ops);
+	if (has_acpi_companion(&con->dev))
+		component_master_del(&con->dev, &typec_aggregate_ops);
 }

This fixes an ugly Oops on the Apple M1. So FWIW:

        M.
Signature · 1 line
Who you jivin' with that Cosmik Debris?
author maintainer
#3 lore raw

PATCH 2/2 usb: typec: Don't try to register component master without components

In reply to Heikki Krogerus

This fixes NULL pointer dereference that happens if component master is registered with empty component match list.

Fixes 730b49aac426 ("usb: typec: port-mapper: Convert to the component framework")
---
 drivers/usb/typec/port-mapper.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/typec/port-mapper.c +2 -0
index b6e0c6acc628c..a7d507802509f 100644
@@ -60,6 +60,8 @@ int typec_link_ports(struct typec_port *con)
 		return 0;
 
 	bus_for_each_dev(&acpi_bus_type, NULL, &arg, typec_port_match);
+	if (!arg.match)
+		return 0;
 
 	/*
 	 * REVISIT: Now each connector can have only a single component master.
Signature · 1 line
2.34.1