[1/8] media: allegro: use 'time_left' variable with wait_for_completion_timeout()

Message ID 20240603092841.9500-2-wsa+renesas@sang-engineering.com (mailing list archive)
State New
Headers
Series media: use 'time_left' instead of 'timeout' with wait_*() functions |

Commit Message

Wolfram Sang June 3, 2024, 9:28 a.m. UTC
  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>
---
 .../media/platform/allegro-dvt/allegro-core.c    | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
  

Comments

Michael Tretter June 13, 2024, 8:39 a.m. UTC | #1
Hi Wolfram,

On Mon, 03 Jun 2024 11:28:32 +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.

Thanks for the patch.

There is another instance of wait_for_completion_timeout() in the
driver, which uses tmo instead of timeout. Maybe this patch should
change that, too.

Michael

> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  .../media/platform/allegro-dvt/allegro-core.c    | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c
> index da61f9beb6b4..4016aef5fdb9 100644
> --- a/drivers/media/platform/allegro-dvt/allegro-core.c
> +++ b/drivers/media/platform/allegro-dvt/allegro-core.c
> @@ -2481,14 +2481,14 @@ static void allegro_mcu_interrupt(struct allegro_dev *dev)
>  static void allegro_destroy_channel(struct allegro_channel *channel)
>  {
>  	struct allegro_dev *dev = channel->dev;
> -	unsigned long timeout;
> +	unsigned long time_left;
>  
>  	if (channel_exists(channel)) {
>  		reinit_completion(&channel->completion);
>  		allegro_mcu_send_destroy_channel(dev, channel);
> -		timeout = wait_for_completion_timeout(&channel->completion,
> -						      msecs_to_jiffies(5000));
> -		if (timeout == 0)
> +		time_left = wait_for_completion_timeout(&channel->completion,
> +							msecs_to_jiffies(5000));
> +		if (time_left == 0)
>  			v4l2_warn(&dev->v4l2_dev,
>  				  "channel %d: timeout while destroying\n",
>  				  channel->mcu_channel_id);
> @@ -2544,7 +2544,7 @@ static void allegro_destroy_channel(struct allegro_channel *channel)
>  static int allegro_create_channel(struct allegro_channel *channel)
>  {
>  	struct allegro_dev *dev = channel->dev;
> -	unsigned long timeout;
> +	unsigned long time_left;
>  
>  	if (channel_exists(channel)) {
>  		v4l2_warn(&dev->v4l2_dev,
> @@ -2595,9 +2595,9 @@ static int allegro_create_channel(struct allegro_channel *channel)
>  
>  	reinit_completion(&channel->completion);
>  	allegro_mcu_send_create_channel(dev, channel);
> -	timeout = wait_for_completion_timeout(&channel->completion,
> -					      msecs_to_jiffies(5000));
> -	if (timeout == 0)
> +	time_left = wait_for_completion_timeout(&channel->completion,
> +						msecs_to_jiffies(5000));
> +	if (time_left == 0)
>  		channel->error = -ETIMEDOUT;
>  	if (channel->error)
>  		goto err;
> -- 
> 2.43.0
> 
>
  
Wolfram Sang June 20, 2024, 7:52 p.m. UTC | #2
Hi Michael,

> There is another instance of wait_for_completion_timeout() in the
> driver, which uses tmo instead of timeout. Maybe this patch should
> change that, too.

Good point. I will update the patch (after waiting some more for review
comments).

Thanks,

   Wolfram
  

Patch

diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c
index da61f9beb6b4..4016aef5fdb9 100644
--- a/drivers/media/platform/allegro-dvt/allegro-core.c
+++ b/drivers/media/platform/allegro-dvt/allegro-core.c
@@ -2481,14 +2481,14 @@  static void allegro_mcu_interrupt(struct allegro_dev *dev)
 static void allegro_destroy_channel(struct allegro_channel *channel)
 {
 	struct allegro_dev *dev = channel->dev;
-	unsigned long timeout;
+	unsigned long time_left;
 
 	if (channel_exists(channel)) {
 		reinit_completion(&channel->completion);
 		allegro_mcu_send_destroy_channel(dev, channel);
-		timeout = wait_for_completion_timeout(&channel->completion,
-						      msecs_to_jiffies(5000));
-		if (timeout == 0)
+		time_left = wait_for_completion_timeout(&channel->completion,
+							msecs_to_jiffies(5000));
+		if (time_left == 0)
 			v4l2_warn(&dev->v4l2_dev,
 				  "channel %d: timeout while destroying\n",
 				  channel->mcu_channel_id);
@@ -2544,7 +2544,7 @@  static void allegro_destroy_channel(struct allegro_channel *channel)
 static int allegro_create_channel(struct allegro_channel *channel)
 {
 	struct allegro_dev *dev = channel->dev;
-	unsigned long timeout;
+	unsigned long time_left;
 
 	if (channel_exists(channel)) {
 		v4l2_warn(&dev->v4l2_dev,
@@ -2595,9 +2595,9 @@  static int allegro_create_channel(struct allegro_channel *channel)
 
 	reinit_completion(&channel->completion);
 	allegro_mcu_send_create_channel(dev, channel);
-	timeout = wait_for_completion_timeout(&channel->completion,
-					      msecs_to_jiffies(5000));
-	if (timeout == 0)
+	time_left = wait_for_completion_timeout(&channel->completion,
+						msecs_to_jiffies(5000));
+	if (time_left == 0)
 		channel->error = -ETIMEDOUT;
 	if (channel->error)
 		goto err;