diff mbox series

[v1] ImgTec powerVR DRM driver: Convert to use time_before macro

Message ID 20240821092121.16447-1-chenyufan@vivo.com (mailing list archive)
State New, archived
Headers show
Series [v1] ImgTec powerVR DRM driver: Convert to use time_before macro | expand

Commit Message

Chen Yufan Aug. 21, 2024, 9:21 a.m. UTC
Use time_before instead of direct subtraction for readability.

Signed-off-by: Chen Yufan <chenyufan@vivo.com>
---
 drivers/gpu/drm/imagination/pvr_ccb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Matt Coster Aug. 22, 2024, 11:41 a.m. UTC | #1
Hi Chen,

Thanks for the patch! Just a couple minor notes.

On 21/08/2024 10:21, Chen Yufan wrote:

> Subject: [PATCH v1] ImgTec powerVR DRM driver: Convert to use time_before macro

The prefix here should be based on the source path. For us, that's 
"drm/imagination:".

> Use time_before instead of direct subtraction for readability.

I think the real justification here is correctness. The code as it
currently exists is susceptible to overflow issues that are handled
correctly by the time_*() macros.

> Signed-off-by: Chen Yufan <chenyufan@vivo.com>

Please add a Fixes: tag as per [1].

> ---
>   drivers/gpu/drm/imagination/pvr_ccb.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/imagination/pvr_ccb.c b/drivers/gpu/drm/imagination/pvr_ccb.c
> index 4deeac7ed..b7d5f9ca3 100644
> --- a/drivers/gpu/drm/imagination/pvr_ccb.c
> +++ b/drivers/gpu/drm/imagination/pvr_ccb.c
> @@ -321,7 +321,7 @@ static int pvr_kccb_reserve_slot_sync(struct pvr_device *pvr_dev)
>   	bool reserved = false;
>   	u32 retries = 0;
>   
> -	while ((jiffies - start_timestamp) < (u32)RESERVE_SLOT_TIMEOUT ||
> +	while (time_before(jiffies, start_timestamp + (u32)RESERVE_SLOT_TIMEOUT) ||

You might as well drop the cast here too; it only seems to have existed here
as an attempt to correclty deal with overflow.

Cheers,
Matt

[1]: 
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes

>   	       retries < RESERVE_SLOT_MIN_RETRIES) {
>   		reserved = pvr_kccb_try_reserve_slot(pvr_dev);
>   		if (reserved)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/imagination/pvr_ccb.c b/drivers/gpu/drm/imagination/pvr_ccb.c
index 4deeac7ed..b7d5f9ca3 100644
--- a/drivers/gpu/drm/imagination/pvr_ccb.c
+++ b/drivers/gpu/drm/imagination/pvr_ccb.c
@@ -321,7 +321,7 @@  static int pvr_kccb_reserve_slot_sync(struct pvr_device *pvr_dev)
 	bool reserved = false;
 	u32 retries = 0;
 
-	while ((jiffies - start_timestamp) < (u32)RESERVE_SLOT_TIMEOUT ||
+	while (time_before(jiffies, start_timestamp + (u32)RESERVE_SLOT_TIMEOUT) ||
 	       retries < RESERVE_SLOT_MIN_RETRIES) {
 		reserved = pvr_kccb_try_reserve_slot(pvr_dev);
 		if (reserved)