Linux IIO development
 help / color / mirror / Atom feed
From: Andrey Skvortsov <andrej.skvortzov@gmail.com>
To: "Jean-Baptiste Maneyrol" <jean-baptiste.maneyrol@tdk.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Andrey Skvortsov <andrej.skvortzov@gmail.com>
Subject: [PATCH] iio: imu: fix unbalanced regulator_disable calls, when probe fails
Date: Sun,  8 Mar 2026 14:03:28 +0300	[thread overview]
Message-ID: <20260308110328.2859831-1-andrej.skvortzov@gmail.com> (raw)

During a probe functions after all regulators are enabled, runtime pm
is enabled. Before probe function finishes, runtime pm triggers and
disables vddio regulator. When probe function fails after that,
inv_mpu_core_disable_regulator_action tries to disable already
disabled by runtime pm vddio regulator causing following backtrace:

 inv-mpu6050-i2c 1-0068: trigger probe fail -19
 ------------[ cut here ]------------
 unbalanced disables a for vcc-dsi-sensor
 WARNING: drivers/regulator/core.c:3244 at _regulator_disable+0x118/0x260, CPU#3: (udev-worker)/357
 Call trace:
  _regulator_disable+0x118/0x260 (P)
  regulator_disable+0x50/0xa0
  inv_mpu_core_disable_regulator_action+0x30/0xa0 [inv_mpu6050]
  devm_action_release+0x1c/0x30
  release_nodes+0x6c/0xa8
  devres_release_group+0x158/0x1a0
  i2c_device_probe+0x33c/0x3a0
  really_probe+0xc8/0x3f0
  __driver_probe_device+0x88/0x170
  driver_probe_device+0x48/0x130
  __driver_attach+0x10c/0x260
  bus_for_each_dev+0x84/0xf0
  driver_attach+0x2c/0x40
  bus_add_driver+0x124/0x258
  driver_register+0x70/0x138
  i2c_register_driver+0x50/0xe8
  inv_mpu_driver_init+0x28/0xfb8 [inv_mpu6050_i2c]
  do_one_initcall+0x5c/0x478
  do_init_module+0x5c/0x268
  load_module+0x1d04/0x2558
  init_module_from_file+0xe8/0x158
  __arm64_sys_finit_module+0x1f8/0x388
  invoke_syscall.constprop.0+0x64/0xe8
  el0_svc_common.constprop.0+0xc0/0xe8
  do_el0_svc+0x24/0x38
  el0_svc+0x3c/0x198
  el0t_64_sync_handler+0xa0/0xe8
  el0t_64_sync+0x198/0x1a0
 ---[ end trace 0000000000000000 ]---
 inv-mpu6050-i2c 1-0068: Failed to disable vddio regulator: -5

This change introduces variable to track state of vddio regulator and
whether it's needed to disable it or not.

Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 5 +++++
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  | 1 +
 2 files changed, 6 insertions(+)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 5796896d54cd8..7dd09963d5a39 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1843,6 +1843,7 @@ static int inv_mpu_core_enable_regulator_vddio(struct inv_mpu6050_state *st)
 		/* Give the device a little bit of time to start up. */
 		usleep_range(3000, 5000);
 	}
+	st->vddio_supply_en = !result;
 
 	return result;
 }
@@ -1851,10 +1852,14 @@ static int inv_mpu_core_disable_regulator_vddio(struct inv_mpu6050_state *st)
 {
 	int result;
 
+	if (!st->vddio_supply_en)
+		return 0;
+
 	result = regulator_disable(st->vddio_supply);
 	if (result)
 		dev_err(regmap_get_device(st->map),
 			"Failed to disable vddio regulator: %d\n", result);
+	st->vddio_supply_en = false;
 
 	return result;
 }
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index 6239b1a803f77..1a2fb857f022d 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -208,6 +208,7 @@ struct inv_mpu6050_state {
 	struct inv_sensors_timestamp timestamp;
 	struct regulator *vdd_supply;
 	struct regulator *vddio_supply;
+	bool vddio_supply_en;
 	bool magn_disabled;
 	s32 magn_raw_to_gauss[3];
 	struct iio_mount_matrix magn_orient;
-- 
2.51.0


             reply	other threads:[~2026-03-08 11:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-08 11:03 Andrey Skvortsov [this message]
2026-03-08 18:29 ` [PATCH] iio: imu: fix unbalanced regulator_disable calls, when probe fails David Lechner
2026-03-08 20:39 ` Andy Shevchenko

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=20260308110328.2859831-1-andrej.skvortzov@gmail.com \
    --to=andrej.skvortzov@gmail.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jean-baptiste.maneyrol@tdk.com \
    --cc=jic23@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