Skip to content

Commit 639ff20

Browse files
Prashant MalaniEnric Balletbo i Serra
authored andcommitted
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 <[email protected]> Signed-off-by: Prashant Malani <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent dbc334f commit 639ff20

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ static void cros_typec_remove_partner(struct cros_typec_data *typec,
220220
{
221221
struct cros_typec_port *port = typec->ports[port_num];
222222

223+
if (!port->partner)
224+
return;
225+
223226
cros_typec_unregister_altmodes(typec, port_num, true);
224227

225228
cros_typec_usb_disconnect_state(port);
@@ -235,6 +238,9 @@ static void cros_typec_remove_cable(struct cros_typec_data *typec,
235238
{
236239
struct cros_typec_port *port = typec->ports[port_num];
237240

241+
if (!port->cable)
242+
return;
243+
238244
cros_typec_unregister_altmodes(typec, port_num, false);
239245

240246
typec_unregister_plug(port->plug);
@@ -253,11 +259,8 @@ static void cros_unregister_ports(struct cros_typec_data *typec)
253259
if (!typec->ports[i])
254260
continue;
255261

256-
if (typec->ports[i]->partner)
257-
cros_typec_remove_partner(typec, i);
258-
259-
if (typec->ports[i]->cable)
260-
cros_typec_remove_cable(typec, i);
262+
cros_typec_remove_partner(typec, i);
263+
cros_typec_remove_cable(typec, i);
261264

262265
usb_role_switch_put(typec->ports[i]->role_sw);
263266
typec_switch_put(typec->ports[i]->ori_sw);
@@ -647,11 +650,8 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
647650
"Failed to register partner on port: %d\n",
648651
port_num);
649652
} else {
650-
if (typec->ports[port_num]->partner)
651-
cros_typec_remove_partner(typec, port_num);
652-
653-
if (typec->ports[port_num]->cable)
654-
cros_typec_remove_cable(typec, port_num);
653+
cros_typec_remove_partner(typec, port_num);
654+
cros_typec_remove_cable(typec, port_num);
655655
}
656656
}
657657

0 commit comments

Comments
 (0)