Re: [PATCH v2 2/3] mm, swap: distinguish a malformed swap entry from a dying device

Kairui Song <[email protected]>
Newsgroups gmane.linux.kernel,gmane.linux.kernel.mm
Message-ID <aoQFzEgZP_ZuSP3e@KASONG-MC4>
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 <[email protected]>
> ---
>  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 <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.