public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Ethan Tidmore <ethantidmore06@gmail.com>
Cc: linusw@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
	andy@kernel.org, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/4] iio: gyro: mpu3050: Move iio_device_register() to correct location
Date: Sat, 28 Feb 2026 18:17:52 +0000	[thread overview]
Message-ID: <20260228181752.05e08886@jic23-huawei> (raw)
In-Reply-To: <20260224224818.2452675-4-ethantidmore06@gmail.com>

On Tue, 24 Feb 2026 16:48:17 -0600
Ethan Tidmore <ethantidmore06@gmail.com> wrote:

> iio_device_register() should be at the end of the probe function to
> prevent race conditions.
Ah. I perhaps over stated this...
See below.

> 
> Place iio_device_register() at the end of the probe function and place
> iio_device_unregister() accordingly.
> 
> Fixes: 3904b28efb2c7 ("iio: gyro: Add driver for the MPU-3050 gyroscope")
> Suggested-by: Jonathan Cameron <jic23@kernel.org>
> Reviewed-by: Linus Walleij <linusw@kernel.org>
> Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
> ---
> v3: 
> - Remove stray change.
> - Fix grammar with "the".
> v2:
> - Patch added to series.
> 
>  drivers/iio/gyro/mpu3050-core.c | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
> index b6e05afbe512..b590cf6709b4 100644
> --- a/drivers/iio/gyro/mpu3050-core.c
> +++ b/drivers/iio/gyro/mpu3050-core.c
> @@ -1218,12 +1218,6 @@ int mpu3050_common_probe(struct device *dev,
>  		goto err_power_down;
>  	}
>  
> -	ret = iio_device_register(indio_dev);
> -	if (ret) {
> -		dev_err(dev, "device register failed\n");
> -		goto err_cleanup_buffer;
> -	}
> -
>  	dev_set_drvdata(dev, indio_dev);
>  
>  	/* Check if we have an assigned IRQ to use as trigger */
> @@ -1246,9 +1240,20 @@ int mpu3050_common_probe(struct device *dev,
>  	pm_runtime_use_autosuspend(dev);
>  	pm_runtime_put(dev);
>  
> +	ret = iio_device_register(indio_dev);
> +	if (ret) {
> +		dev_err(dev, "device register failed\n");
> +		goto err_iio_device_register;
> +	}
> +
>  	return 0;
>  
> -err_cleanup_buffer:
> +err_iio_device_register:
> +	pm_runtime_get_sync(dev);
> +	pm_runtime_put_noidle(dev);
> +	pm_runtime_disable(dev);
These are a rare thing that is fine either before or after iio_device_register()
as any races just result in elevated reference counts (which drop again when
the racing access finishes).

Having said that, the order you have here should be fine.

Jonathan


> +	if (irq)
> +		free_irq(mpu3050->irq, mpu3050->trig);
>  	iio_triggered_buffer_cleanup(indio_dev);
>  err_power_down:
>  	mpu3050_power_down(mpu3050);
> @@ -1261,13 +1266,13 @@ void mpu3050_common_remove(struct device *dev)
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>  	struct mpu3050 *mpu3050 = iio_priv(indio_dev);
>  
> +	iio_device_unregister(indio_dev);
>  	pm_runtime_get_sync(dev);
>  	pm_runtime_put_noidle(dev);
>  	pm_runtime_disable(dev);
>  	iio_triggered_buffer_cleanup(indio_dev);
>  	if (mpu3050->irq)
>  		free_irq(mpu3050->irq, mpu3050->trig);
> -	iio_device_unregister(indio_dev);
>  	mpu3050_power_down(mpu3050);
>  }
>  


  reply	other threads:[~2026-02-28 18:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-24 22:48 [PATCH v3 0/4] iio: gyro: mpu3050: Multiple bug fixes Ethan Tidmore
2026-02-24 22:48 ` [PATCH v3 1/4] iio: gyro: mpu3050: Fix incorrect free_irq() variable Ethan Tidmore
2026-02-24 22:48 ` [PATCH v3 2/4] iio: gyro: mpu3050: Fix irq resource leak Ethan Tidmore
2026-02-24 22:48 ` [PATCH v3 3/4] iio: gyro: mpu3050: Move iio_device_register() to correct location Ethan Tidmore
2026-02-28 18:17   ` Jonathan Cameron [this message]
2026-02-24 22:48 ` [PATCH v3 4/4] iio: gyro: mpu3050: Fix out-of-sequence free_irq() Ethan Tidmore
2026-02-25 11:53   ` Andy Shevchenko
2026-02-25 11:59   ` Andy Shevchenko
2026-02-28 18:15     ` Jonathan Cameron
2026-02-25 12:01 ` [PATCH v3 0/4] iio: gyro: mpu3050: Multiple bug fixes Andy Shevchenko
2026-02-28 18:16   ` Jonathan Cameron

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=20260228181752.05e08886@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=ethantidmore06@gmail.com \
    --cc=linusw@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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