{
        struct sg_table *pages;
 
-       GEM_BUG_ON(i915_gem_object_has_pinned_pages(obj));
-
        if (unlikely(obj->mm.madv != I915_MADV_WILLNEED)) {
                DRM_DEBUG("Attempting to obtain a purgeable object\n");
                return -EFAULT;
                return err;
 
        if (unlikely(IS_ERR_OR_NULL(obj->mm.pages))) {
+               GEM_BUG_ON(i915_gem_object_has_pinned_pages(obj));
+
                err = ____i915_gem_object_get_pages(obj);
                if (err)
                        goto unlock;
 
        if (!atomic_inc_not_zero(&obj->mm.pages_pin_count)) {
                if (unlikely(IS_ERR_OR_NULL(obj->mm.pages))) {
+                       GEM_BUG_ON(i915_gem_object_has_pinned_pages(obj));
+
                        ret = ____i915_gem_object_get_pages(obj);
                        if (ret)
                                goto err_unlock;