]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm/filemap: return early if failed to allocate memory for split
authorKairui Song <kasong@tencent.com>
Tue, 1 Oct 2024 21:06:23 +0000 (05:06 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Oct 2024 14:30:02 +0000 (16:30 +0200)
commit de60fd8ddeda2b41fbe11df11733838c5f684616 upstream.

xas_split_alloc could fail with NOMEM, and in such case, it should abort
early instead of keep going and fail the xas_split below.

Link: https://lkml.kernel.org/r/20240416071722.45997-1-ryncsn@gmail.com
Link: https://lkml.kernel.org/r/20240415171857.19244-1-ryncsn@gmail.com
Link: https://lkml.kernel.org/r/20240415171857.19244-2-ryncsn@gmail.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Acked-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Stable-dep-of: 6758c1128ceb ("mm/filemap: optimize filemap folio adding")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/filemap.c

index 2662c416e7fa82f253de3dea9497df88894b0402..b9bad8328861687e7fd6760b44a4c61654b3ed5f 100644 (file)
@@ -872,9 +872,12 @@ noinline int __filemap_add_folio(struct address_space *mapping,
                unsigned int order = xa_get_order(xas.xa, xas.xa_index);
                void *entry, *old = NULL;
 
-               if (order > folio_order(folio))
+               if (order > folio_order(folio)) {
                        xas_split_alloc(&xas, xa_load(xas.xa, xas.xa_index),
                                        order, gfp);
+                       if (xas_error(&xas))
+                               goto error;
+               }
                xas_lock_irq(&xas);
                xas_for_each_conflict(&xas, entry) {
                        old = entry;