[PATCH] media: i2c: og0ve1b: Free controls when control creation fails

From: Wentao Liang

Date: Tue Nov 03 2026 - 03:25:21 EST


If a control cannot be created, og0ve1b_init_controls() returns the
handler error directly, skipping the cleanup used by its later failures.
The probe caller then powers the sensor off without freeing the control
handler, leaking controls that were successfully created before the
failure and the handler's allocation.

Save the error and use the existing handler cleanup path. Preserve the
original error before v4l2_ctrl_handler_free() resets the handler.

Fixes: 25bf2e1925c9 ("media: i2c: Add OmniVision OG0VE1B camera sensor")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/media/i2c/og0ve1b.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/og0ve1b.c b/drivers/media/i2c/og0ve1b.c
index e7cd0f72f3e5..78e8675d99dd 100644
--- a/drivers/media/i2c/og0ve1b.c
+++ b/drivers/media/i2c/og0ve1b.c
@@ -665,8 +665,10 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b)
data->num_test_patterns - 1,
0, 0, data->test_pattern_menu);

- if (ctrl_hdlr->error)
- return ctrl_hdlr->error;
+ if (ctrl_hdlr->error) {
+ ret = ctrl_hdlr->error;
+ goto error_free_hdlr;
+ }

ret = v4l2_fwnode_device_parse(og0ve1b->dev, &props);
if (ret)
--
2.34.1