Commit 639ff208 authored by Prashant Malani's avatar Prashant Malani Committed by Enric Balletbo i Serra

platform/chrome: cros_ec_typec: Check for device within remove function

In a couple of call sites, we use the same pattern of checking for a
partner or cable device before attempting to remove it. Simplify this by
moving those checks into the remove functions.

Cc: Benson Leung <bleung@chromium.org>
Signed-off-by: default avatarPrashant Malani <pmalani@chromium.org>
Signed-off-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210319015103.3751672-1-pmalani@chromium.org
parent dbc334fb
...@@ -220,6 +220,9 @@ static void cros_typec_remove_partner(struct cros_typec_data *typec, ...@@ -220,6 +220,9 @@ static void cros_typec_remove_partner(struct cros_typec_data *typec,
{ {
struct cros_typec_port *port = typec->ports[port_num]; struct cros_typec_port *port = typec->ports[port_num];
if (!port->partner)
return;
cros_typec_unregister_altmodes(typec, port_num, true); cros_typec_unregister_altmodes(typec, port_num, true);
cros_typec_usb_disconnect_state(port); cros_typec_usb_disconnect_state(port);
...@@ -235,6 +238,9 @@ static void cros_typec_remove_cable(struct cros_typec_data *typec, ...@@ -235,6 +238,9 @@ static void cros_typec_remove_cable(struct cros_typec_data *typec,
{ {
struct cros_typec_port *port = typec->ports[port_num]; struct cros_typec_port *port = typec->ports[port_num];
if (!port->cable)
return;
cros_typec_unregister_altmodes(typec, port_num, false); cros_typec_unregister_altmodes(typec, port_num, false);
typec_unregister_plug(port->plug); typec_unregister_plug(port->plug);
...@@ -253,10 +259,7 @@ static void cros_unregister_ports(struct cros_typec_data *typec) ...@@ -253,10 +259,7 @@ static void cros_unregister_ports(struct cros_typec_data *typec)
if (!typec->ports[i]) if (!typec->ports[i])
continue; continue;
if (typec->ports[i]->partner)
cros_typec_remove_partner(typec, i); cros_typec_remove_partner(typec, i);
if (typec->ports[i]->cable)
cros_typec_remove_cable(typec, i); cros_typec_remove_cable(typec, i);
usb_role_switch_put(typec->ports[i]->role_sw); usb_role_switch_put(typec->ports[i]->role_sw);
...@@ -647,10 +650,7 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, ...@@ -647,10 +650,7 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
"Failed to register partner on port: %d\n", "Failed to register partner on port: %d\n",
port_num); port_num);
} else { } else {
if (typec->ports[port_num]->partner)
cros_typec_remove_partner(typec, port_num); cros_typec_remove_partner(typec, port_num);
if (typec->ports[port_num]->cable)
cros_typec_remove_cable(typec, port_num); cros_typec_remove_cable(typec, port_num);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment