diff mbox series

tcpm: fix pd_transmit poll condition

Message ID 20250526-topic-tcpm-tx-poll-cond-v1-1-38a81560ffff@linaro.org
State New
Headers show
Series tcpm: fix pd_transmit poll condition | expand

Commit Message

Neil Armstrong May 26, 2025, 7:42 a.m. UTC
The read_poll_timeout() exit "cond" parameter wait for a complete
transmit state.

The "!tx_complete" cond means that on the first tcpm_transmit_helper()
call, if the tx_complete returns to false, the poll loop would exit.
But since at probe the tx_status is left at 0, the tx is considered
as successful. And then later the proper status is returned and
ignored.

But if on the first tcpm_transmit_helper() call the TX status is
returned the read_poll_timeout() would return in timeout and the
negociation would fail.

Fixes: 1db4c0ac77e ("usb: tcpm: add core framework")
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/usb/tcpm/tcpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


---
base-commit: bab54f5942c428be698216224fd10b91d974d4da
change-id: 20250526-topic-tcpm-tx-poll-cond-8dd3ebbbeddc

Best regards,

Comments

Marcel Ziswiler June 18, 2025, 9:38 a.m. UTC | #1
Hi Neil

Good catch. Thanks!

On Mon, 2025-05-26 at 09:42 +0200, Neil Armstrong wrote:
> The read_poll_timeout() exit "cond" parameter wait for a complete
> transmit state.
> 
> The "!tx_complete" cond means that on the first tcpm_transmit_helper()
> call, if the tx_complete returns to false, the poll loop would exit.
> But since at probe the tx_status is left at 0, the tx is considered
> as successful. And then later the proper status is returned and
> ignored.
> 
> But if on the first tcpm_transmit_helper() call the TX status is
> returned the read_poll_timeout() would return in timeout and the
> negociation would fail.
> 
> Fixes: 1db4c0ac77e ("usb: tcpm: add core framework")
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>

Tested-by: Marcel Ziswiler <marcel.ziswiler@codethink.co.uk> # rock5b

> ---
>  drivers/usb/tcpm/tcpm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/tcpm/tcpm.c b/drivers/usb/tcpm/tcpm.c
> index 0aee57cb2f4a44af7b483e0e609e39ba584a06c0..c8679615cd7701982b64b1905c5822ac98ed6f79 100644
> --- a/drivers/usb/tcpm/tcpm.c
> +++ b/drivers/usb/tcpm/tcpm.c
> @@ -209,7 +209,7 @@ static int tcpm_pd_transmit(struct udevice *dev,
>  	 */
>  	timeout_us *= 5;
>  	ret = read_poll_timeout(tcpm_transmit_helper, tx_complete,
> -				!tx_complete, false, timeout_us, dev);
> +				tx_complete, false, timeout_us, dev);
>  	if (ret < 0) {
>  		dev_err(dev, "TCPM: PD transmit data failed: %d\n", ret);
>  		return ret;
> 
> ---
> base-commit: bab54f5942c428be698216224fd10b91d974d4da
> change-id: 20250526-topic-tcpm-tx-poll-cond-8dd3ebbbeddc
> 
> Best regards,
> --
> Neil Armstrong <neil.armstrong@linaro.org>

Cheers

Marcel
diff mbox series

Patch

diff --git a/drivers/usb/tcpm/tcpm.c b/drivers/usb/tcpm/tcpm.c
index 0aee57cb2f4a44af7b483e0e609e39ba584a06c0..c8679615cd7701982b64b1905c5822ac98ed6f79 100644
--- a/drivers/usb/tcpm/tcpm.c
+++ b/drivers/usb/tcpm/tcpm.c
@@ -209,7 +209,7 @@  static int tcpm_pd_transmit(struct udevice *dev,
 	 */
 	timeout_us *= 5;
 	ret = read_poll_timeout(tcpm_transmit_helper, tx_complete,
-				!tx_complete, false, timeout_us, dev);
+				tx_complete, false, timeout_us, dev);
 	if (ret < 0) {
 		dev_err(dev, "TCPM: PD transmit data failed: %d\n", ret);
 		return ret;