media: i2c: vd56g3: Clean up subdev state on init failure
Subsystems (4)
PATCH v3 1/1 media: i2c: vd56g3: Clean up subdev state on init failure
vd56g3_subdev_init() calls v4l2_subdev_init_finalize(), which allocates the subdev active state and requires v4l2_subdev_cleanup() to release it.
If vd56g3_update_controls() fails after finalize succeeds, the probe error path currently skips v4l2_subdev_cleanup() and returns an error. The driver .remove() callback is not called after a failed probe, so the active state is leaked.
Move the control update to vd56g3_probe() after vd56g3_subdev_init() succeeds, and route failures through the existing err_subdev path. This keeps v4l2_subdev_cleanup() in the common vd56g3_subdev_cleanup() helper.
---
Changes in v3:
- Restore the capitalized subject summary.
- Route vd56g3_update_controls() failures through the probe-side subdev cleanup path instead of adding a second v4l2_subdev_cleanup() call.
- Add the Assisted-by trailer.
Changes in v2:
- Use a lowercase subject summary.
drivers/media/i2c/vd56g3.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/media/i2c/vd56g3.c +10 -10
@@ -1388,7 +1388,6 @@ static int vd56g3_detect(struct vd56g3 *sensor)static int vd56g3_subdev_init (struct vd56g3 *sensor) { -struct v4l2_subdev_state *state;int ret;/* Init remaining sub device ops */
@@ -1421,15 +1420,6 @@ static int vd56g3_subdev_init(struct vd56g3 *sensor) goto err_ctrls; } -/* Update controls according to the resolution set */ - state =v4l2_subdev_lock_and_get_active_state (&sensor->sd); - ret =vd56g3_update_controls (sensor); -v4l2_subdev_unlock_state (state); -if (ret) { -dev_err (sensor->dev,"Controls update failed: %d\n" , ret); - goto err_ctrls; - } -return 0 ; err_ctrls:
@@ -1452,6 +1442,7 @@ static void vd56g3_subdev_cleanup(struct vd56g3 *sensor)static int vd56g3_probe (struct i2c_client *client) {struct device *dev = &client->dev; +struct v4l2_subdev_state *state;struct vd56g3 *sensor;int ret;
@@ -1517,6 +1508,15 @@ static int vd56g3_probe(struct i2c_client *client) goto err_power_off; } +/* Update controls according to the resolution set */ + state =v4l2_subdev_lock_and_get_active_state (&sensor->sd); + ret =vd56g3_update_controls (sensor); +v4l2_subdev_unlock_state (state); +if (ret) { +dev_err (sensor->dev,"Controls update failed: %d\n" , ret); + goto err_subdev; + } + ret =v4l2_async_register_subdev (&sensor->sd);if (ret) {dev_err (dev,"Async subdev register failed: %d\n" , ret);
Signature · 1 line
2.50.1
Hi Myeonghun,
Sorry for the delay.
Le 22/06/2026 à 14:14, Myeonghun Pak a écrit :
Quoted 8 lines
vd56g3_subdev_init()callsv4l2_subdev_init_finalize(), which allocates the subdev active state and requiresv4l2_subdev_cleanup()to release it.If
vd56g3_update_controls()fails after finalize succeeds, the probe error path currently skipsv4l2_subdev_cleanup()and returns an error. The driver .remove() callback is not called after a failed probe, so the active state is leaked.
Quoted 8 lines
Move the control update to
vd56g3_probe()aftervd56g3_subdev_init()succeeds, and route failures through the existingerr_subdevpath. This keepsv4l2_subdev_cleanup()in the commonvd56g3_subdev_cleanup()helper.Fixes 87aa97fc3157 ("media: i2c: Add driver for ST VD56G3 camera sensor")Assisted-by OpenAI:GPT-5.4Signed-off-by Myeonghun Pak <[email protected]>
One more nitpick but otherwise :
Quoted 26 lines
---
Changes in v3:
- Restore the capitalized subject summary.
- Routevd56g3_update_controls()failures through the probe-side subdev cleanup path instead of adding a secondv4l2_subdev_cleanup()call.
- Add the Assisted-by trailer.Changes in v2:
- Use a lowercase subject summary.drivers/media/i2c/vd56g3.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)drivers/media/i2c/vd56g3.c +0
-1@@ -1388,7 +1388,6 @@ static int vd56g3_detect(struct vd56g3 *sensor)static int vd56g3_subdev_init (struct vd56g3 *sensor) { -struct v4l2_subdev_state *state;int ret;/* Init remaining sub device ops */
drivers/media/i2c/vd56g3.c static int vd56g3_subdev_init(struct vd56g3 *sensor) · line 1430
Quoted 10 lines
drivers/media/i2c/vd56g3.c +0
-7@@ -1421,15 +1420,6 @@ static int vd56g3_subdev_init(struct vd56g3 *sensor) goto err_ctrls; } -/* Update controls according to the resolution set */ - state =v4l2_subdev_lock_and_get_active_state (&sensor->sd); - ret =vd56g3_update_controls (sensor); -v4l2_subdev_unlock_state (state); -if (ret) { -dev_err (sensor->dev,"Controls update failed: %d\n" , ret); - goto err_ctrls;
The err_ctrls label could be renamed to something more relevant now.
Quoted 29 lines
drivers/media/i2c/vd56g3.c +10
-2- } -return 0 ; err_ctrls:@@ -1452,6 +1442,7 @@ static void vd56g3_subdev_cleanup(struct vd56g3 *sensor)static int vd56g3_probe (struct i2c_client *client) {struct device *dev = &client->dev; +struct v4l2_subdev_state *state;struct vd56g3 *sensor;int ret;@@ -1517,6 +1508,15 @@ static int vd56g3_probe(struct i2c_client *client) goto err_power_off; } +/* Update controls according to the resolution set */ + state =v4l2_subdev_lock_and_get_active_state (&sensor->sd); + ret =vd56g3_update_controls (sensor); +v4l2_subdev_unlock_state (state); +if (ret) { +dev_err (sensor->dev,"Controls update failed: %d\n" , ret); + goto err_subdev; + } + ret =v4l2_async_register_subdev (&sensor->sd);if (ret) {dev_err (dev,"Async subdev register failed: %d\n" , ret);
Signature · 2 lines
Regards, Benjamin