Re: [PATCH 07/10] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback
From: Andy Shevchenko
Date: Thu Nov 19 2026 - 12:35:06 EST
On Thu, Nov 19, 2026 at 03:30:40PM +0000, Lee Jones wrote:
> struct tm5_aux_dev_wrapper embeds a reference-counted struct
> auxiliary_device, whose memory must be released from its dev.release
> callback once the final device reference is dropped.
>
> Allocating the wrapper with devm_kzalloc_obj() on the parent ADC device
> and providing an empty adc5_gen3_aux_device_release() causes parent
> devres teardown to free the wrapper immediately after
> auxiliary_device_uninit(), even if external references to the embedded
> struct device are still held.
>
> Allocate the wrapper with kzalloc_obj(), release it from
> adc5_gen3_aux_device_release(), and unwind cleanly on early error paths
> in adc5_gen3_add_aux_tm_device().
...
> #include <linux/platform_device.h>
> #include <linux/property.h>
> #include <linux/regmap.h>
> +#include <linux/slab.h>
> #include <linux/types.h>
> #include <linux/unaligned.h>
> +static void adc5_gen3_aux_device_release(struct device *dev)
> +{
> + struct tm5_aux_dev_wrapper *aux_device =
> + container_of(dev, struct tm5_aux_dev_wrapper, aux_dev.dev);
container_of() is also in a separate header, id est container_of.h.
> + kfree(aux_device);
> +}
...
> ret = auxiliary_device_add(&aux_device->aux_dev);
> - if (ret)
> + if (ret) {
> + devm_release_action(adc->dev, adc5_gen3_uninit_aux,
> + &aux_device->aux_dev);
Oh, this is interesting... Usually the release devm_*() calls point
to a misdesign somewhere. But I haven't checked the twisted flow of
this code.
> return ret;
> + }
> +
> ret = devm_add_action_or_reset(adc->dev, adc5_gen3_delete_aux,
> &aux_device->aux_dev);
> - if (ret)
> + if (ret) {
> + devm_release_action(adc->dev, adc5_gen3_uninit_aux,
> + &aux_device->aux_dev);
> return ret;
> + }
--
With Best Regards,
Andy Shevchenko