Re: [PATCH v2 07/15] mm, swap: tidy up swap device and cluster info helpers

From: David Hildenbrand
Date: Mon Sep 08 2025 - 08:21:33 EST


On 05.09.25 21:13, Kairui Song wrote:
From: Kairui Song <kasong@xxxxxxxxxxx>

swp_swap_info is the most commonly used helper for retrieving swap info.
It has an internal check that may lead to a NULL return value, but
almost none of its caller checks the return value, making the internal
check pointless. In fact, most of these callers already ensured the
entry is valid and never expect a NULL value.

Tidy this up and shorten the name. If the caller can make sure the

"Tidy this up and improve the function names." ?

swap entry/type is valid and the device is pinned, use the new introduced
__swap_entry_to_info/__swap_type_to_info instead. They have more debug
sanity checks and lower overhead as they are inlined.

Callers that may expect a NULL value should use
swap_entry_to_info/swap_type_to_info instead.

No feature change. The rearranged codes should have had no effect, or
they should have been hitting NULL de-ref bugs already. Only some new
sanity checks are added so potential issues may show up in debug build.

The new helpers will be frequently used with swap table later when working
with swap cache folios. A locked swap cache folio ensures the entries are
valid and stable so these helpers are very helpful.

Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
Acked-by: Chris Li <chrisl@xxxxxxxxxx>
Reviewed-by: Barry Song <baohua@xxxxxxxxxx>
---

Acked-by: David Hildenbrand <david@xxxxxxxxxx>

--
Cheers

David / dhildenb