* [PATCH 1/1] usb: typec: tcpm: use 'time_left' variable with wait_for_completion_timeout()
@ 2024-06-04 21:27 Wolfram Sang
2024-06-06 7:19 ` Heikki Krogerus
0 siblings, 1 reply; 2+ messages in thread
From: Wolfram Sang @ 2024-06-04 21:27 UTC (permalink / raw)
To: linux-kernel; +Cc: Wolfram Sang, Heikki Krogerus, Greg Kroah-Hartman, linux-usb
There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_completion_timeout() causing patterns like:
timeout = wait_for_completion_timeout(...)
if (!timeout) return -ETIMEDOUT;
with all kinds of permutations. Use 'time_left' as a variable to make the code
self explaining.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/usb/typec/tcpm/tcpm.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 8a1af08f71b6..e46148c19be3 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -943,7 +943,7 @@ static int tcpm_pd_transmit(struct tcpm_port *port,
enum tcpm_transmit_type tx_sop_type,
const struct pd_message *msg)
{
- unsigned long timeout;
+ unsigned long time_left;
int ret;
unsigned int negotiated_rev;
@@ -968,10 +968,10 @@ static int tcpm_pd_transmit(struct tcpm_port *port,
return ret;
mutex_unlock(&port->lock);
- timeout = wait_for_completion_timeout(&port->tx_complete,
- msecs_to_jiffies(PD_T_TCPC_TX_TIMEOUT));
+ time_left = wait_for_completion_timeout(&port->tx_complete,
+ msecs_to_jiffies(PD_T_TCPC_TX_TIMEOUT));
mutex_lock(&port->lock);
- if (!timeout)
+ if (!time_left)
return -ETIMEDOUT;
switch (port->tx_status) {
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] usb: typec: tcpm: use 'time_left' variable with wait_for_completion_timeout()
2024-06-04 21:27 [PATCH 1/1] usb: typec: tcpm: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
@ 2024-06-06 7:19 ` Heikki Krogerus
0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2024-06-06 7:19 UTC (permalink / raw)
To: Wolfram Sang; +Cc: linux-kernel, Greg Kroah-Hartman, linux-usb
On Tue, Jun 04, 2024 at 11:27:31PM +0200, Wolfram Sang wrote:
> There is a confusing pattern in the kernel to use a variable named 'timeout' to
> store the result of wait_for_completion_timeout() causing patterns like:
>
> timeout = wait_for_completion_timeout(...)
> if (!timeout) return -ETIMEDOUT;
>
> with all kinds of permutations. Use 'time_left' as a variable to make the code
> self explaining.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> drivers/usb/typec/tcpm/tcpm.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 8a1af08f71b6..e46148c19be3 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -943,7 +943,7 @@ static int tcpm_pd_transmit(struct tcpm_port *port,
> enum tcpm_transmit_type tx_sop_type,
> const struct pd_message *msg)
> {
> - unsigned long timeout;
> + unsigned long time_left;
> int ret;
> unsigned int negotiated_rev;
>
> @@ -968,10 +968,10 @@ static int tcpm_pd_transmit(struct tcpm_port *port,
> return ret;
>
> mutex_unlock(&port->lock);
> - timeout = wait_for_completion_timeout(&port->tx_complete,
> - msecs_to_jiffies(PD_T_TCPC_TX_TIMEOUT));
> + time_left = wait_for_completion_timeout(&port->tx_complete,
> + msecs_to_jiffies(PD_T_TCPC_TX_TIMEOUT));
> mutex_lock(&port->lock);
> - if (!timeout)
> + if (!time_left)
> return -ETIMEDOUT;
>
> switch (port->tx_status) {
> --
> 2.43.0
--
heikki
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-06 7:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-04 21:27 [PATCH 1/1] usb: typec: tcpm: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
2024-06-06 7:19 ` Heikki Krogerus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome