Cleanup the gotos in the function.
No functional change intended.
Signed-off-by: Gregory Price <gourry@gourry.net>
---
drivers/cxl/core/region_dax.c | 21 ++++++++-------------
drivers/cxl/cxl.h | 1 +
2 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/drivers/cxl/core/region_dax.c b/drivers/cxl/core/region_dax.c
index c8dd2bd1d9b9..49907c6c7620 100644
--- a/drivers/cxl/core/region_dax.c
+++ b/drivers/cxl/core/region_dax.c
@@ -81,29 +81,24 @@ static void cxlr_dax_unregister(void *_cxlr_dax)
int devm_cxl_add_dax_region(struct cxl_region *cxlr)
{
- struct cxl_dax_region *cxlr_dax;
- struct device *dev;
+ struct cxl_dax_region *cxlr_dax __free(put_cxl_dax_region) = NULL;
int rc;
cxlr_dax = cxl_dax_region_alloc(cxlr);
if (IS_ERR(cxlr_dax))
return PTR_ERR(cxlr_dax);
- dev = &cxlr_dax->dev;
- rc = dev_set_name(dev, "dax_region%d", cxlr->id);
+ rc = dev_set_name(&cxlr_dax->dev, "dax_region%d", cxlr->id);
if (rc)
- goto err;
+ return rc;
- rc = device_add(dev);
+ rc = device_add(&cxlr_dax->dev);
if (rc)
- goto err;
+ return rc;
- dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent),
- dev_name(dev));
+ dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(cxlr_dax->dev.parent),
+ dev_name(&cxlr_dax->dev));
return devm_add_action_or_reset(&cxlr->dev, cxlr_dax_unregister,
- cxlr_dax);
-err:
- put_device(dev);
- return rc;
+ no_free_ptr(cxlr_dax));
}
diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index 04c673e7cdb0..0b59008ea45a 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -803,6 +803,7 @@ DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_device(&_T->port.dev))
DEFINE_FREE(put_cxl_port, struct cxl_port *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev))
DEFINE_FREE(put_cxl_root_decoder, struct cxl_root_decoder *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->cxlsd.cxld.dev))
DEFINE_FREE(put_cxl_region, struct cxl_region *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev))
+DEFINE_FREE(put_cxl_dax_region, struct cxl_dax_region *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev))
int devm_cxl_enumerate_ports(struct cxl_memdev *cxlmd);
void cxl_bus_rescan(void);
--
2.47.3
On 2/11/26 1:42 PM, Gregory Price wrote:
> Cleanup the gotos in the function.
>
> No functional change intended.
>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> ---
> drivers/cxl/core/region_dax.c | 21 ++++++++-------------
> drivers/cxl/cxl.h | 1 +
> 2 files changed, 9 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/cxl/core/region_dax.c b/drivers/cxl/core/region_dax.c
> index c8dd2bd1d9b9..49907c6c7620 100644
> --- a/drivers/cxl/core/region_dax.c
> +++ b/drivers/cxl/core/region_dax.c
> @@ -81,29 +81,24 @@ static void cxlr_dax_unregister(void *_cxlr_dax)
>
> int devm_cxl_add_dax_region(struct cxl_region *cxlr)
> {
> - struct cxl_dax_region *cxlr_dax;
> - struct device *dev;
> + struct cxl_dax_region *cxlr_dax __free(put_cxl_dax_region) = NULL;
> int rc;
>
> cxlr_dax = cxl_dax_region_alloc(cxlr);
The typical __cleanup() pattern is to move the variable declaration here in order to minimize unintended issues between declare and check.
> if (IS_ERR(cxlr_dax))
> return PTR_ERR(cxlr_dax);
>
> - dev = &cxlr_dax->dev;
Given that this local var is used multiple times, maybe we should keep it?
DJ
> - rc = dev_set_name(dev, "dax_region%d", cxlr->id);
> + rc = dev_set_name(&cxlr_dax->dev, "dax_region%d", cxlr->id);
> if (rc)
> - goto err;
> + return rc;
>
> - rc = device_add(dev);
> + rc = device_add(&cxlr_dax->dev);
> if (rc)
> - goto err;
> + return rc;
>
> - dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent),
> - dev_name(dev));
> + dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(cxlr_dax->dev.parent),
> + dev_name(&cxlr_dax->dev));
>
> return devm_add_action_or_reset(&cxlr->dev, cxlr_dax_unregister,
> - cxlr_dax);
> -err:
> - put_device(dev);
> - return rc;
> + no_free_ptr(cxlr_dax));
> }
> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> index 04c673e7cdb0..0b59008ea45a 100644
> --- a/drivers/cxl/cxl.h
> +++ b/drivers/cxl/cxl.h
> @@ -803,6 +803,7 @@ DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_device(&_T->port.dev))
> DEFINE_FREE(put_cxl_port, struct cxl_port *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev))
> DEFINE_FREE(put_cxl_root_decoder, struct cxl_root_decoder *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->cxlsd.cxld.dev))
> DEFINE_FREE(put_cxl_region, struct cxl_region *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev))
> +DEFINE_FREE(put_cxl_dax_region, struct cxl_dax_region *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev))
>
> int devm_cxl_enumerate_ports(struct cxl_memdev *cxlmd);
> void cxl_bus_rescan(void);
On Tue, Feb 17, 2026 at 04:55:13PM -0700, Dave Jiang wrote:
>
>
> On 2/11/26 1:42 PM, Gregory Price wrote:
> > Cleanup the gotos in the function.
> >
> > No functional change intended.
> >
> > Signed-off-by: Gregory Price <gourry@gourry.net>
> > ---
> > drivers/cxl/core/region_dax.c | 21 ++++++++-------------
> > drivers/cxl/cxl.h | 1 +
> > 2 files changed, 9 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/cxl/core/region_dax.c b/drivers/cxl/core/region_dax.c
> > index c8dd2bd1d9b9..49907c6c7620 100644
> > --- a/drivers/cxl/core/region_dax.c
> > +++ b/drivers/cxl/core/region_dax.c
> > @@ -81,29 +81,24 @@ static void cxlr_dax_unregister(void *_cxlr_dax)
> >
> > int devm_cxl_add_dax_region(struct cxl_region *cxlr)
> > {
> > - struct cxl_dax_region *cxlr_dax;
> > - struct device *dev;
> > + struct cxl_dax_region *cxlr_dax __free(put_cxl_dax_region) = NULL;
> > int rc;
> >
> > cxlr_dax = cxl_dax_region_alloc(cxlr);
>
> The typical __cleanup() pattern is to move the variable declaration here in order to minimize unintended issues between declare and check.
>
Ah, relatively new pattern for me, i'll clean it up
> > if (IS_ERR(cxlr_dax))
> > return PTR_ERR(cxlr_dax);
> >
> > - dev = &cxlr_dax->dev;
>
> Given that this local var is used multiple times, maybe we should keep it?
>
Fair, will re-spin claned up
~Gregory
© 2016 - 2026 Red Hat, Inc.