Merge tag 'kvm-riscv-6.4-1' of https://github.com/kvm-riscv/linux into HEAD
[linux-2.6-microblaze.git] / mm / filemap.c
index 2723104..a34abfe 100644 (file)
@@ -1836,7 +1836,7 @@ EXPORT_SYMBOL(page_cache_prev_miss);
  */
 
 /*
- * mapping_get_entry - Get a page cache entry.
+ * filemap_get_entry - Get a page cache entry.
  * @mapping: the address_space to search
  * @index: The page cache index.
  *
@@ -1847,7 +1847,7 @@ EXPORT_SYMBOL(page_cache_prev_miss);
  *
  * Return: The folio, swap or shadow entry, %NULL if nothing is found.
  */
-static void *mapping_get_entry(struct address_space *mapping, pgoff_t index)
+void *filemap_get_entry(struct address_space *mapping, pgoff_t index)
 {
        XA_STATE(xas, &mapping->i_pages, index);
        struct folio *folio;
@@ -1891,8 +1891,6 @@ out:
  *
  * * %FGP_ACCESSED - The folio will be marked accessed.
  * * %FGP_LOCK - The folio is returned locked.
- * * %FGP_ENTRY - If there is a shadow / swap / DAX entry, return it
- *   instead of allocating a new folio to replace it.
  * * %FGP_CREAT - If no page is present then a new page is allocated using
  *   @gfp and added to the page cache and the VM's LRU list.
  *   The page is returned locked and with an increased refcount.
@@ -1909,7 +1907,7 @@ out:
  *
  * If there is a page cache page, it is returned with an increased refcount.
  *
- * Return: The found folio or %NULL otherwise.
+ * Return: The found folio or an ERR_PTR() otherwise.
  */
 struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
                int fgp_flags, gfp_t gfp)
@@ -1917,12 +1915,9 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
        struct folio *folio;
 
 repeat:
-       folio = mapping_get_entry(mapping, index);
-       if (xa_is_value(folio)) {
-               if (fgp_flags & FGP_ENTRY)
-                       return folio;
+       folio = filemap_get_entry(mapping, index);
+       if (xa_is_value(folio))
                folio = NULL;
-       }
        if (!folio)
                goto no_page;
 
@@ -1930,7 +1925,7 @@ repeat:
                if (fgp_flags & FGP_NOWAIT) {
                        if (!folio_trylock(folio)) {
                                folio_put(folio);
-                               return NULL;
+                               return ERR_PTR(-EAGAIN);
                        }
                } else {
                        folio_lock(folio);
@@ -1969,7 +1964,7 @@ no_page:
 
                folio = filemap_alloc_folio(gfp, 0);
                if (!folio)
-                       return NULL;
+                       return ERR_PTR(-ENOMEM);
 
                if (WARN_ON_ONCE(!(fgp_flags & (FGP_LOCK | FGP_FOR_MMAP))))
                        fgp_flags |= FGP_LOCK;
@@ -1994,6 +1989,8 @@ no_page:
                        folio_unlock(folio);
        }
 
+       if (!folio)
+               return ERR_PTR(-ENOENT);
        return folio;
 }
 EXPORT_SYMBOL(__filemap_get_folio);
@@ -3263,7 +3260,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
         * Do we have something in the page cache already?
         */
        folio = filemap_get_folio(mapping, index);
-       if (likely(folio)) {
+       if (likely(!IS_ERR(folio))) {
                /*
                 * We found the page, so try async readahead before waiting for
                 * the lock.
@@ -3292,7 +3289,7 @@ retry_find:
                folio = __filemap_get_folio(mapping, index,
                                          FGP_CREAT|FGP_FOR_MMAP,
                                          vmf->gfp_mask);
-               if (!folio) {
+               if (IS_ERR(folio)) {
                        if (fpin)
                                goto out_retry;
                        filemap_invalidate_unlock_shared(mapping);
@@ -3643,7 +3640,7 @@ static struct folio *do_read_cache_folio(struct address_space *mapping,
                filler = mapping->a_ops->read_folio;
 repeat:
        folio = filemap_get_folio(mapping, index);
-       if (!folio) {
+       if (IS_ERR(folio)) {
                folio = filemap_alloc_folio(gfp, 0);
                if (!folio)
                        return ERR_PTR(-ENOMEM);