Re: [PATCH] cxl/region: Fix a race bug in delete_region_store

From: Jonathan Cameron

Date: Mon Mar 09 2026 - 08:02:45 EST


On Sun, 8 Mar 2026 14:59:58 -0400
Sungwoo Kim <iam@xxxxxxxxxxxx> wrote:

> A race exists when two concurrent sysfs writes to delete_region specify
> the same region name. Both calls succeed in cxl_find_region_by_name()
> (which only does device_find_child_by_name and takes a reference), and
> both then proceed to call devm_release_action(). The first call atomically
> removes and releases the devres entry successfully. The second call finds
> no matching entry, causing devres_release() to return -ENOENT, which trips
> the WARN_ON.
>
> Fix this by replacing devm_release_action() with devm_remove_action_nowarn()
> followed by a manual call to unregister_region(). devm_remove_action_nowarn()
> removes the devres tracking entry and returns an error code.

Naive question (or just me being lazy). Why can't we take the
write lock on cxl_rwsem.region?

Jonathan