linux/drivers/dax
Davidlohr Bueso ef4fc53898 dax/kmem: account for partial discontiguous resource upon removal
[ Upstream commit 8aa442cfce ]

When dev_dax_kmem_probe() partially succeeds (at least one range is
mapped) but a subsequent range fails request_mem_region() or
add_memory_driver_managed(), the probe silently continues, ultimately
returning success, but with the corresponding range resource NULL'ed out.

dev_dax_kmem_remove() iterates over all dax_device ranges regardless of if
the underlying resource exists.  When remove_memory() is called later, it
returns 0 because the memory was never added which causes
dev_dax_kmem_remove() to incorrectly assume the (nonexistent) resource can
be removed and attempts cleanup on a NULL pointer.

Fix this by skipping these ranges altogether, noting that these cases are
considered success, such that the cleanup is still reached when all
actually-added ranges are successfully removed.

Link: https://lore.kernel.org/20260223201516.1517657-1-dave@stgolabs.net
Fixes: 60e93dc097 ("device-dax: add dis-contiguous resource support")
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Reviewed-by: Ben Cheatham <benjamin.cheatham@amd.com>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2026-07-24 15:51:31 +02:00
..
hmem devdax: Fix soft-reservation memory description 2022-09-28 11:11:57 +02:00
pmem libnvdimm: Make remove callback return void 2021-02-16 19:35:29 -08:00
bus.c dax: Introduce alloc_dev_dax_id() 2023-07-23 13:47:17 +02:00
bus.h dax-device: Make remove callback return void 2021-02-16 19:45:13 -08:00
dax-private.h dax: Introduce alloc_dev_dax_id() 2023-07-23 13:47:17 +02:00
device.c fs: remove noop_set_page_dirty() 2021-06-29 10:53:48 -07:00
Kconfig mm: fix phys_to_target_node() and memory_add_physaddr_to_nid() exports 2020-11-22 10:48:22 -08:00
kmem.c dax/kmem: account for partial discontiguous resource upon removal 2026-07-24 15:51:31 +02:00
Makefile ACPI: HMAT: refactor hmat_register_target_device to hmem_register_device 2020-10-13 18:38:27 -07:00
super.c dax: make sure inodes are flushed before destroy cache 2022-04-08 14:23:31 +02:00