*
  * Return: The index of the gap if found, otherwise an index outside the
  * range specified (in which case 'return - index >= max_scan' will be true).
- * In the rare case of index wrap-around, 0 will be returned.  0 will also
- * be returned if index == 0 and there is a gap at the index.  We can not
- * wrap-around if passed index == 0.
+ * In the rare case of index wrap-around, 0 will be returned.
  */
 pgoff_t page_cache_next_miss(struct address_space *mapping,
                             pgoff_t index, unsigned long max_scan)
        while (max_scan--) {
                void *entry = xas_next(&xas);
                if (!entry || xa_is_value(entry))
-                       return xas.xa_index;
-               if (xas.xa_index == 0 && index != 0)
-                       return xas.xa_index;
+                       break;
+               if (xas.xa_index == 0)
+                       break;
        }
 
-       /* No gaps in range and no wrap-around, return index beyond range */
-       return xas.xa_index + 1;
+       return xas.xa_index;
 }
 EXPORT_SYMBOL(page_cache_next_miss);
 
  *
  * Return: The index of the gap if found, otherwise an index outside the
  * range specified (in which case 'index - return >= max_scan' will be true).
- * In the rare case of wrap-around, ULONG_MAX will be returned.  ULONG_MAX
- * will also be returned if index == ULONG_MAX and there is a gap at the
- * index.  We can not wrap-around if passed index == ULONG_MAX.
+ * In the rare case of wrap-around, ULONG_MAX will be returned.
  */
 pgoff_t page_cache_prev_miss(struct address_space *mapping,
                             pgoff_t index, unsigned long max_scan)
        while (max_scan--) {
                void *entry = xas_prev(&xas);
                if (!entry || xa_is_value(entry))
-                       return xas.xa_index;
-               if (xas.xa_index == ULONG_MAX && index != ULONG_MAX)
-                       return xas.xa_index;
+                       break;
+               if (xas.xa_index == ULONG_MAX)
+                       break;
        }
 
-       /* No gaps in range and no wrap-around, return index beyond range */
-       return xas.xa_index - 1;
+       return xas.xa_index;
 }
 EXPORT_SYMBOL(page_cache_prev_miss);