public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Salah Triki <salah.triki@gmail.com>
To: "Crt Mori" <cmo@melexis.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Salah Triki <salah.triki@gmail.com>
Subject: [PATCH] iio: mlx90614: fix missing GPIO direction return value checks
Date: Mon, 27 Apr 2026 22:58:00 +0100	[thread overview]
Message-ID: <20260427215800.28082-1-salah.triki@gmail.com> (raw)

The functions gpiod_direction_output() and gpiod_direction_input() can
fail, but their return values were previously ignored.

If an error occurs during the GPIO configuration, the function should
abort the wake-up sequence and return the error code. More importantly,
failing to check these values could lead to the I2C bus remaining
locked if an error occurs after i2c_lock_bus() is called.

Add return value checks and ensure the I2C bus is properly unlocked
via a goto label in case of failure.

Fixes: eb4b07dae4d4 ("iio: mlx90614: Add power management")
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 drivers/iio/temperature/mlx90614.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/temperature/mlx90614.c b/drivers/iio/temperature/mlx90614.c
index 1ad21b73e1b4..ce12b44c84e0 100644
--- a/drivers/iio/temperature/mlx90614.c
+++ b/drivers/iio/temperature/mlx90614.c
@@ -489,6 +489,7 @@ static int mlx90614_sleep(struct mlx90614_data *data)
 static int mlx90614_wakeup(struct mlx90614_data *data)
 {
 	const struct mlx_chip_info *chip_info = data->chip_info;
+	int ret;
 
 	if (!data->wakeup_gpio) {
 		dev_dbg(&data->client->dev, "Wake-up disabled");
@@ -498,9 +499,17 @@ static int mlx90614_wakeup(struct mlx90614_data *data)
 	dev_dbg(&data->client->dev, "Requesting wake-up");
 
 	i2c_lock_bus(data->client->adapter, I2C_LOCK_ROOT_ADAPTER);
-	gpiod_direction_output(data->wakeup_gpio, 0);
+
+	ret = gpiod_direction_output(data->wakeup_gpio, 0);
+	if (ret)
+		goto out_unlock;
+
 	msleep(chip_info->wakeup_delay_ms);
-	gpiod_direction_input(data->wakeup_gpio);
+
+	ret = gpiod_direction_input(data->wakeup_gpio);
+	if (ret)
+		goto out_unlock;
+
 	i2c_unlock_bus(data->client->adapter, I2C_LOCK_ROOT_ADAPTER);
 
 	data->ready_timestamp = jiffies +
@@ -515,6 +524,10 @@ static int mlx90614_wakeup(struct mlx90614_data *data)
 	i2c_smbus_read_word_data(data->client, chip_info->op_eeprom_config1);
 
 	return 0;
+
+out_unlock:
+	i2c_unlock_bus(data->client->adapter, I2C_LOCK_ROOT_ADAPTER);
+	return ret;
 }
 
 /* Return wake-up GPIO or NULL if sleep functionality should be disabled. */
-- 
2.43.0


             reply	other threads:[~2026-04-27 21:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-27 21:58 Salah Triki [this message]
2026-04-28  8:00 ` [PATCH] iio: mlx90614: fix missing GPIO direction return value checks Andy Shevchenko
2026-04-28  8:38   ` Salah Triki
2026-04-28 16:04     ` Jonathan Cameron
2026-04-28 16:33       ` Crt Mori
2026-05-05  7:31         ` Salah Triki
2026-05-05  7:48           ` Crt Mori
2026-04-28 16:05 ` 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=20260427215800.28082-1-salah.triki@gmail.com \
    --to=salah.triki@gmail.com \
    --cc=andy@kernel.org \
    --cc=cmo@melexis.com \
    --cc=dlechner@baylibre.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