Skip to contentSkip to conversation

media: vimc: bug fixes related to memory management

PATCH Superseded Dafna Hirschfeld 3 participants 10 messages Oct 1, 2019 Media (V4L/DVB)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover media: vimc: bug fixes related to memory management

This patchset has 3 patches fixing 3 bugs in vimc. The patchset is rebased on top of v5 of the patchset 'media: vimc: Collapse component structure into a single monolithic driver' sent by 'Shuah Khan'

Dafna Hirschfeld (3):
media: vimc: initialize vim entity pointers to NULL
media: vimc: sensor: register subdevice only after initialization
media: vimc: move media_entity_cleanup to release callbacks

 drivers/media/platform/vimc/vimc-capture.c |  2 +-
 drivers/media/platform/vimc/vimc-common.c  |  1 -
 drivers/media/platform/vimc/vimc-core.c    |  8 +++-----
 drivers/media/platform/vimc/vimc-debayer.c |  1 +
 drivers/media/platform/vimc/vimc-scaler.c  |  1 +
 drivers/media/platform/vimc/vimc-sensor.c  | 21 +++++++++++----------
 6 files changed, 17 insertions(+), 17 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 media: vimc: initialize vim entity pointers to NULL

since NULL value for vimc entity pointer indicates that entity creation failed and this is tested, the pointers should be initialized to NULL.

---
 drivers/media/platform/vimc/vimc-core.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/platform/vimc/vimc-core.c +3 -5
index 6e3e5c91ae39..32a79e578b78 100644
@@ -160,19 +160,17 @@ static int vimc_create_links(struct vimc_device *vimc)
 static int vimc_add_subdevs(struct vimc_device *vimc)
 {
 	unsigned int i;
-	struct vimc_ent_device *ved;
 
 	for (i = 0; i < vimc->pipe_cfg->num_ents; i++) {
 		dev_dbg(&vimc->pdev.dev, "new entity for %s\n",
 			vimc->pipe_cfg->ents[i].name);
-		ved = vimc->pipe_cfg->ents[i].add(vimc,
+		vimc->ent_devs[i] = vimc->pipe_cfg->ents[i].add(vimc,
 					vimc->pipe_cfg->ents[i].name);
-		if (!ved) {
+		if (!vimc->ent_devs[i]) {
 			dev_err(&vimc->pdev.dev, "add new entity for %s\n",
 				vimc->pipe_cfg->ents[i].name);
 			return -EINVAL;
 		}
-		vimc->ent_devs[i] = ved;
 	}
 	return 0;
 }
@@ -199,7 +197,7 @@ static int vimc_register_devices(struct vimc_device *vimc)
 	}
 
 	/* allocate ent_devs */
-	vimc->ent_devs = kmalloc_array(vimc->pipe_cfg->num_ents,
+	vimc->ent_devs = kcalloc(vimc->pipe_cfg->num_ents,
 				       sizeof(*vimc->ent_devs),
 				       GFP_KERNEL);
 	if (!vimc->ent_devs)
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 1/3] media: vimc: initialize vim entity pointers to NULL

Hi Dafna,

Quoted 3 lines · Dafna Hirschfeld

since NULL value for vimc entity pointer indicates that entity creation failed and this is tested, the pointers should be initialized to NULL.

Nice catch :)

Quoted 22 lines
---
 drivers/media/platform/vimc/vimc-core.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/platform/vimc/vimc-core.c +1 -2
index 6e3e5c91ae39..32a79e578b78 100644
@@ -160,19 +160,17 @@ static int vimc_create_links(struct vimc_device *vimc)
 static int vimc_add_subdevs(struct vimc_device *vimc)
 {
 	unsigned int i;
-	struct vimc_ent_device *ved;
 
 	for (i = 0; i < vimc->pipe_cfg->num_ents; i++) {
 		dev_dbg(&vimc->pdev.dev, "new entity for %s\n",
 			vimc->pipe_cfg->ents[i].name);
-		ved = vimc->pipe_cfg->ents[i].add(vimc,
+		vimc->ent_devs[i] = vimc->pipe_cfg->ents[i].add(vimc,
 					vimc->pipe_cfg->ents[i].name);

drivers/media/platform/vimc/vimc-core.c static int vimc_create_links(struct vimc_device *vimc) · line 176

Quoted 10 lines
drivers/media/platform/vimc/vimc-core.c +1 -2
-		if (!ved) {
+		if (!vimc->ent_devs[i]) {
 			dev_err(&vimc->pdev.dev, "add new entity for %s\n",
 				vimc->pipe_cfg->ents[i].name);
 			return -EINVAL;
 		}
-		vimc->ent_devs[i] = ved;
 	}
 	return 0;
 }

I believe just the kcalloc bellow should fix the issue.
But if you want to do this cleanup anyway, I would suggest sending a separate patch for it.

drivers/media/platform/vimc/vimc-core.c static int vimc_register_devices(struct vimc_device *vimc) · line 202

Quoted 8 lines
drivers/media/platform/vimc/vimc-core.c +1 -1
@@ -199,7 +197,7 @@ static int vimc_register_devices(struct vimc_device *vimc)
 	}
 
 	/* allocate ent_devs */
-	vimc->ent_devs = kmalloc_array(vimc->pipe_cfg->num_ents,
+	vimc->ent_devs = kcalloc(vimc->pipe_cfg->num_ents,
 				       sizeof(*vimc->ent_devs),
 				       GFP_KERNEL);

Could you fix the alignment of the params here?

Thanks
Helen

Quoted 2 lines
drivers/media/platform/vimc/vimc-core.c +0 -0
 	if (!vimc->ent_devs)
#3 lore raw

Re: [PATCH 1/3] media: vimc: initialize vim entity pointers to NULL

Hi Dafna, hi Helen,

W dniu 01.10.2019 o 19:19, Helen Koike pisze:

Quoted 48 lines

Hi Dafna,

Quoted 3 lines · Dafna Hirschfeld

since NULL value for vimc entity pointer indicates that entity creation failed and this is tested, the pointers should be initialized to NULL.

Nice catch :)

Quoted 22 lines
---
  drivers/media/platform/vimc/vimc-core.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/platform/vimc/vimc-core.c +1 -2
index 6e3e5c91ae39..32a79e578b78 100644
@@ -160,19 +160,17 @@ static int vimc_create_links(struct vimc_device *vimc)
  static int vimc_add_subdevs(struct vimc_device *vimc)
  {
  	unsigned int i;
-	struct vimc_ent_device *ved;
 
  	for (i = 0; i < vimc->pipe_cfg->num_ents; i++) {
  		dev_dbg(&vimc->pdev.dev, "new entity for %s\n",
  			vimc->pipe_cfg->ents[i].name);
-		ved = vimc->pipe_cfg->ents[i].add(vimc,
+		vimc->ent_devs[i] = vimc->pipe_cfg->ents[i].add(vimc,
  					vimc->pipe_cfg->ents[i].name);

drivers/media/platform/vimc/vimc-core.c static int vimc_create_links(struct vimc_device *vimc) · line 176

Quoted 10 lines
drivers/media/platform/vimc/vimc-core.c +1 -2
-		if (!ved) {
+		if (!vimc->ent_devs[i]) {
  			dev_err(&vimc->pdev.dev, "add new entity for %s\n",
  				vimc->pipe_cfg->ents[i].name);
  			return -EINVAL;
  		}
-		vimc->ent_devs[i] = ved;
  	}
  	return 0;
  }

I believe just the kcalloc bellow should fix the issue.
But if you want to do this cleanup anyway, I would suggest sending a separate patch for it.

Quoted 3 lines
drivers/media/platform/vimc/vimc-core.c +0 -0
@@ -199,7 +197,7 @@ static int vimc_register_devices(struct vimc_device *vimc)
  	}
 
Quoted 7 lines

drivers/media/platform/vimc/vimc-core.c static int vimc_register_devices(struct vimc_device *vimc) · line 202

Quoted 5 lines
drivers/media/platform/vimc/vimc-core.c +1 -1
  	/* allocate ent_devs */
-	vimc->ent_devs = kmalloc_array(vimc->pipe_cfg->num_ents,
+	vimc->ent_devs = kcalloc(vimc->pipe_cfg->num_ents,
  				       sizeof(*vimc->ent_devs),
  				       GFP_KERNEL);

Could you fix the alignment of the params here?

Isn't the above change (kmalloc_array() to kcalloc()) alone enough to ensure the promise from the patch title is fulfilled?

In other words, why remove the "ved" local variable in vimc_add_subdevs()?

Andrzej

#4 lore raw

Re: [PATCH 1/3] media: vimc: initialize vim entity pointers to NULL

Quoted 57 lines · Andrzej Pietrasiewicz

Hi Dafna, hi Helen,

W dniu 01.10.2019 o 19:19, Helen Koike pisze:

Quoted 44 lines

Hi Dafna,

Quoted 3 lines · Dafna Hirschfeld

since NULL value for vimc entity pointer indicates that entity creation failed and this is tested, the pointers should be initialized to NULL.

Nice catch :)

Quoted 21 lines

---
  drivers/media/platform/vimc/vimc-core.c | 8 +++-----

  1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/platform/vimc/vimc-core.c +1 -2
index 6e3e5c91ae39..32a79e578b78 100644
@@ -160,19 +160,17 @@ static int vimc_create_links(struct vimc_device *vimc)
   static int vimc_add_subdevs(struct vimc_device *vimc)
   {
       unsigned int i;
-    struct vimc_ent_device *ved;
         for (i = 0; i < vimc->pipe_cfg->num_ents; i++) {
           dev_dbg(&vimc->pdev.dev, "new entity for %s\n",
               vimc->pipe_cfg->ents[i].name);
-        ved = vimc->pipe_cfg->ents[i].add(vimc,
+        vimc->ent_devs[i] = vimc->pipe_cfg->ents[i].add(vimc,
                       vimc->pipe_cfg->ents[i].name);

drivers/media/platform/vimc/vimc-core.c static int vimc_create_links(struct vimc_device *vimc) · line 175

Quoted 10 lines
drivers/media/platform/vimc/vimc-core.c +1 -2
-        if (!ved) {
+        if (!vimc->ent_devs[i]) {
               dev_err(&vimc->pdev.dev, "add new entity for %s\n",
                   vimc->pipe_cfg->ents[i].name);
               return -EINVAL;
           }
-        vimc->ent_devs[i] = ved;
       }
       return 0;
   }

I believe just the kcalloc bellow should fix the issue.
But if you want to do this cleanup anyway, I would suggest sending a separate patch for it.

Quoted 9 lines

drivers/media/platform/vimc/vimc-core.c static int vimc_register_devices(struct vimc_device *vimc) · line 201

Quoted 7 lines
drivers/media/platform/vimc/vimc-core.c +1 -1
@@ -199,7 +197,7 @@ static int vimc_register_devices(struct vimc_device *vimc)
       }
         /* allocate ent_devs */
-    vimc->ent_devs = kmalloc_array(vimc->pipe_cfg->num_ents,
+    vimc->ent_devs = kcalloc(vimc->pipe_cfg->num_ents,
                          sizeof(*vimc->ent_devs),
                          GFP_KERNEL);

Could you fix the alignment of the params here?

Quoted 2 lines

Isn't the above change (kmalloc_array() to kcalloc()) alone enough to ensure the promise from the patch title is fulfilled?

I fully agree. That is why I mentioned above in "I believe just the kcalloc bellow should fix the issue." Sorry if I wasn't clear.

Thanks
Helen

Quoted 4 lines

In other words, why remove the "ved" local variable in vimc_add_subdevs()?

Andrzej

#5 lore raw

Re: [PATCH 1/3] media: vimc: initialize vim entity pointers to NULL

W dniu 01.10.2019 o 19:35, Helen Koike pisze:

Quoted 1 line

<snip>

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

I believe just the kcalloc bellow should fix the issue.
But if you want to do this cleanup anyway, I would suggest sending a separate patch for it.

drivers/media/platform/vimc/vimc-core.c static int vimc_register_devices(struct vimc_device *vimc) · line 201

Quoted 7 lines
drivers/media/platform/vimc/vimc-core.c +1 -1
@@ -199,7 +197,7 @@ static int vimc_register_devices(struct vimc_device *vimc)
       }
         /* allocate ent_devs */
-    vimc->ent_devs = kmalloc_array(vimc->pipe_cfg->num_ents,
+    vimc->ent_devs = kcalloc(vimc->pipe_cfg->num_ents,
                          sizeof(*vimc->ent_devs),
                          GFP_KERNEL);

Could you fix the alignment of the params here?

Quoted 6 lines
Quoted 2 lines

Isn't the above change (kmalloc_array() to kcalloc()) alone enough to ensure the promise from the patch title is fulfilled?

I fully agree. That is why I mentioned above in "I believe just the kcalloc bellow should fix the issue." Sorry if I wasn't clear.

Thanks for teaching me how to read :D

Andrzej

#6 lore raw

PATCH 2/3 media: vimc: sensor: register subdevice only after initialization

In reply to Dafna Hirschfeld

vimc_sen_add function first registers the subdevice and then calls tpg_alloc. If tpg_alloc fails it unregisters the subdevice and then frees vsen, this cause double free since the release callback that follows subdevice unregistration also frees vsen.

---
 drivers/media/platform/vimc/vimc-sensor.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/media/platform/vimc/vimc-sensor.c +10 -10
index 46dc6a535abe..ee2306c08569 100644
@@ -358,6 +358,13 @@ struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc,
 		goto err_free_vsen;
 	}
 
+	/* Initialize the test pattern generator */
+	tpg_init(&vsen->tpg, vsen->mbus_format.width,
+		 vsen->mbus_format.height);
+	ret = tpg_alloc(&vsen->tpg, VIMC_FRAME_MAX_WIDTH);
+	if (ret)
+		goto err_free_hdl;
+
 	/* Initialize ved and sd */
 	ret = vimc_ent_sd_register(&vsen->ved, &vsen->sd, v4l2_dev,
 				   vcfg_name,
@@ -365,7 +372,7 @@ struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc,
 				   (const unsigned long[1]) {MEDIA_PAD_FL_SOURCE},
 				   &vimc_sen_int_ops, &vimc_sen_ops);
 	if (ret)
-		goto err_free_hdl;
+		goto err_free_tpg;
 
 	vsen->ved.process_frame = vimc_sen_process_frame;
 	vsen->dev = &vimc->pdev.dev;
@@ -373,17 +380,10 @@ struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc,
 	/* Initialize the frame format */
 	vsen->mbus_format = fmt_default;
 
-	/* Initialize the test pattern generator */
-	tpg_init(&vsen->tpg, vsen->mbus_format.width,
-		 vsen->mbus_format.height);
-	ret = tpg_alloc(&vsen->tpg, VIMC_FRAME_MAX_WIDTH);
-	if (ret)
-		goto err_unregister_ent_sd;
-
 	return &vsen->ved;
 
-err_unregister_ent_sd:
-	vimc_ent_sd_unregister(&vsen->ved,  &vsen->sd);
+err_free_tpg:
+	tpg_free(&vsen->tpg);
 err_free_hdl:
 	v4l2_ctrl_handler_free(&vsen->hdl);
 err_free_vsen:
Signature · 1 line
2.20.1
Acked-by on v1 2/3
#7 lore raw

Re: [PATCH 2/3] media: vimc: sensor: register subdevice only after initialization

Quoted 6 lines · Dafna Hirschfeld

vimc_sen_add function first registers the subdevice and then calls tpg_alloc. If tpg_alloc fails it unregisters the subdevice and then frees vsen, this cause double free since the release callback that follows subdevice unregistration also frees vsen.

Quoted 52 lines
---
 drivers/media/platform/vimc/vimc-sensor.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/media/platform/vimc/vimc-sensor.c +10 -10
index 46dc6a535abe..ee2306c08569 100644
@@ -358,6 +358,13 @@ struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc,
 		goto err_free_vsen;
 	}
 
+	/* Initialize the test pattern generator */
+	tpg_init(&vsen->tpg, vsen->mbus_format.width,
+		 vsen->mbus_format.height);
+	ret = tpg_alloc(&vsen->tpg, VIMC_FRAME_MAX_WIDTH);
+	if (ret)
+		goto err_free_hdl;
+
 	/* Initialize ved and sd */
 	ret = vimc_ent_sd_register(&vsen->ved, &vsen->sd, v4l2_dev,
 				   vcfg_name,
@@ -365,7 +372,7 @@ struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc,
 				   (const unsigned long[1]) {MEDIA_PAD_FL_SOURCE},
 				   &vimc_sen_int_ops, &vimc_sen_ops);
 	if (ret)
-		goto err_free_hdl;
+		goto err_free_tpg;
 
 	vsen->ved.process_frame = vimc_sen_process_frame;
 	vsen->dev = &vimc->pdev.dev;
@@ -373,17 +380,10 @@ struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc,
 	/* Initialize the frame format */
 	vsen->mbus_format = fmt_default;
 
-	/* Initialize the test pattern generator */
-	tpg_init(&vsen->tpg, vsen->mbus_format.width,
-		 vsen->mbus_format.height);
-	ret = tpg_alloc(&vsen->tpg, VIMC_FRAME_MAX_WIDTH);
-	if (ret)
-		goto err_unregister_ent_sd;
-
 	return &vsen->ved;
 
-err_unregister_ent_sd:
-	vimc_ent_sd_unregister(&vsen->ved,  &vsen->sd);
+err_free_tpg:
+	tpg_free(&vsen->tpg);
 err_free_hdl:
 	v4l2_ctrl_handler_free(&vsen->hdl);
 err_free_vsen:
#8 lore raw

PATCH 3/3 media: vimc: move media_entity_cleanup to release callbacks

In reply to Dafna Hirschfeld

according to the docs, this function must be called during the cleanup phase after unregistering the entity.

---
 drivers/media/platform/vimc/vimc-capture.c | 2 +-
 drivers/media/platform/vimc/vimc-common.c  | 1 -
 drivers/media/platform/vimc/vimc-debayer.c | 1 +
 drivers/media/platform/vimc/vimc-scaler.c  | 1 +
 drivers/media/platform/vimc/vimc-sensor.c  | 1 +
 5 files changed, 4 insertions(+), 2 deletions(-)
drivers/media/platform/vimc/vimc-capture.c +1 -1
index 602f80323031..5f353c20e605 100644
@@ -330,6 +330,7 @@ static void vimc_cap_release(struct video_device *vdev)
 	struct vimc_cap_device *vcap =
 		container_of(vdev, struct vimc_cap_device, vdev);
 
+	media_entity_cleanup(vcap->ved.ent);
 	vimc_pads_cleanup(vcap->ved.pads);
 	kfree(vcap);
 }
@@ -340,7 +341,6 @@ void vimc_cap_rm(struct vimc_device *vimc, struct vimc_ent_device *ved)
 
 	vcap = container_of(ved, struct vimc_cap_device, ved);
 	vb2_queue_release(&vcap->queue);
-	media_entity_cleanup(ved->ent);
 	video_unregister_device(&vcap->vdev);
 }
 
drivers/media/platform/vimc/vimc-common.c +0 -1
index a3120f4f7a90..999bc353fb10 100644
@@ -423,7 +423,6 @@ EXPORT_SYMBOL_GPL(vimc_ent_sd_register);
 
 void vimc_ent_sd_unregister(struct vimc_ent_device *ved, struct v4l2_subdev *sd)
 {
-	media_entity_cleanup(ved->ent);
 	v4l2_device_unregister_subdev(sd);
 }
 EXPORT_SYMBOL_GPL(vimc_ent_sd_unregister);
drivers/media/platform/vimc/vimc-debayer.c +1 -0
index feac47d79449..e1bad6713cde 100644
@@ -477,6 +477,7 @@ static void vimc_deb_release(struct v4l2_subdev *sd)
 	struct vimc_deb_device *vdeb =
 				container_of(sd, struct vimc_deb_device, sd);
 
+	media_entity_cleanup(vdeb->ved.ent);
 	vimc_pads_cleanup(vdeb->ved.pads);
 	kfree(vdeb);
 }
drivers/media/platform/vimc/vimc-scaler.c +1 -0
index a6a3cc5be872..1982bc089af5 100644
@@ -336,6 +336,7 @@ static void vimc_sca_release(struct v4l2_subdev *sd)
 	struct vimc_sca_device *vsca =
 				container_of(sd, struct vimc_sca_device, sd);
 
+	media_entity_cleanup(vsca->ved.ent);
 	vimc_pads_cleanup(vsca->ved.pads);
 	kfree(vsca);
 }
drivers/media/platform/vimc/vimc-sensor.c +1 -0
index ee2306c08569..63fe024ccea5 100644
@@ -291,6 +291,7 @@ static void vimc_sen_release(struct v4l2_subdev *sd)
 
 	v4l2_ctrl_handler_free(&vsen->hdl);
 	tpg_free(&vsen->tpg);
+	media_entity_cleanup(vsen->ved.ent);
 	vimc_pads_cleanup(vsen->ved.pads);
 	kfree(vsen);
 }
Signature · 1 line
2.20.1
Acked-by on v1 3/3
#9 lore raw

Re: [PATCH 3/3] media: vimc: move media_entity_cleanup to release callbacks

Hi Dafna,

Thanks for your patch

Quoted 4 lines · Dafna Hirschfeld

according to the docs, this function must be called during the cleanup phase after unregistering the entity.

I just have one note below.

Quoted 33 lines
---
 drivers/media/platform/vimc/vimc-capture.c | 2 +-
 drivers/media/platform/vimc/vimc-common.c  | 1 -
 drivers/media/platform/vimc/vimc-debayer.c | 1 +
 drivers/media/platform/vimc/vimc-scaler.c  | 1 +
 drivers/media/platform/vimc/vimc-sensor.c  | 1 +
 5 files changed, 4 insertions(+), 2 deletions(-)
drivers/media/platform/vimc/vimc-capture.c +1 -1
index 602f80323031..5f353c20e605 100644
@@ -330,6 +330,7 @@ static void vimc_cap_release(struct video_device *vdev)
 	struct vimc_cap_device *vcap =
 		container_of(vdev, struct vimc_cap_device, vdev);
 
+	media_entity_cleanup(vcap->ved.ent);
 	vimc_pads_cleanup(vcap->ved.pads);
 	kfree(vcap);
 }
@@ -340,7 +341,6 @@ void vimc_cap_rm(struct vimc_device *vimc, struct vimc_ent_device *ved)
 
 	vcap = container_of(ved, struct vimc_cap_device, ved);
 	vb2_queue_release(&vcap->queue);
-	media_entity_cleanup(ved->ent);
 	video_unregister_device(&vcap->vdev);
 }
 
drivers/media/platform/vimc/vimc-common.c +0 -0
index a3120f4f7a90..999bc353fb10 100644

drivers/media/platform/vimc/vimc-common.c EXPORT_SYMBOL_GPL(vimc_ent_sd_register); · line 424

Quoted 2 lines
drivers/media/platform/vimc/vimc-common.c +0 -0
@@ -423,7 +423,6 @@ EXPORT_SYMBOL_GPL(vimc_ent_sd_register);
 
 void vimc_ent_sd_unregister(struct vimc_ent_device *ved, struct v4l2_subdev *sd)

Could you get rid of this function as well?
There is no point in keeping it anymore, feel free to send in another patch.

Thanks
Helen

Quoted 42 lines
drivers/media/platform/vimc/vimc-common.c +0 -1
 {
-	media_entity_cleanup(ved->ent);
 	v4l2_device_unregister_subdev(sd);
 }
 EXPORT_SYMBOL_GPL(vimc_ent_sd_unregister);
drivers/media/platform/vimc/vimc-debayer.c +1 -0
index feac47d79449..e1bad6713cde 100644
@@ -477,6 +477,7 @@ static void vimc_deb_release(struct v4l2_subdev *sd)
 	struct vimc_deb_device *vdeb =
 				container_of(sd, struct vimc_deb_device, sd);
 
+	media_entity_cleanup(vdeb->ved.ent);
 	vimc_pads_cleanup(vdeb->ved.pads);
 	kfree(vdeb);
 }
drivers/media/platform/vimc/vimc-scaler.c +1 -0
index a6a3cc5be872..1982bc089af5 100644
@@ -336,6 +336,7 @@ static void vimc_sca_release(struct v4l2_subdev *sd)
 	struct vimc_sca_device *vsca =
 				container_of(sd, struct vimc_sca_device, sd);
 
+	media_entity_cleanup(vsca->ved.ent);
 	vimc_pads_cleanup(vsca->ved.pads);
 	kfree(vsca);
 }
drivers/media/platform/vimc/vimc-sensor.c +1 -0
index ee2306c08569..63fe024ccea5 100644
@@ -291,6 +291,7 @@ static void vimc_sen_release(struct v4l2_subdev *sd)
 
 	v4l2_ctrl_handler_free(&vsen->hdl);
 	tpg_free(&vsen->tpg);
+	media_entity_cleanup(vsen->ved.ent);
 	vimc_pads_cleanup(vsen->ved.pads);
 	kfree(vsen);
 }