linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: i2c: Fix regulator disable balance in ov8865
@ 2022-01-30 21:36 Daniel Scally
  2022-02-02 12:21 ` Sakari Ailus
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Scally @ 2022-01-30 21:36 UTC (permalink / raw)
  To: linux-media; +Cc: sakari.ailus, paul.kocialkowski, kevin.lhopital

ov8865_sensor_power() disables all three of the sensor's regulators
on the error path, however not all of the regulators may have been
enabled at the time of the error, which will result in unbalanced
disable calls.

Fix the issue by adding specific error paths for each regulator.

Fixes: 11c0d8fdccc5 ("media: i2c: Add support for the OV8865 image sensor")

Signed-off-by: Daniel Scally <djrscally@gmail.com>
---
 drivers/media/i2c/ov8865.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
index ebdb20d3fe9d..cb740d7e4f5a 100644
--- a/drivers/media/i2c/ov8865.c
+++ b/drivers/media/i2c/ov8865.c
@@ -2404,30 +2404,28 @@ static int ov8865_sensor_power(struct ov8865_sensor *sensor, bool on)
 		gpiod_set_value_cansleep(sensor->powerdown, 1);
 
 		ret = regulator_enable(sensor->dovdd);
-		if (ret) {
-			dev_err(sensor->dev,
-				"failed to enable DOVDD regulator\n");
-			goto disable;
-		}
+		if (ret)
+			return dev_err_probe(sensor->dev, ret,
+					     "failed to enable DOVDD\n");
 
 		ret = regulator_enable(sensor->avdd);
 		if (ret) {
 			dev_err(sensor->dev,
 				"failed to enable AVDD regulator\n");
-			goto disable;
+			goto err_disable_dovdd;
 		}
 
 		ret = regulator_enable(sensor->dvdd);
 		if (ret) {
 			dev_err(sensor->dev,
 				"failed to enable DVDD regulator\n");
-			goto disable;
+			goto err_disable_avdd;
 		}
 
 		ret = clk_prepare_enable(sensor->extclk);
 		if (ret) {
 			dev_err(sensor->dev, "failed to enable EXTCLK clock\n");
-			goto disable;
+			goto err_disable_dvdd;
 		}
 
 		gpiod_set_value_cansleep(sensor->reset, 0);
@@ -2436,7 +2434,6 @@ static int ov8865_sensor_power(struct ov8865_sensor *sensor, bool on)
 		/* Time to enter streaming mode according to power timings. */
 		usleep_range(10000, 12000);
 	} else {
-disable:
 		gpiod_set_value_cansleep(sensor->powerdown, 1);
 		gpiod_set_value_cansleep(sensor->reset, 1);
 
@@ -2447,6 +2444,15 @@ static int ov8865_sensor_power(struct ov8865_sensor *sensor, bool on)
 		regulator_disable(sensor->dovdd);
 	}
 
+	return ret;
+
+err_disable_dvdd:
+	regulator_disable(sensor->dvdd);
+err_disable_avdd:
+	regulator_disable(sensor->avdd);
+err_disable_dovdd:
+	regulator_disable(sensor->dovdd);
+
 	return ret;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: i2c: Fix regulator disable balance in ov8865
  2022-01-30 21:36 [PATCH] media: i2c: Fix regulator disable balance in ov8865 Daniel Scally
@ 2022-02-02 12:21 ` Sakari Ailus
  2022-02-02 12:37   ` Daniel Scally
  0 siblings, 1 reply; 3+ messages in thread
From: Sakari Ailus @ 2022-02-02 12:21 UTC (permalink / raw)
  To: Daniel Scally; +Cc: linux-media, paul.kocialkowski, kevin.lhopital

Hi Daniel,

On Sun, Jan 30, 2022 at 09:36:21PM +0000, Daniel Scally wrote:
> ov8865_sensor_power() disables all three of the sensor's regulators
> on the error path, however not all of the regulators may have been
> enabled at the time of the error, which will result in unbalanced
> disable calls.
> 
> Fix the issue by adding specific error paths for each regulator.
> 
> Fixes: 11c0d8fdccc5 ("media: i2c: Add support for the OV8865 image sensor")
> 
> Signed-off-by: Daniel Scally <djrscally@gmail.com>

Thanks for the patch.

This has been already fixed by commit
cbe0b3af73bf72fad197756f026084404e2bcdc7 (in media tree).

-- 
Kind regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: i2c: Fix regulator disable balance in ov8865
  2022-02-02 12:21 ` Sakari Ailus
@ 2022-02-02 12:37   ` Daniel Scally
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Scally @ 2022-02-02 12:37 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-media, paul.kocialkowski, kevin.lhopital

Hi Sakari

On 02/02/2022 12:21, Sakari Ailus wrote:
> Hi Daniel,
>
> On Sun, Jan 30, 2022 at 09:36:21PM +0000, Daniel Scally wrote:
>> ov8865_sensor_power() disables all three of the sensor's regulators
>> on the error path, however not all of the regulators may have been
>> enabled at the time of the error, which will result in unbalanced
>> disable calls.
>>
>> Fix the issue by adding specific error paths for each regulator.
>>
>> Fixes: 11c0d8fdccc5 ("media: i2c: Add support for the OV8865 image sensor")
>>
>> Signed-off-by: Daniel Scally <djrscally@gmail.com>
> Thanks for the patch.
>
> This has been already fixed by commit
> cbe0b3af73bf72fad197756f026084404e2bcdc7 (in media tree).
>
Ah cool ok - my bad :)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-02 12:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-30 21:36 [PATCH] media: i2c: Fix regulator disable balance in ov8865 Daniel Scally
2022-02-02 12:21 ` Sakari Ailus
2022-02-02 12:37   ` Daniel Scally

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).