Re: [PATCH v2 2/2] cxl/region: Use __free(put_device) in find_pos_and_ways()
Alison Schofield <[email protected]> Fri, 24 Jul 2026 14:57:30 -0700
| Newsgroups | org.kernel.vger.linux-cxl |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Jul 22, 2026 at 12:56:48AM +0100, Jonathan Cameron wrote: > On Tue, 21 Jul 2026 10:37:04 -0700 > Alison Schofield <[email protected]> wrote: > > > Use __free(put_device) for the switch decoder reference returned by > > device_find_child() instead of releasing it with an open-coded > > put_device(). > > > > This matches the scoped device reference handling used elsewhere in > > the file. > > > > Suggested-by: Li Ming <[email protected]> > > Signed-off-by: Alison Schofield <[email protected]> > > --- > > > > This is a new patch added in series after the UAF fixup in patch 1/2. > > > > > > drivers/cxl/core/region.c | 4 +--- > > 1 file changed, 1 insertion(+), 3 deletions(-) > > > > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > > index c86dd9d55e93..4d7d96d03ece 100644 > > --- a/drivers/cxl/core/region.c > > +++ b/drivers/cxl/core/region.c > > @@ -1911,9 +1911,9 @@ static int match_switch_decoder_by_range(struct device *dev, > > static int find_pos_and_ways(struct cxl_port *port, struct range *range, > > int *pos, int *ways) > > { > > + struct device *dev __free(put_device) = NULL; > > No to this. See rules in cleanup.h. > This is the path to grumpy Linus if he happens to spot it. > > Short story is declaration and destructor must be in same statement > as the constructor. Here that means > > struct device *dev __free(put_device) = > device_find_child(&parent->dev, range, match_switch_decoder_by_range); > > I would go long on that second line given it's only a bit beyond 80 chars > and the two lines are horrible enough to read without becoming 3. Thanks for the cleanup.h pointer. In v3 dev is declared and assigned in a single statement after the !parent check, formatted as you suggested above. -- Alison