Re: [PATCH v7 1/4] iio: backend: use __free(fwnode_handle) for automatic cleanup
From: Jonathan Cameron
Date: Sat Mar 21 2026 - 08:03:46 EST
On Sat, 21 Mar 2026 12:01:51 +0200
Antoniu Miclaus <antoniu.miclaus@xxxxxxxxxx> wrote:
> Convert __devm_iio_backend_fwnode_get() to use the __free(fwnode_handle)
> cleanup attribute for the fwnode_back variable, removing the need for
> manual fwnode_handle_put() calls. Move the declaration closer to its
> first use, narrowing its scope.
>
> No functional change.
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
> Reviewed-by: Nuno Sá <nuno.sa@xxxxxxxxxx>
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@xxxxxxxxxx>
This patch stands on it's own as a good improvement so applied to the testing
branch of iio.git. If we end up going to a v8 just don't include this
patch. (I'm easily confused ;)
Thanks,
Jonathan
> ---
> Changes in v7:
> - No changes
>
> drivers/iio/industrialio-backend.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
> index 447b694d6d5f..58f7e1426095 100644
> --- a/drivers/iio/industrialio-backend.c
> +++ b/drivers/iio/industrialio-backend.c
> @@ -952,7 +952,6 @@ EXPORT_SYMBOL_NS_GPL(iio_backend_data_transfer_addr, "IIO_BACKEND");
> static struct iio_backend *__devm_iio_backend_fwnode_get(struct device *dev, const char *name,
> struct fwnode_handle *fwnode)
> {
> - struct fwnode_handle *fwnode_back;
> struct iio_backend *back;
> unsigned int index;
> int ret;
> @@ -967,7 +966,8 @@ static struct iio_backend *__devm_iio_backend_fwnode_get(struct device *dev, con
> index = 0;
> }
>
> - fwnode_back = fwnode_find_reference(fwnode, "io-backends", index);
> + struct fwnode_handle *fwnode_back __free(fwnode_handle) =
> + fwnode_find_reference(fwnode, "io-backends", index);
> if (IS_ERR(fwnode_back))
> return dev_err_cast_probe(dev, fwnode_back,
> "Cannot get Firmware reference\n");
> @@ -977,7 +977,6 @@ static struct iio_backend *__devm_iio_backend_fwnode_get(struct device *dev, con
> if (!device_match_fwnode(back->dev, fwnode_back))
> continue;
>
> - fwnode_handle_put(fwnode_back);
> ret = __devm_iio_backend_get(dev, back);
> if (ret)
> return ERR_PTR(ret);
> @@ -988,7 +987,6 @@ static struct iio_backend *__devm_iio_backend_fwnode_get(struct device *dev, con
> return back;
> }
>
> - fwnode_handle_put(fwnode_back);
> return ERR_PTR(-EPROBE_DEFER);
> }
>