[PATCH v2] media: ov7670: propagate clock enable failures

From: Pengpeng Hou

Date: Wed Dec 02 2026 - 22:37:59 EST


ov7670_power_on() sets the powered state even when clk_prepare_enable()
fails. Return the error before toggling GPIOs or setting info->on, and
stop probe and the subdevice power operation if the clock could not be
enabled.

The issue was identified via static analysis and manually reviewed.

Fixes: 030f9f682e66 ("media: ov7670: control clock along with power")
Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
Changes since v1:
Keep the existing power-state checks, scope ret to the power-on block in
s_power(), and leave runtime PM conversion out of this fix.
Previous version: https://lore.kernel.org/r/20260828091506.6732-1-pengpeng@xxxxxxxxxxx

The v1 mail recorded LLM assistance without identifying the model.
I can't identify that version from the submission record.
Codex assisted with patch preparation and the changelog.
Current review: Codex (Assisted-by: gpt 5).
Static review only; this revision was not built.

drivers/media/i2c/ov7670.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
index 5a553d50f3a367de1b7d7d7e299181b7b4b78d79..c6ebc0abf71e15b6c924054b421df42401770d06 100644
--- a/drivers/media/i2c/ov7670.c
+++ b/drivers/media/i2c/ov7670.c
@@ -1648,14 +1648,17 @@ static int ov7670_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_regis
}
#endif

-static void ov7670_power_on(struct v4l2_subdev *sd)
+static int ov7670_power_on(struct v4l2_subdev *sd)
{
struct ov7670_info *info = to_state(sd);
+ int ret;

if (info->on)
- return;
+ return 0;

- clk_prepare_enable(info->clk);
+ ret = clk_prepare_enable(info->clk);
+ if (ret)
+ return ret;

if (info->pwdn_gpio)
gpiod_set_value(info->pwdn_gpio, 0);
@@ -1668,6 +1671,8 @@ static void ov7670_power_on(struct v4l2_subdev *sd)
usleep_range(3000, 5000);

info->on = true;
+
+ return 0;
}

static void ov7670_power_off(struct v4l2_subdev *sd)
@@ -1693,7 +1698,10 @@ static int ov7670_s_power(struct v4l2_subdev *sd, int on)
return 0;

if (on) {
- ov7670_power_on(sd);
+ int ret = ov7670_power_on(sd);
+
+ if (ret)
+ return ret;
ov7670_init(sd, 0);
ov7670_apply_fmt(sd);
ov7675_apply_framerate(sd);
@@ -1873,7 +1881,9 @@ static int ov7670_probe(struct i2c_client *client)
if (ret)
return ret;

- ov7670_power_on(sd);
+ ret = ov7670_power_on(sd);
+ if (ret)
+ return ret;

if (info->clk) {
info->clock_speed = clk_get_rate(info->clk) / 1000000;

base-commit: 37760be5a04b538bbd25099000e37d3208c27efe