[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aRF34dlvZaD-stgt@smile.fi.intel.com>
Date: Mon, 10 Nov 2025 07:28:01 +0200
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: Ma Ke <make24@...as.ac.cn>
Cc: jic23@...nel.org, dlechner@...libre.com, nuno.sa@...log.com,
andy@...nel.org, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org, akpm@...ux-foundation.org
Subject: Re: [PATCH v4 2/2] iio: trigger: fix device initialization order in
viio_trigger_alloc
On Mon, Nov 10, 2025 at 11:58:38AM +0800, Ma Ke wrote:
> Move device initialization to the end of viio_trigger_alloc() to
> simplify error handling. This follows the pattern used in similar
> functions like spi_alloc_device(), where device_initialize() is called
> only after all resources have been successfully allocated.
>
> This change eliminates the need for complex cleanup in error paths and
> ensures that the device release callback only runs when the device was
> fully initialized.
>
> By moving device_initialize() after all resource allocations, we can
> use simple kfree() in error paths instead of put_device(), making the
> code more straightforward and less error-prone.
>
> Found by code review.
Thanks for the update, my comments below.
...
> - trig->dev.parent = parent;
> - trig->dev.type = &iio_trig_type;
> - trig->dev.bus = &iio_bus_type;
> - device_initialize(&trig->dev);
> - INIT_WORK(&trig->reenable_work, iio_reenable_work_fn);
> + /* Initialize device only after all resources are allocated */
> + trig->dev.parent = parent;
> + trig->dev.type = &iio_trig_type;
> + trig->dev.bus = &iio_bus_type;
> + device_initialize(&trig->dev);
> + INIT_WORK(&trig->reenable_work, iio_reenable_work_fn);
Why has this been moved?
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists