Re: [PATCH v2 2/3] mm, swap: distinguish a malformed swap entry from a dying device
From: Kairui Song
Date: Tue Aug 18 2026 - 05:08:23 EST
On Thu, Aug 13, 2026 at 03:02:21AM +0800, Breno Leitao wrote:
> get_swap_device() returns NULL for two different things: an entry whose
> type names no swap device or whose offset is past the end of one, and a
> device that swapoff is taking away. The first never becomes valid, the
> second does, and callers cannot tell them apart.
>
> Return ERR_PTR(-EIO) for the two malformed cases and keep NULL for
> swapoff. copy_nonpresent_pte() already reports -EIO for the same
> corruption on the fork path.
>
> Callers bail out on failure either way, so switch them to
> IS_ERR_OR_NULL() and clear si where the cleanup path would otherwise
> put an ERR_PTR. No functional change.
>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> ---
> mm/memory.c | 6 ++++--
> mm/mincore.c | 2 +-
> mm/shmem.c | 2 +-
> mm/swap_state.c | 4 ++--
> mm/swapfile.c | 14 +++++++++-----
> mm/userfaultfd.c | 3 ++-
> mm/zswap.c | 2 +-
> 7 files changed, 20 insertions(+), 13 deletions(-)
>
Looks good, thanks!
Acked-by: Kairui Song <kasong@xxxxxxxxxxx>