Claude review: mm/zone_device: Do not touch device folio after calling ->folio_free()

Claude Code Review Bot
2026-04-11T23:15:48Z

Overall Series Review

Subject: mm/zone_device: Do not touch device folio after calling ->folio_free()
Author: Matthew Brost <matthew.brost@intel.com>
Patches: 2
Reviewed: 2026-04-12T09:15:48.772101

---

This is a single-patch fix for a use-after-free bug in the MM zone_device code (`mm/memremap.c`). The bug is straightforward and the fix is correct: after `pgmap->ops->folio_free(folio)` is called, the folio may be immediately reallocated by the driver with a different order, making subsequent access to `folio->pgmap` unsafe. The local stack variable `pgmap` (captured at function entry on line 418) should be used instead.

The patch is well-motivated with a real crash trace showing a GPF at `free_zone_device_folio+0x149/0x240` from a non-canonical address (`0x900000000000000`), consistent with reading stale/corrupted data from a reallocated folio.

**Verdict: The patch looks correct and should be applied.**

---
Generated by Claude Code Patch Reviewer