All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] usb: typec: Two fixes
@ 2022-01-24  9:02 Heikki Krogerus
  2022-01-24  9:02 ` [PATCH 1/2] usb: typec: Only attempt to link USB ports if there is fwnode Heikki Krogerus
  2022-01-24  9:02 ` [PATCH 2/2] usb: typec: Don't try to register component master without components Heikki Krogerus
  0 siblings, 2 replies; 4+ messages in thread
From: Heikki Krogerus @ 2022-01-24  9:02 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb

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(-)

-- 
2.34.1


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

* [PATCH 1/2] usb: typec: Only attempt to link USB ports if there is fwnode
  2022-01-24  9:02 [PATCH 0/2] usb: typec: Two fixes Heikki Krogerus
@ 2022-01-24  9:02 ` Heikki Krogerus
  2022-01-24 16:26   ` Marc Zyngier
  2022-01-24  9:02 ` [PATCH 2/2] usb: typec: Don't try to register component master without components Heikki Krogerus
  1 sibling, 1 reply; 4+ messages in thread
From: Heikki Krogerus @ 2022-01-24  9:02 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, Robert Święcki, Mikhail Gavrilov

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.

Reported-and-tested-by: Robert Święcki <robert@swiecki.net>
Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Fixes: 730b49aac426 ("usb: typec: port-mapper: Convert to the component framework")
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/usb/typec/port-mapper.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/port-mapper.c b/drivers/usb/typec/port-mapper.c
index 07d307418b470..b6e0c6acc628c 100644
--- a/drivers/usb/typec/port-mapper.c
+++ b/drivers/usb/typec/port-mapper.c
@@ -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);
 }
-- 
2.34.1


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

* [PATCH 2/2] usb: typec: Don't try to register component master without components
  2022-01-24  9:02 [PATCH 0/2] usb: typec: Two fixes Heikki Krogerus
  2022-01-24  9:02 ` [PATCH 1/2] usb: typec: Only attempt to link USB ports if there is fwnode Heikki Krogerus
@ 2022-01-24  9:02 ` Heikki Krogerus
  1 sibling, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2022-01-24  9:02 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, Mikhail Gavrilov, John Stultz

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

Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Tested-by: John Stultz <john.stultz@linaro.org>
Fixes: 730b49aac426 ("usb: typec: port-mapper: Convert to the component framework")
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/usb/typec/port-mapper.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/typec/port-mapper.c b/drivers/usb/typec/port-mapper.c
index b6e0c6acc628c..a7d507802509f 100644
--- a/drivers/usb/typec/port-mapper.c
+++ b/drivers/usb/typec/port-mapper.c
@@ -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.
-- 
2.34.1


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

* Re: [PATCH 1/2] usb: typec: Only attempt to link USB ports if there is fwnode
  2022-01-24  9:02 ` [PATCH 1/2] usb: typec: Only attempt to link USB ports if there is fwnode Heikki Krogerus
@ 2022-01-24 16:26   ` Marc Zyngier
  0 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2022-01-24 16:26 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Greg Kroah-Hartman, linux-usb, Robert Święcki,
	Mikhail Gavrilov

On 2022-01-24 09:02, Heikki Krogerus wrote:
> 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.
> 
> Reported-and-tested-by: Robert Święcki <robert@swiecki.net>
> Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
> Fixes: 730b49aac426 ("usb: typec: port-mapper: Convert to the
> component framework")
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
>  drivers/usb/typec/port-mapper.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/port-mapper.c 
> b/drivers/usb/typec/port-mapper.c
> index 07d307418b470..b6e0c6acc628c 100644
> --- a/drivers/usb/typec/port-mapper.c
> +++ b/drivers/usb/typec/port-mapper.c
> @@ -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);
>  }

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

Acked-by: Marc Zyngier <maz@kernel.org>
Tested-by: Marc Zyngier <maz@kernel.org>

         M.
-- 
Who you jivin' with that Cosmik Debris?

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

end of thread, other threads:[~2022-01-24 16:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24  9:02 [PATCH 0/2] usb: typec: Two fixes Heikki Krogerus
2022-01-24  9:02 ` [PATCH 1/2] usb: typec: Only attempt to link USB ports if there is fwnode Heikki Krogerus
2022-01-24 16:26   ` Marc Zyngier
2022-01-24  9:02 ` [PATCH 2/2] usb: typec: Don't try to register component master without components Heikki Krogerus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.