media: i2c: Add missing media_entity_cleanup() calls
cover media: i2c: Add missing media_entity_cleanup() calls
Hi all,
This patch series addresses missing media_entity_cleanup() calls in the error paths and remove functions of several media/i2c drivers.
While media_entity_cleanup() is currently a no-op when CONFIG_MEDIA_CONTROLLER is disabled (and even when enabled in modern kernels, as pads are rarely dynamically allocated anymore), the media subsystem guidelines strictly require drivers to call it to prevent future leaks if the core framework behavior changes.
Biren Pandya (5):
media: i2c: cx25840-core: Add missing media_entity_cleanup()
media: i2c: max9286: Add missing media_entity_cleanup()
media: i2c: msp3400-driver: Add missing media_entity_cleanup()
media: i2c: mt9v011: Add missing media_entity_cleanup()
media: i2c: saa7115: Add missing media_entity_cleanup()
drivers/media/i2c/cx25840/cx25840-core.c | 2 ++ drivers/media/i2c/max9286.c | 5 ++++- drivers/media/i2c/msp3400-driver.c | 2 ++ drivers/media/i2c/mt9v011.c | 3 +++ drivers/media/i2c/saa7115.c | 2 ++ 5 files changed, 13 insertions(+), 1 deletion(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 1/5 media: i2c: cx25840-core: Add missing media_entity_cleanup()
The probe error paths and remove function are missing calls to media_entity_cleanup(). Add them to prevent memory leaks if pads are dynamically allocated.
--- drivers/media/i2c/cx25840/cx25840-core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/i2c/cx25840/cx25840-core.c +2 -0
@@ -3962,6 +3962,7 @@ static int cx25840_probe(struct i2c_client *client)int err = state->hdl.error;v4l2_ctrl_handler_free (&state->hdl); +media_entity_cleanup (&sd->entity);return err; }if (!is_cx2583x (state))
@@ -3986,6 +3987,7 @@ static void cx25840_remove(struct i2c_client *client)cx25840_ir_remove (sd);v4l2_device_unregister_subdev (sd);v4l2_ctrl_handler_free (&state->hdl); +media_entity_cleanup (&sd->entity); }static const struct i2c_device_id cx25840_id[] = {
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 2/5 media: i2c: max9286: Add missing media_entity_cleanup()
In reply to Biren PandyaThe probe error paths and unregister function are missing calls to media_entity_cleanup(). Add them to prevent memory leaks if pads are dynamically allocated.
--- drivers/media/i2c/max9286.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/max9286.c +4 -1
@@ -1062,7 +1062,7 @@ static int max9286_v4l2_register(struct max9286_priv *priv) priv->sd.state_lock = priv->ctrls.lock; ret =v4l2_subdev_init_finalize (&priv->sd);if (ret) - goto err_async; + goto err_entity; ret =v4l2_async_register_subdev (&priv->sd);if (ret <0 ) {
@@ -1074,6 +1074,8 @@ static int max9286_v4l2_register(struct max9286_priv *priv) err_subdev:v4l2_subdev_cleanup (&priv->sd); +err_entity: +media_entity_cleanup (&priv->sd.entity); err_async:v4l2_ctrl_handler_free (&priv->ctrls);max9286_v4l2_notifier_unregister (priv);
@@ -1084,6 +1086,7 @@ static int max9286_v4l2_register(struct max9286_priv *priv)static void max9286_v4l2_unregister (struct max9286_priv *priv) {v4l2_subdev_cleanup (&priv->sd); +media_entity_cleanup (&priv->sd.entity);v4l2_ctrl_handler_free (&priv->ctrls);v4l2_async_unregister_subdev (&priv->sd);max9286_v4l2_notifier_unregister (priv);
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH 2/5] media: i2c: max9286: Add missing media_entity_cleanup()
Hi Biren
Quoted 3 lines · Biren Pandya
The probe error paths and unregister function are missing calls to
media_entity_cleanup(). Add them to prevent memory leaks if pads are dynamically allocated.
I think the last phrase can be dropped. media_entity_cleanup() is a nop.
Quoted 2 lines
Signed-off-by Biren Pandya <[email protected]>
Quoted 38 lines
--- drivers/media/i2c/max9286.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/media/i2c/max9286.c +4
-2@@ -1062,7 +1062,7 @@ static int max9286_v4l2_register(struct max9286_priv *priv) priv->sd.state_lock = priv->ctrls.lock; ret =v4l2_subdev_init_finalize (&priv->sd);if (ret) - goto err_async; + goto err_entity; ret =v4l2_async_register_subdev (&priv->sd);if (ret <0 ) {@@ -1074,6 +1074,8 @@ static int max9286_v4l2_register(struct max9286_priv *priv) err_subdev:v4l2_subdev_cleanup (&priv->sd); +err_entity: +media_entity_cleanup (&priv->sd.entity); err_async:v4l2_ctrl_handler_free (&priv->ctrls);max9286_v4l2_notifier_unregister (priv);@@ -1084,6 +1086,7 @@ static int max9286_v4l2_register(struct max9286_priv *priv)static void max9286_v4l2_unregister (struct max9286_priv *priv) {v4l2_subdev_cleanup (&priv->sd); +media_entity_cleanup (&priv->sd.entity);v4l2_ctrl_handler_free (&priv->ctrls);v4l2_async_unregister_subdev (&priv->sd);max9286_v4l2_notifier_unregister (priv); --2.50.1 (Apple Git-155)
PATCH 3/5 media: i2c: msp3400-driver: Add missing media_entity_cleanup()
In reply to Biren PandyaThe probe error paths and remove function are missing calls to media_entity_cleanup(). Add them to prevent memory leaks if pads are dynamically allocated.
--- drivers/media/i2c/msp3400-driver.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/i2c/msp3400-driver.c +2 -0
@@ -812,6 +812,7 @@ static int msp_probe(struct i2c_client *client)int err = hdl->error;v4l2_ctrl_handler_free (hdl); +media_entity_cleanup (&sd->entity);return err; }
@@ -865,6 +866,7 @@ static void msp_remove(struct i2c_client *client)msp_reset (client);v4l2_ctrl_handler_free (&state->hdl); +media_entity_cleanup (&state->sd.entity); }/* ----------------------------------------------------------------------- */
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH 3/5] media: i2c: msp3400-driver: Add missing media_entity_cleanup()
Hi Biren
Quoted 14 lines · Biren Pandya
The probe error paths and remove function are missing calls to
media_entity_cleanup(). Add them to prevent memory leaks if pads are dynamically allocated.Signed-off-by Biren Pandya <[email protected]>--- drivers/media/i2c/msp3400-driver.c | 2 ++ 1 file changed, 2 insertions(+)drivers/media/i2c/msp3400-driver.c +0
-0
drivers/media/i2c/msp3400-driver.c static int msp_probe(struct i2c_client *client) · line 815
Quoted 4 lines
drivers/media/i2c/msp3400-driver.c +1
-0@@ -812,6 +812,7 @@ static int msp_probe(struct i2c_client *client)int err = hdl->error;v4l2_ctrl_handler_free (hdl); +media_entity_cleanup (&sd->entity);
This driver really seems a relic from the past, but if you want to add media_entity_cleanup() to it, there is one previous error path after media_entity_pads_init() where you might want to do that.
Quoted 15 lines
drivers/media/i2c/msp3400-driver.c +1
-1return err; }@@ -865,6 +866,7 @@ static void msp_remove(struct i2c_client *client)msp_reset (client);v4l2_ctrl_handler_free (&state->hdl); +media_entity_cleanup (&state->sd.entity); }/* ----------------------------------------------------------------------- */ --2.50.1 (Apple Git-155)
PATCH 4/5 media: i2c: mt9v011: Add missing media_entity_cleanup()
In reply to Biren PandyaThe probe error paths and remove function are missing calls to media_entity_cleanup(). Add them to prevent memory leaks if pads are dynamically allocated.
--- drivers/media/i2c/mt9v011.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/i2c/mt9v011.c +3 -0
@@ -520,6 +520,7 @@ static int mt9v011_probe(struct i2c_client *c) (version != MT9V011_REV_B_VERSION)) {v4l2_info (sd,"*** unknown micron chip detected (0x%04x).\n" , version); +media_entity_cleanup (&sd->entity);return -EINVAL ; }
@@ -542,6 +543,7 @@ static int mt9v011_probe(struct i2c_client *c)v4l2_err (sd,"control initialization error %d\n" , ret);v4l2_ctrl_handler_free (&core->ctrls); +media_entity_cleanup (&sd->entity);return ret; } core->sd.ctrl_handler = &core->ctrls;
@@ -577,6 +579,7 @@ static void mt9v011_remove(struct i2c_client *c)v4l2_device_unregister_subdev (sd);v4l2_ctrl_handler_free (&core->ctrls); +media_entity_cleanup (&sd->entity); }/* ----------------------------------------------------------------------- */
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 5/5 media: i2c: saa7115: Add missing media_entity_cleanup()
In reply to Biren PandyaThe probe error paths and remove function are missing calls to media_entity_cleanup(). Add them to prevent memory leaks if pads are dynamically allocated.
--- drivers/media/i2c/saa7115.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/i2c/saa7115.c +2 -0
@@ -1867,6 +1867,7 @@ static int saa711x_probe(struct i2c_client *client)int err = hdl->error;v4l2_ctrl_handler_free (hdl); +media_entity_cleanup (&sd->entity);return err; }v4l2_ctrl_auto_cluster (2 , &state->agc,0 , true);
@@ -1925,6 +1926,7 @@ static void saa711x_remove(struct i2c_client *client)v4l2_device_unregister_subdev (sd);v4l2_ctrl_handler_free (sd->ctrl_handler); +media_entity_cleanup (&sd->entity); }static const struct i2c_device_id saa711x_id[] = {
Signature · 1 line
2.50.1 (Apple Git-155)