Skip to content

Commit e37b383

Browse files
Łukasz Bartosikgregkh
authored andcommitted
usb: typec: ucsi: Fix completion notifications
OPM PPM LPM | 1.send cmd | | |-------------------------->| | | |-- | | | | 2.set busy bit in CCI | | |<- | | 3.notify the OPM | | |<--------------------------| | | | 4.send cmd to be executed | | |-------------------------->| | | | | | 5.cmd completed | | |<--------------------------| | | | | |-- | | | | 6.set cmd completed | | |<- bit in CCI | | | | | 7.notify the OPM | | |<--------------------------| | | | | | 8.handle notification | | | from point 3, read CCI | | |<--------------------------| | | | | When the PPM receives command from the OPM (p.1) it sets the busy bit in the CCI (p.2), sends notification to the OPM (p.3) and forwards the command to be executed by the LPM (p.4). When the PPM receives command completion from the LPM (p.5) it sets command completion bit in the CCI (p.6) and sends notification to the OPM (p.7). If command execution by the LPM is fast enough then when the OPM starts handling the notification from p.3 in p.8 and reads the CCI value it will see command completion bit set and will call complete(). Then complete() might be called again when the OPM handles notification from p.7. This fix replaces test_bit() with test_and_clear_bit() in ucsi_notify_common() in order to call complete() only once per request. This fix also reinitializes completion variable in ucsi_sync_control_common() before a command is sent. Fixes: 584e8df ("usb: typec: ucsi: extract common code for command handling") Cc: stable@vger.kernel.org Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Reviewed-by: Benson Leung <bleung@chromium.org> Link: https://lore.kernel.org/r/20241203102318.3386345-1-ukaszb@chromium.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1cf1bd8 commit e37b383

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ void ucsi_notify_common(struct ucsi *ucsi, u32 cci)
4646
ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci));
4747

4848
if (cci & UCSI_CCI_ACK_COMPLETE &&
49-
test_bit(ACK_PENDING, &ucsi->flags))
49+
test_and_clear_bit(ACK_PENDING, &ucsi->flags))
5050
complete(&ucsi->complete);
5151

5252
if (cci & UCSI_CCI_COMMAND_COMPLETE &&
53-
test_bit(COMMAND_PENDING, &ucsi->flags))
53+
test_and_clear_bit(COMMAND_PENDING, &ucsi->flags))
5454
complete(&ucsi->complete);
5555
}
5656
EXPORT_SYMBOL_GPL(ucsi_notify_common);
@@ -65,6 +65,8 @@ int ucsi_sync_control_common(struct ucsi *ucsi, u64 command)
6565
else
6666
set_bit(COMMAND_PENDING, &ucsi->flags);
6767

68+
reinit_completion(&ucsi->complete);
69+
6870
ret = ucsi->ops->async_control(ucsi, command);
6971
if (ret)
7072
goto out_clear_bit;

0 commit comments

Comments
 (0)