static void cxl_region_release(struct device *dev)
 {
+       struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev->parent);
        struct cxl_region *cxlr = to_cxl_region(dev);
+       int id = atomic_read(&cxlrd->region_id);
+
+       /*
+        * Try to reuse the recently idled id rather than the cached
+        * next id to prevent the region id space from increasing
+        * unnecessarily.
+        */
+       if (cxlr->id < id)
+               if (atomic_try_cmpxchg(&cxlrd->region_id, &id, cxlr->id)) {
+                       memregion_free(id);
+                       goto out;
+               }
 
        memregion_free(cxlr->id);
+out:
+       put_device(dev->parent);
        kfree(cxlr);
 }
 
        device_initialize(dev);
        lockdep_set_class(&dev->mutex, &cxl_region_key);
        dev->parent = &cxlrd->cxlsd.cxld.dev;
+       /*
+        * Keep root decoder pinned through cxl_region_release to fixup
+        * region id allocations
+        */
+       get_device(dev->parent);
        device_set_pm_not_required(dev);
        dev->bus = &cxl_bus_type;
        dev->type = &cxl_region_type;