UPSTREAM: mm: prevent derefencing NULL ptr in pfn_section_valid()

Commit 5ec8e8ea8b77 ("mm/sparsemem: fix race in accessing
memory_section->usage") changed pfn_section_valid() to add a READ_ONCE()
call around "ms->usage" to fix a race with section_deactivate() where
ms->usage can be cleared.  The READ_ONCE() call, by itself, is not enough
to prevent NULL pointer dereference.  We need to check its value before
dereferencing it.

Link: https://lkml.kernel.org/r/20240626001639.1350646-1-longman@redhat.com
Fixes: 5ec8e8ea8b77 ("mm/sparsemem: fix race in accessing memory_section->usage")
Signed-off-by: Waiman Long <longman@redhat.com>
Cc: Charan Teja Kalla <quic_charante@quicinc.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 82f0b6f041fad768c28b4ad05a683065412c226e)

BUG=None
TEST=None

Signed-off-by: Linux Patches Robot <linux-patches-robot@chromeos-missing-patches.google.com.iam.gserviceaccount.com>
Change-Id: Ia8ea7789889a6d7cbfeffdd434e043bbbe4cf220
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/5693220
Commit-Queue: Tzung-Bi Shih <tzungbi@chromium.org>
Reviewed-by: Sean Paul <sean@poorly.run>
Reviewed-by: Tzung-Bi Shih <tzungbi@chromium.org>
1 file changed