Handle vblank->enabled in a separate branch before handling the
opposite case. Prepares the code for estimating the vblank timeout
while vblanking is disabled. No functional changes.

Signed-off-by: Thomas Zimmermann <[email protected]>
---
 drivers/gpu/drm/drm_vblank.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 03b07e3c2598..cecaef98aa52 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -2306,8 +2306,6 @@ bool drm_crtc_vblank_get_vblank_timeout(struct drm_crtc 
*crtc, ktime_t *vblank_t
        struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc);
        struct drm_vblank_crtc_timer *vtimer = &vblank->vblank_timer;
        const struct drm_display_mode *mode;
-       u64 cur_count;
-       ktime_t cur_time;
        s64 framedur_ns;
        s64 activedur_ns;
 
@@ -2316,24 +2314,28 @@ bool drm_crtc_vblank_get_vblank_timeout(struct drm_crtc 
*crtc, ktime_t *vblank_t
        else
                mode = &crtc->hwmode;
 
-       if (!READ_ONCE(vblank->enabled))
-               return false;
+       if (READ_ONCE(vblank->enabled)) {
+               ktime_t cur_time;
+               u64 cur_count;
 
-       /*
-        * A concurrent vblank timeout could update the expires field before
-        * we compare it with the vblank time. Hence we'd compare the old
-        * expiry time to the new vblank time; deducing the timer had already
-        * expired. Reread until we get consistent values from both fields.
-        */
-       do {
-               cur_count = drm_crtc_vblank_count_and_time(crtc, &cur_time);
-               *vblank_time = READ_ONCE(vtimer->timer.node.expires);
-       } while (cur_count != drm_crtc_vblank_count_and_time(crtc, &cur_time));
+               /*
+                * A concurrent vblank timeout could update the expires field 
before
+                * we compare it with the vblank time. Hence we'd compare the 
old
+                * expiry time to the new vblank time; deducing the timer had 
already
+                * expired. Reread until we get consistent values from both 
fields.
+                */
+               do {
+                       cur_count = drm_crtc_vblank_count_and_time(crtc, 
&cur_time);
+                       *vblank_time = READ_ONCE(vtimer->timer.node.expires);
+               } while (cur_count != drm_crtc_vblank_count_and_time(crtc, 
&cur_time));
 
-       if (drm_WARN_ON(dev, !ktime_compare(*vblank_time, cur_time)))
-               return false; /* Already expired */
+               if (drm_WARN_ON(dev, !ktime_compare(*vblank_time, cur_time)))
+                       return false; /* already expired */
 
-       framedur_ns = vblank->framedur_ns;
+               framedur_ns = vblank->framedur_ns;
+       } else {
+               return false;
+       }
 
        /*
         * To prevent races we rolled the hrtimer forward before we did any
-- 
2.54.0

Reply via email to