Re: [PATCH v5 2/8] mm: factor zone-device page init helpers out of __init_zone_device_page
"Li Zhe" <[email protected]>
| Newsgroups | org.kernel.vger.linux-arch,org.kernel.vger.linux-hardening,org.kernel.vger.linux-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 6 Jul 2026 15:47:43 +0200, [email protected] wrote: > On 7/6/26 13:50, Li Zhe wrote: > > On Mon, Jul 6, 2026 at 11:13:45AM +0200, [email protected] wrote: > > > >>> +static inline bool pagemap_resets_refcount(const struct dev_pagemap *pgmap) > >>> +{ > >>> + /* > >>> + * MEMORY_DEVICE_GENERIC pages regain a refcount of 1 in the free > >>> + * path. The remaining ZONE_DEVICE types start from 0 here and raise > >>> + * the count again when the allocator or driver hands the page out. > >>> + */ > >>> + switch (pgmap->type) { > >>> + case MEMORY_DEVICE_FS_DAX: > >>> + case MEMORY_DEVICE_PRIVATE: > >>> + case MEMORY_DEVICE_COHERENT: > >>> + case MEMORY_DEVICE_PCI_P2PDMA: > >>> + return false; > >>> + case MEMORY_DEVICE_GENERIC: > >>> + return true; > >>> + default: > >>> + WARN_ONCE(1, "Unknown memory type!"); > >>> + return true; > >> > >> Wouldn't the compiler warn if we would define a new type but forgot to update it > >> here? We're using an enum, and I thought the compiler would bail out in that case. > >> > >> Or are we scared of some other garbage ending up in there? > >> > >> Apart from that LGTM. > > > > Thanks. > > > > I will drop the default case in v6 so a newly added enum memory_type > > value is easier to catch during build review. > > > > I will move the WARN_ONCE() after the switch so we still keep a > > runtime guard in case some invalid value ever shows up there. > > If the compiler complains, we won't need the WARN_ONCE(). Thanks. I will drop the WARN_ONCE() as well in v6. Thanks, Zhe