[PATCH] media: staging: max96712: fix cleanup in remove and error paths
From: Raphael
Date: Tue Sep 01 2026 - 15:13:00 EST
When max96712_v4l2_register() succeeds in finalizing subdev
initialization, v4l2_subdev_cleanup(), media_entity_cleanup(), and
v4l2_ctrl_handler_free() must be called during error unwinding and
driver removal to prevent resource leaks. Also pass the array directly
instead of address-of array in max96712_write_bulk_value().
Signed-off-by: Raphael Zanarelli <zanarelli.dev@xxxxxxxxx>
---
drivers/staging/media/max96712/max96712.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/media/max96712/max96712.c
b/drivers/staging/media/max96712/max96712.c
index 0751b2e04..852a1a7a3 100644
--- a/drivers/staging/media/max96712/max96712.c
+++ b/drivers/staging/media/max96712/max96712.c
@@ -92,7 +92,7 @@ static int max96712_write_bulk_value(struct
max96712_priv *priv,
for (i = 1; i <= val_count; i++)
values[i - 1] = (val >> ((val_count - i) * 8)) & 0xff;
- return max96712_write_bulk(priv, reg, &values, val_count);
+ return max96712_write_bulk(priv, reg, values, val_count);
}
static void max96712_reset(struct max96712_priv *priv)
@@ -329,23 +329,28 @@ static int max96712_v4l2_register(struct
max96712_priv *priv)
priv->pads[0].flags = MEDIA_PAD_FL_SOURCE;
ret = media_entity_pads_init(&priv->sd.entity, 1, priv->pads);
if (ret)
- goto error;
+ goto err_ctrl;
v4l2_set_subdevdata(&priv->sd, priv);
priv->sd.state_lock = priv->ctrl_handler.lock;
ret = v4l2_subdev_init_finalize(&priv->sd);
if (ret)
- goto error;
+ goto err_entity;
if (ret < 0) {
ret = v4l2_async_register_subdev(&priv->sd);
dev_err(&priv->client->dev, "Unable to register subdevice\n");
- goto error;
+ goto err_subdev;
}
return 0;
-error:
+
+err_subdev:
+ v4l2_subdev_cleanup(&priv->sd);
+err_entity:
+ media_entity_cleanup(&priv->sd.entity);
+err_ctrl:
v4l2_ctrl_handler_free(&priv->ctrl_handler);
return ret;
@@ -451,6 +456,9 @@ static void max96712_remove(struct i2c_client *client)
struct max96712_priv *priv = container_of(sd, struct
max96712_priv, sd);
v4l2_async_unregister_subdev(&priv->sd);
+ v4l2_subdev_cleanup(&priv->sd);
+ media_entity_cleanup(&priv->sd.entity);
+ v4l2_ctrl_handler_free(&priv->ctrl_handler);
gpiod_set_value_cansleep(priv->gpiod_pwdn, 0);
}
--
2.50.1 (Apple Git-155)