Linux IIO development
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Ma Ke <make24@iscas.ac.cn>
Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
	andy@kernel.org, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Subject: Re: [PATCH v4 2/2] iio: trigger: fix device initialization order in viio_trigger_alloc
Date: Mon, 10 Nov 2025 07:28:01 +0200	[thread overview]
Message-ID: <aRF34dlvZaD-stgt@smile.fi.intel.com> (raw)
In-Reply-To: <20251110035838.37029-1-make24@iscas.ac.cn>

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



  reply	other threads:[~2025-11-10  5:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-10  3:58 [PATCH v4 2/2] iio: trigger: fix device initialization order in viio_trigger_alloc Ma Ke
2025-11-10  5:28 ` Andy Shevchenko [this message]
2025-11-10 14:49 ` Nuno Sá

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aRF34dlvZaD-stgt@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=make24@iscas.ac.cn \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox