Re: [PATCH v2 1/4] mm, swap: Fix potential NULL dereference when trying a sleep table allocation

From: Andrew Morton

Date: Fri Aug 28 2026 - 21:04:04 EST


On Thu, 27 Aug 2026 17:10:54 +0800 Kairui Song <ryncsn@xxxxxxxxx> wrote:

> > --- a/mm/swapfile.c
> > +++ b/mm/swapfile.c
> > @@ -466,8 +466,6 @@ static int swap_cluster_alloc_table(struct swap_cluster_info *ci, gfp_t gfp)
> > if (!table)
> > return -ENOMEM;
> >
> > - rcu_assign_pointer(ci->table, table);
> > -
> > #ifdef CONFIG_MEMCG
> > if (!mem_cgroup_disabled()) {
> > VM_WARN_ON_ONCE(ci->memcg_table);
> > @@ -487,6 +485,12 @@ static int swap_cluster_alloc_table(struct swap_cluster_info *ci, gfp_t gfp)
> > return -ENOMEM;
> > }
> > #endif
> > +
> > + /*
> > + * Make tables visible to cluster_is_usable() after everything is
> > + * ready.
> > + */
> > + rcu_assign_pointer(ci->table, table);
>
> Hmm, but for the error paths above, they will leak the new allocated table?

Sashiko thinks so ;)

It also might have found a pre-existing data-race which seems
sufficiently on-topic for this patchset?

https://sashiko.dev/#/patchset/20260820115505.20027-1-shikemeng@xxxxxxxxxxxxxxx