Skip to content

Commit e3ed55c

Browse files
svenpeter42marcan
authored andcommitted
usb: typec: tipd: Clear interrupts first
Right now the interrupt handler first reads all updated status registers and only then clears the interrupts. It's possible that a duplicate interrupt for a changed register or plug state comes in after the interrupts have been processed but before they have been cleared: * plug is inserted, TPS_REG_INT_PLUG_EVENT is set * TPS_REG_INT_EVENT1 is read * tps6598x_handle_plug_event() has run and registered the plug * plug is removed again, TPS_REG_INT_PLUG_EVENT is set (again) * TPS_REG_INT_CLEAR1 is written, TPS_REG_INT_PLUG_EVENT is cleared We then have no plug connected and no pending interrupt but the tipd core still thinks there is a plug. It's possible to trigger this with e.g. a slightly broken Type-C to USB A converter. Fix this by first clearing the interrupts and only then reading the updated registers. Fixes: 45188f2 ("usb: typec: tipd: Add support for Apple CD321X") Fixes: 0a4c005 ("usb: typec: driver for TI TPS6598x USB Power Delivery controllers") Cc: stable <[email protected]> Signed-off-by: Sven Peter <[email protected]>
1 parent 42ffc89 commit e3ed55c

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

drivers/usb/typec/tipd/core.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -494,24 +494,23 @@ static irqreturn_t cd321x_interrupt(int irq, void *data)
494494
if (!event)
495495
goto err_unlock;
496496

497+
tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event);
498+
497499
if (!tps6598x_read_status(tps, &status))
498-
goto err_clear_ints;
500+
goto err_unlock;
499501

500502
if (event & APPLE_CD_REG_INT_POWER_STATUS_UPDATE)
501503
if (!tps6598x_read_power_status(tps))
502-
goto err_clear_ints;
504+
goto err_unlock;
503505

504506
if (event & APPLE_CD_REG_INT_DATA_STATUS_UPDATE)
505507
if (!tps6598x_read_data_status(tps))
506-
goto err_clear_ints;
508+
goto err_unlock;
507509

508510
/* Handle plug insert or removal */
509511
if (event & APPLE_CD_REG_INT_PLUG_EVENT)
510512
tps6598x_handle_plug_event(tps, status);
511513

512-
err_clear_ints:
513-
tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event);
514-
515514
err_unlock:
516515
mutex_unlock(&tps->lock);
517516

@@ -541,25 +540,24 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
541540
if (!(event1 | event2))
542541
goto err_unlock;
543542

543+
tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event1);
544+
tps6598x_write64(tps, TPS_REG_INT_CLEAR2, event2);
545+
544546
if (!tps6598x_read_status(tps, &status))
545-
goto err_clear_ints;
547+
goto err_unlock;
546548

547549
if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE)
548550
if (!tps6598x_read_power_status(tps))
549-
goto err_clear_ints;
551+
goto err_unlock;
550552

551553
if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE)
552554
if (!tps6598x_read_data_status(tps))
553-
goto err_clear_ints;
555+
goto err_unlock;
554556

555557
/* Handle plug insert or removal */
556558
if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT)
557559
tps6598x_handle_plug_event(tps, status);
558560

559-
err_clear_ints:
560-
tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event1);
561-
tps6598x_write64(tps, TPS_REG_INT_CLEAR2, event2);
562-
563561
err_unlock:
564562
mutex_unlock(&tps->lock);
565563

0 commit comments

Comments
 (0)