Re: [PATCH v3] iio: trigger: use put_device() in viio_trigger_alloc() error path
From: Andy Shevchenko
Date: Mon Feb 16 2026 - 02:55:43 EST
On Sun, Feb 15, 2026 at 11:23:47PM +0100, Salah Triki wrote:
> Once `device_initialize()` is called, the lifecycle of the trigger must be
> managed by the kobject reference counting. Currently, if `kvasprintf()`
> fails, the code manually calls kfree() and `irq_free_descs()`.
>
> Switching to `put_device()` ensures that the device's release callback
> (`iio_trig_release()`) is properly invoked. This simplifies the error
> path by centralizing the cleanup logic (including `irq_free_descs()`)
> inside the release handler, following the standard driver model pattern.
How did you test this, please?
...
> struct iio_trigger *viio_trigger_alloc(struct device *parent,
> trig->name = kvasprintf(GFP_KERNEL, fmt, vargs);
> if (trig->name == NULL)
> - goto free_descs;
> + goto free_trig;
>
> INIT_LIST_HEAD(&trig->list);
> return trig;
>
> -free_descs:
> - irq_free_descs(trig->subirq_base, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
> free_trig:
> - kfree(trig);
> + put_device(&trig->dev);
Now, in iio_trig_release() you will call a bunch of code with
trig->subirq_base != 0.
Please, test your changes before submitting.
> return NULL;
> }
--
With Best Regards,
Andy Shevchenko