usb: typec: Set port->pd before adding device for typec_port

When calling device_add in the registration of typec_port, it will do
the NULL check on usb_power_delivery handle in typec_port for the
visibility of the device attributes. It is always NULL because port->pd
is set in typec_port_set_usb_power_delivery which is later than the
device_add call.

Set port->pd before device_add and only link the device after that.

Fixes: a7cff92f06 ("usb: typec: USB Power Delivery helpers for ports and partners")
Cc: stable@vger.kernel.org
Signed-off-by: Kyle Tso <kyletso@google.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20230623151036.3955013-2-kyletso@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Kyle Tso 2023-06-23 23:10:34 +08:00 committed by Greg Kroah-Hartman
parent da6d91ed77
commit b33ebb2415
1 changed files with 3 additions and 1 deletions

View File

@ -2288,6 +2288,8 @@ struct typec_port *typec_register_port(struct device *parent,
return ERR_PTR(ret);
}
port->pd = cap->pd;
ret = device_add(&port->dev);
if (ret) {
dev_err(parent, "failed to register port (%d)\n", ret);
@ -2295,7 +2297,7 @@ struct typec_port *typec_register_port(struct device *parent,
return ERR_PTR(ret);
}
ret = typec_port_set_usb_power_delivery(port, cap->pd);
ret = usb_power_delivery_link_device(port->pd, &port->dev);
if (ret) {
dev_err(&port->dev, "failed to link pd\n");
device_unregister(&port->dev);