drm/msm: Avoid rounding up to one jiffy
PATCH 1/1 drm/msm: Avoid rounding up to one jiffy
From: Rob Clark <[email protected]>
If userspace is trying to achieve a timeout of zero, let 'em have it. Only round up if the timeout is greater than zero.
Fixes 4969bccd5f4e ("drm/msm: Avoid rounding down to zero jiffies")
Signed-off-by Rob Clark <[email protected]>
--- drivers/gpu/drm/msm/msm_drv.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/msm/msm_drv.h +4 -6
@@ -537,16 +537,14 @@ static inline int align_pitch(int width, int bpp)static inline unsigned long timeout_to_jiffies (const ktime_t *timeout) {ktime_t now =ktime_get (); -s64 remaining_jiffies; -if (ktime_compare (*timeout, now) <0 ) { - remaining_jiffies =0 ; +if (ktime_compare (*timeout, now) <=0 ) { +return 0 ; }else {ktime_t rem =ktime_sub (*timeout, now); - remaining_jiffies =ktime_divns (rem,NSEC_PER_SEC /HZ ); +s64 remaining_jiffies =ktime_divns (rem,NSEC_PER_SEC /HZ ); +return clamp (remaining_jiffies,1LL , (s64 )INT_MAX ); } - -return clamp (remaining_jiffies,1LL , (s64 )INT_MAX ); }/* Driver helpers */
Signature · 1 line
2.47.1
Quoted 16 lines · Rob Clark
From: Rob Clark <[email protected]>
If userspace is trying to achieve a timeout of zero, let 'em have it. Only round up if the timeout is greater than zero.
Fixes 4969bccd5f4e ("drm/msm: Avoid rounding down to zero jiffies")Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/msm/msm_drv.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/gpu/drm/msm/msm_drv.h +0
-0
drivers/gpu/drm/msm/msm_drv.h static inline int align_pitch(int width, int bpp) · line 543
Quoted 10 lines
drivers/gpu/drm/msm/msm_drv.h +2
-3@@ -537,16 +537,14 @@ static inline int align_pitch(int width, int bpp)static inline unsigned long timeout_to_jiffies (const ktime_t *timeout) {ktime_t now =ktime_get (); -s64 remaining_jiffies; -if (ktime_compare (*timeout, now) <0 ) { - remaining_jiffies =0 ; +if (ktime_compare (*timeout, now) <=0 ) { +return 0 ; }else {
For readability, we can now remove 'else' block and de-nest rest of the code.
-Akhil
Quoted 10 lines
drivers/gpu/drm/msm/msm_drv.h +2
-3ktime_t rem =ktime_sub (*timeout, now); - remaining_jiffies =ktime_divns (rem,NSEC_PER_SEC /HZ ); +s64 remaining_jiffies =ktime_divns (rem,NSEC_PER_SEC /HZ ); +return clamp (remaining_jiffies,1LL , (s64 )INT_MAX ); } - -return clamp (remaining_jiffies,1LL , (s64 )INT_MAX ); }/* Driver helpers */