Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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")
Reported-and-tested-by: Robert Święcki <robert@swiecki.net>
Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Tested-by: Marc Zyngier <maz@kernel.org>
Acked-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20220124090228.41396-2-heikki.krogerus@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Heikki Krogerus and committed by
Greg Kroah-Hartman
7817adb0 5638b0df

+5 -1
+5 -1
drivers/usb/typec/port-mapper.c
··· 56 56 { 57 57 struct each_port_arg arg = { .port = con, .match = NULL }; 58 58 59 + if (!has_acpi_companion(&con->dev)) 60 + return 0; 61 + 59 62 bus_for_each_dev(&acpi_bus_type, NULL, &arg, typec_port_match); 60 63 61 64 /* ··· 77 74 78 75 void typec_unlink_ports(struct typec_port *con) 79 76 { 80 - component_master_del(&con->dev, &typec_aggregate_ops); 77 + if (has_acpi_companion(&con->dev)) 78 + component_master_del(&con->dev, &typec_aggregate_ops); 81 79 }