Re: [PATCH v4] iio: core: Clean up device correctly on viio_trigger_alloc() failure
From: Jonathan Cameron
Date: Sun Feb 22 2026 - 11:21:01 EST
On Sat, 21 Feb 2026 11:07:10 -0600
David Lechner <dlechner@xxxxxxxxxxxx> wrote:
> On 2/21/26 1:32 AM, Salah Triki wrote:
> > Once we called device_initialize() we have to call put_device()
> > on it. Refactor the code to make it in the right order.
>
> This could be a bit more clear. Something like ...
>
> Move device_initialize() after all error paths in viio_trigger_alloc().
> Previously, we should have been calling put_device() on any error path
> after device_initialize(), but failed to do so.
>
> Rather than adding put_device(), we can just move device_initialize()
> to avoid needing to unwind it on error.
>
> Additional trig->dev initialization is also moved with this just to
> keep the code organized.
>
>
I used this but edited to be in imperative:
Move device_initialize() after all error paths in viio_trigger_alloc().
Previously, put_device() should have been called on all error paths after
device_initialize(), but that was not done.
Rather than adding put_device(), move device_initialize() to avoid
needing to unwind it on error.
In addition move trig->dev initialization to just before device_initialize()
to related code together
> >
>
> Did we decide this doesn't need a Fixes: tag?
We never identified an actual problem. It's wrong from a best
practice point of view, but I'm not convinced there is a bug
today without the change. Hence not something we'll rush to backport
and no fixes tag.
>
> > Signed-off-by: Salah Triki <salah.triki@xxxxxxxxx>
> > ---
> No need to send a new revision for this right away. If Jonathan is
> in the mood, he might fix it up for you.
Done ;)
Applied to the testing branch of iio.git
Thanks for the persistence Salah
(and thanks David for the suggestions!)
>
> With the commit message improved:
>
> Reviewed-by: David Lechner <dlechner@xxxxxxxxxxxx>
>