diff mbox series

[1/1] drm: arm: display: komeda: komeda_crtc: use 'time_left' variable with wait_for_completion_timeout()

Message ID 20240502210252.11617-2-wsa+renesas@sang-engineering.com (mailing list archive)
State New, archived
Headers show
Series [1/1] drm: arm: display: komeda: komeda_crtc: use 'time_left' variable with wait_for_completion_timeout() | expand

Commit Message

Wolfram Sang May 2, 2024, 9:02 p.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.

Fix to the proper variable type 'unsigned long' while here.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Liviu Dudau May 3, 2024, 11:55 a.m. UTC | #1
On Thu, May 02, 2024 at 11:02:53PM +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.
> 
> Fix to the proper variable type 'unsigned long' while here.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
> index 2c661f28410e..c867acb737d6 100644
> --- a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
> +++ b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
> @@ -294,7 +294,7 @@ komeda_crtc_flush_and_wait_for_flip_done(struct komeda_crtc *kcrtc,
>  	struct komeda_dev *mdev = kcrtc->master->mdev;
>  	struct completion *flip_done;
>  	struct completion temp;
> -	int timeout;
> +	unsigned long time_left;
>  
>  	/* if caller doesn't send a flip_done, use a private flip_done */
>  	if (input_flip_done) {
> @@ -308,8 +308,8 @@ komeda_crtc_flush_and_wait_for_flip_done(struct komeda_crtc *kcrtc,
>  	mdev->funcs->flush(mdev, kcrtc->master->id, 0);
>  
>  	/* wait the flip take affect.*/
> -	timeout = wait_for_completion_timeout(flip_done, HZ);
> -	if (timeout == 0) {
> +	time_left = wait_for_completion_timeout(flip_done, HZ);
> +	if (time_left == 0) {

Honestly, if the name of the variable is confusing I would get rid of it completely. Can you
send a patch that removes the timeout variable and here just does:

	if (wait_for_completion_timeout(flip_done, HZ) == 0) {

Thanks,
Liviu

>  		DRM_ERROR("wait pipe%d flip done timeout\n", kcrtc->master->id);
>  		if (!input_flip_done) {
>  			unsigned long flags;
> -- 
> 2.43.0
>
Wolfram Sang May 5, 2024, 1:25 p.m. UTC | #2
> >  	/* wait the flip take affect.*/
> > -	timeout = wait_for_completion_timeout(flip_done, HZ);
> > -	if (timeout == 0) {
> > +	time_left = wait_for_completion_timeout(flip_done, HZ);
> > +	if (time_left == 0) {
> 
> Honestly, if the name of the variable is confusing I would get rid of it completely. Can you
> send a patch that removes the timeout variable and here just does:
> 
> 	if (wait_for_completion_timeout(flip_done, HZ) == 0) {

Can do. I think, though, that using 'time_left' is still easier to
understand. However, this code block is simple enough and it is your
driver, so I'll send v2 later.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
index 2c661f28410e..c867acb737d6 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
@@ -294,7 +294,7 @@  komeda_crtc_flush_and_wait_for_flip_done(struct komeda_crtc *kcrtc,
 	struct komeda_dev *mdev = kcrtc->master->mdev;
 	struct completion *flip_done;
 	struct completion temp;
-	int timeout;
+	unsigned long time_left;
 
 	/* if caller doesn't send a flip_done, use a private flip_done */
 	if (input_flip_done) {
@@ -308,8 +308,8 @@  komeda_crtc_flush_and_wait_for_flip_done(struct komeda_crtc *kcrtc,
 	mdev->funcs->flush(mdev, kcrtc->master->id, 0);
 
 	/* wait the flip take affect.*/
-	timeout = wait_for_completion_timeout(flip_done, HZ);
-	if (timeout == 0) {
+	time_left = wait_for_completion_timeout(flip_done, HZ);
+	if (time_left == 0) {
 		DRM_ERROR("wait pipe%d flip done timeout\n", kcrtc->master->id);
 		if (!input_flip_done) {
 			unsigned long flags;