Skip to content

Commit 698d4d3

Browse files
Prashant MalaniEnric Balletbo i Serra
authored andcommitted
platform/chrome: cros_ec_typec: Unregister partner on error
When port update is called during probe(), any error with setting the Type C muxes results in an errno being returned to probe(), which promptly returns that itself. Ensure that we unregister any registered partners when doing so, to prevent orphaned partners on the Type C connector class framework. Move the cros_typec_add_partner() and cros_typec_remove_partner() code together to higher up in the file, so that they are together, and we can call cros_typec_remove_partner() from cros_unregister_ports(). Fixes: 7e7def1 ("platform/chrome: cros_ec_typec: Add USB mux control") Signed-off-by: Prashant Malani <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]>
1 parent e48bc01 commit 698d4d3

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,55 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
141141
return -ENODEV;
142142
}
143143

144+
static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num,
145+
bool pd_en)
146+
{
147+
struct cros_typec_port *port = typec->ports[port_num];
148+
struct typec_partner_desc p_desc = {
149+
.usb_pd = pd_en,
150+
};
151+
int ret = 0;
152+
153+
/*
154+
* Fill an initial PD identity, which will then be updated with info
155+
* from the EC.
156+
*/
157+
p_desc.identity = &port->p_identity;
158+
159+
port->partner = typec_register_partner(port->port, &p_desc);
160+
if (IS_ERR(port->partner)) {
161+
ret = PTR_ERR(port->partner);
162+
port->partner = NULL;
163+
}
164+
165+
return ret;
166+
}
167+
168+
static void cros_typec_remove_partner(struct cros_typec_data *typec,
169+
int port_num)
170+
{
171+
struct cros_typec_port *port = typec->ports[port_num];
172+
173+
port->state.alt = NULL;
174+
port->state.mode = TYPEC_STATE_USB;
175+
port->state.data = NULL;
176+
177+
usb_role_switch_set_role(port->role_sw, USB_ROLE_NONE);
178+
typec_switch_set(port->ori_sw, TYPEC_ORIENTATION_NONE);
179+
typec_mux_set(port->mux, &port->state);
180+
181+
typec_unregister_partner(port->partner);
182+
port->partner = NULL;
183+
}
184+
144185
static void cros_unregister_ports(struct cros_typec_data *typec)
145186
{
146187
int i;
147188

148189
for (i = 0; i < typec->num_ports; i++) {
149190
if (!typec->ports[i])
150191
continue;
192+
cros_typec_remove_partner(typec, i);
151193
usb_role_switch_put(typec->ports[i]->role_sw);
152194
typec_switch_put(typec->ports[i]->ori_sw);
153195
typec_mux_put(typec->ports[i]->mux);
@@ -286,47 +328,6 @@ static int cros_typec_ec_command(struct cros_typec_data *typec,
286328
return ret;
287329
}
288330

289-
static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num,
290-
bool pd_en)
291-
{
292-
struct cros_typec_port *port = typec->ports[port_num];
293-
struct typec_partner_desc p_desc = {
294-
.usb_pd = pd_en,
295-
};
296-
int ret = 0;
297-
298-
/*
299-
* Fill an initial PD identity, which will then be updated with info
300-
* from the EC.
301-
*/
302-
p_desc.identity = &port->p_identity;
303-
304-
port->partner = typec_register_partner(port->port, &p_desc);
305-
if (IS_ERR(port->partner)) {
306-
ret = PTR_ERR(port->partner);
307-
port->partner = NULL;
308-
}
309-
310-
return ret;
311-
}
312-
313-
static void cros_typec_remove_partner(struct cros_typec_data *typec,
314-
int port_num)
315-
{
316-
struct cros_typec_port *port = typec->ports[port_num];
317-
318-
port->state.alt = NULL;
319-
port->state.mode = TYPEC_STATE_USB;
320-
port->state.data = NULL;
321-
322-
usb_role_switch_set_role(port->role_sw, USB_ROLE_NONE);
323-
typec_switch_set(port->ori_sw, TYPEC_ORIENTATION_NONE);
324-
typec_mux_set(port->mux, &port->state);
325-
326-
typec_unregister_partner(port->partner);
327-
port->partner = NULL;
328-
}
329-
330331
static void cros_typec_set_port_params_v0(struct cros_typec_data *typec,
331332
int port_num, struct ec_response_usb_pd_control *resp)
332333
{

0 commit comments

Comments
 (0)