Skip to contentSkip to conversation

media: platform: stm32-csi: Add missing media_entity_cleanup()

PATCH New Biren Pandya 1 participant 9 messages Jun 14

Subsystems (12)
lore
Share & tools
lore
#0 lore raw

PATCH v2 6/22 media: platform: stm32-csi: Add missing media_entity_cleanup()

Fixes dcb0f4c16be5 ("media: stm32: csi: addition of the STM32 CSI driver")

The media_entity_pads_init() (or media_entity_init()) function initializes the media entity, but the driver forgets to call media_entity_cleanup() in the error paths and remove function. Add the missing calls to fix the API violation and prevent potential future memory leaks.

---
 drivers/media/platform/st/stm32/stm32-csi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/st/stm32/stm32-csi.c +2 -0
index fd2b6dfbd44c..0847fd347d56 100644
@@ -1060,6 +1060,7 @@ static int stm32_csi_probe(struct platform_device *pdev)
 
 err_cleanup:
 	v4l2_async_nf_cleanup(&csidev->notifier);
+	media_entity_cleanup(&csidev->sd.entity);
 	return ret;
 }
 
@@ -1068,6 +1069,7 @@ static void stm32_csi_remove(struct platform_device *pdev)
 	struct stm32_csi_dev *csidev = platform_get_drvdata(pdev);
 
 	v4l2_async_unregister_subdev(&csidev->sd);
+	media_entity_cleanup(&csidev->sd.entity);
 
 	pm_runtime_disable(&pdev->dev);
 }
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

PATCH v2 8/22 media: platform: microchip-isc-scaler: Add missing media_entity_cleanup()

Fixes 920b2665f392 ("media: microchip: microchip-isc: prepare for media controller support")

The media_entity_pads_init() (or media_entity_init()) function initializes the media entity, but the driver forgets to call media_entity_cleanup() in the error paths and remove function. Add the missing calls to fix the API violation and prevent potential future memory leaks.

---
 drivers/media/platform/microchip/microchip-isc-scaler.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/media/platform/microchip/microchip-isc-scaler.c +7 -0
index e83463543e21..c368c66d9c8b 100644
@@ -222,6 +222,7 @@ int isc_scaler_init(struct isc_device *isc)
 	ret = v4l2_device_register_subdev(&isc->v4l2_dev, &isc->scaler_sd);
 	if (ret < 0) {
 		dev_err(isc->dev, "scaler sd failed to register subdev\n");
+		media_entity_cleanup(&isc->scaler_sd.entity);
 		return ret;
 	}
 
@@ -229,6 +230,12 @@ int isc_scaler_init(struct isc_device *isc)
 }
 EXPORT_SYMBOL_GPL(isc_scaler_init);
 
+void isc_scaler_unregister(struct isc_device *isc)
+{
+	media_entity_cleanup(&isc->scaler_sd.entity);
+}
+EXPORT_SYMBOL_GPL(isc_scaler_unregister);
+
 int isc_scaler_link(struct isc_device *isc)
 {
 	int ret;
Signature · 6 lines
2.50.1 (Apple Git-155)


 drivers/media/platform/microchip/microchip-isc-base.c | 1 +
 drivers/media/platform/microchip/microchip-isc.h      | 1 +
 2 files changed, 2 insertions(+)
drivers/media/platform/microchip/microchip-isc-base.c +1 -0
index a7cdc743fda7..27e180aff9a2 100644
@@ -1949,6 +1949,7 @@ EXPORT_SYMBOL_GPL(isc_mc_init);
 
 void isc_mc_cleanup(struct isc_device *isc)
 {
+	isc_scaler_unregister(isc);
 	media_entity_cleanup(&isc->video_dev.entity);
 	media_device_cleanup(&isc->mdev);
 }
drivers/media/platform/microchip/microchip-isc.h +1 -0
index ad4e98a1dd8f..40a54d7d7e10 100644
@@ -392,6 +392,7 @@ void microchip_isc_clk_cleanup(struct isc_device *isc);
 
 int isc_scaler_link(struct isc_device *isc);
 int isc_scaler_init(struct isc_device *isc);
+void isc_scaler_unregister(struct isc_device *isc);
 int isc_mc_init(struct isc_device *isc, u32 ver);
 void isc_mc_cleanup(struct isc_device *isc);
 
Signature · 1 line
2.50.1 (Apple Git-155)
#2 lore raw

PATCH v2 9/22 media: platform: cdns-csi2tx: Add missing media_entity_cleanup()

In reply to Biren Pandya
Fixes 6f684d4fcce5 ("media: v4l: cadence: Add Cadence MIPI-CSI2 TX driver")

The media_entity_pads_init() (or media_entity_init()) function initializes the media entity, but the driver forgets to call media_entity_cleanup() in the error paths and remove function. Add the missing calls to fix the API violation and prevent potential future memory leaks.

---
 drivers/media/platform/cadence/cdns-csi2tx.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/cadence/cdns-csi2tx.c +4 -1
index 629b0fa838a2..df1598091d57 100644
@@ -620,7 +620,7 @@ static int csi2tx_probe(struct platform_device *pdev)
 
 	ret = v4l2_async_register_subdev(&csi2tx->subdev);
 	if (ret < 0)
-		goto err_free_priv;
+		goto err_entity_cleanup;
 
 	dev_info(&pdev->dev,
 		 "Probed CSI2TX with %u/%u lanes, %u streams, %s D-PHY\n",
@@ -629,6 +629,8 @@ static int csi2tx_probe(struct platform_device *pdev)
 
 	return 0;
 
+err_entity_cleanup:
+	media_entity_cleanup(&csi2tx->subdev.entity);
 err_free_priv:
 	kfree(csi2tx);
 	return ret;
@@ -639,6 +641,7 @@ static void csi2tx_remove(struct platform_device *pdev)
 	struct csi2tx_priv *csi2tx = platform_get_drvdata(pdev);
 
 	v4l2_async_unregister_subdev(&csi2tx->subdev);
+	media_entity_cleanup(&csi2tx->subdev.entity);
 	kfree(csi2tx);
 }
 
Signature · 1 line
2.50.1 (Apple Git-155)
#3 lore raw

PATCH v2 10/22 media: platform: rcar-csi2: Add missing media_entity_cleanup()

In reply to Biren Pandya

The media_entity_pads_init() (or media_entity_init()) function initializes the media entity, but the driver forgets to call media_entity_cleanup() in the error paths and remove function. Add the missing calls to fix the API violation and prevent potential future memory leaks.

---
 drivers/media/platform/renesas/rcar-csi2.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/renesas/rcar-csi2.c +2 -0
index 7305cc4a04cb..c4e35cac97f4 100644
@@ -2634,6 +2634,7 @@ static int rcsi2_probe(struct platform_device *pdev)
 error_async:
 	v4l2_async_nf_unregister(&priv->notifier);
 	v4l2_async_nf_cleanup(&priv->notifier);
+	media_entity_cleanup(&priv->subdev.entity);
 
 	return ret;
 }
@@ -2646,6 +2647,7 @@ static void rcsi2_remove(struct platform_device *pdev)
 	v4l2_async_nf_cleanup(&priv->notifier);
 	v4l2_async_unregister_subdev(&priv->subdev);
 	v4l2_subdev_cleanup(&priv->subdev);
+	media_entity_cleanup(&priv->subdev.entity);
 
 	pm_runtime_disable(&pdev->dev);
 }
Signature · 1 line
2.50.1 (Apple Git-155)
#4 lore raw

PATCH v2 11/22 media: platform: csisp: Add missing media_entity_cleanup()

In reply to Biren Pandya

The media_entity_pads_init() (or media_entity_init()) function initializes the media entity, but the driver forgets to call media_entity_cleanup() in the error paths and remove function. Add the missing calls to fix the API violation and prevent potential future memory leaks.

---
 drivers/media/platform/renesas/rcar-isp/csisp.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/renesas/rcar-isp/csisp.c +2 -0
index 8fb2cc3b5650..51db5ad25c47 100644
@@ -556,6 +556,7 @@ static int risp_probe(struct platform_device *pdev)
 	v4l2_async_nf_cleanup(&isp->notifier);
 error_pm:
 	pm_runtime_disable(&pdev->dev);
+	media_entity_cleanup(&isp->subdev.entity);
 
 	return ret;
 }
@@ -569,6 +570,7 @@ static void risp_remove(struct platform_device *pdev)
 
 	v4l2_async_unregister_subdev(&isp->subdev);
 	v4l2_subdev_cleanup(&isp->subdev);
+	media_entity_cleanup(&isp->subdev.entity);
 
 	pm_runtime_disable(&pdev->dev);
 }
Signature · 1 line
2.50.1 (Apple Git-155)
#5 lore raw

PATCH v2 14/22 media: platform: cfe: Add missing media_entity_cleanup()

In reply to Biren Pandya
Fixes 6edb685abb2a ("media: raspberrypi: Add support for RP1-CFE")

The media_entity_pads_init() (or media_entity_init()) function initializes the media entity, but the driver forgets to call media_entity_cleanup() in the error paths and remove function. Add the missing calls to fix the API violation and prevent potential future memory leaks.

---
 drivers/media/platform/raspberrypi/rp1-cfe/cfe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/raspberrypi/rp1-cfe/cfe.c +2 -0
index 8375ed3e97b9..17c523d32db7 100644
@@ -2039,6 +2039,7 @@ static int cfe_register_node(struct cfe_device *cfe, int id)
 	if (ret) {
 		cfe_err(cfe, "Unable to register video device %s\n",
 			vdev->name);
+		media_entity_cleanup(&vdev->entity);
 		return ret;
 	}
 
@@ -2064,6 +2065,7 @@ static void cfe_unregister_nodes(struct cfe_device *cfe)
 		if (check_state(cfe, NODE_REGISTERED, i)) {
 			clear_state(cfe, NODE_REGISTERED, i);
 			video_unregister_device(&node->video_dev);
+			media_entity_cleanup(&node->video_dev.entity);
 		}
 	}
 }
Signature · 1 line
2.50.1 (Apple Git-155)
#6 lore raw

PATCH v2 15/22 media: platform: j721e-csi2rx: Add missing media_entity_cleanup()

In reply to Biren Pandya
Fixes b4a3d877dc92 ("media: ti: Add CSI2RX support for J721E")

The media_entity_pads_init() (or media_entity_init()) function initializes the media entity, but the driver forgets to call media_entity_cleanup() in the error paths and remove function. Add the missing calls to fix the API violation and prevent potential future memory leaks.

---
 drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +5 -1
index b75aa363d1bf..b88e3ac3dac8 100644
@@ -1079,13 +1079,16 @@ static int ti_csi2rx_v4l2_init(struct ti_csi2rx_dev *csi)
 	csi->v4l2_dev.mdev = mdev;
 
 	ret = v4l2_device_register(csi->dev, &csi->v4l2_dev);
-	if (ret)
+	if (ret) {
+		media_entity_cleanup(&csi->vdev.entity);
 		return ret;
+	}
 
 	ret = media_device_register(mdev);
 	if (ret) {
 		v4l2_device_unregister(&csi->v4l2_dev);
 		media_device_cleanup(mdev);
+		media_entity_cleanup(&csi->vdev.entity);
 		return ret;
 	}
 
@@ -1105,6 +1108,7 @@ static void ti_csi2rx_cleanup_v4l2(struct ti_csi2rx_dev *csi)
 	media_device_unregister(&csi->mdev);
 	v4l2_device_unregister(&csi->v4l2_dev);
 	media_device_cleanup(&csi->mdev);
+	media_entity_cleanup(&csi->vdev.entity);
 }
 
 static void ti_csi2rx_cleanup_subdev(struct ti_csi2rx_dev *csi)
Signature · 1 line
2.50.1 (Apple Git-155)
#7 lore raw

PATCH v2 16/22 media: platform: hantro_drv: Add missing media_entity_cleanup()

In reply to Biren Pandya

The media_entity_pads_init() (or media_entity_init()) function initializes the media entity, but the driver forgets to call media_entity_cleanup() in the error paths and remove function. Add the missing calls to fix the API violation and prevent potential future memory leaks.

---
 drivers/media/platform/verisilicon/hantro_drv.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/hantro_drv.c +9 -3
index 2e81877f640f..ad71c0402ef3 100644
@@ -771,8 +771,10 @@ static int hantro_register_entity(struct media_device *mdev,
 		return ret;
 
 	ret = media_device_register_entity(mdev, entity);
-	if (ret)
+	if (ret) {
+		media_entity_cleanup(entity);
 		return ret;
+	}
 
 	return 0;
 }
@@ -860,12 +862,13 @@ static int hantro_attach_func(struct hantro_dev *vpu,
 
 err_rel_entity2:
 	media_device_unregister_entity(&func->sink);
-
+	media_entity_cleanup(&func->sink);
 err_rel_entity1:
 	media_device_unregister_entity(&func->proc);
-
+	media_entity_cleanup(&func->proc);
 err_rel_entity0:
 	media_device_unregister_entity(&func->vdev.entity);
+	media_entity_cleanup(&func->vdev.entity);
 	return ret;
 }
 
@@ -878,6 +881,9 @@ static void hantro_detach_func(struct hantro_func *func)
 	media_device_unregister_entity(&func->sink);
 	media_device_unregister_entity(&func->proc);
 	media_device_unregister_entity(&func->vdev.entity);
+	media_entity_cleanup(&func->sink);
+	media_entity_cleanup(&func->proc);
+	media_entity_cleanup(&func->vdev.entity);
 }
 
 static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
Signature · 1 line
2.50.1 (Apple Git-155)
#8 lore raw

PATCH v2 21/22 media: usb: dvb-usb-v2: Add missing media_entity_cleanup()

In reply to Biren Pandya

The media_entity_pads_init() (or media_entity_init()) function initializes the media entity, but the driver forgets to call media_entity_cleanup() in the error paths and remove function. Add the missing calls to fix the API violation and prevent potential future memory leaks.

---
 drivers/media/usb/dvb-usb-v2/mxl111sf.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/media/usb/dvb-usb-v2/mxl111sf.c +20 -1
index 870ac3c8b085..0524685e220e 100644
@@ -900,8 +900,21 @@ static int mxl111sf_attach_tuner(struct dvb_usb_adapter *adap)
 		return ret;
 
 	ret = media_device_register_entity(mdev, &state->tuner);
-	if (ret)
+	if (ret) {
+		media_entity_cleanup(&state->tuner);
 		return ret;
+	}
+#endif
+	return 0;
+}
+
+static int mxl111sf_detach_tuner(struct dvb_usb_adapter *adap)
+{
+	struct mxl111sf_state *state = adap_to_priv(adap);
+
+#ifdef CONFIG_MEDIA_CONTROLLER_DVB
+	media_device_unregister_entity(&state->tuner);
+	media_entity_cleanup(&state->tuner);
 #endif
 	return 0;
 }
@@ -1093,6 +1106,7 @@ static struct dvb_usb_device_properties mxl111sf_props_dvbt = {
 	.i2c_algo          = &mxl111sf_i2c_algo,
 	.frontend_attach   = mxl111sf_frontend_attach_dvbt,
 	.tuner_attach      = mxl111sf_attach_tuner,
+	.tuner_detach      = mxl111sf_detach_tuner,
 	.init              = mxl111sf_init,
 	.streaming_ctrl    = mxl111sf_ep4_streaming_ctrl,
 	.get_stream_config = mxl111sf_get_stream_config_dvbt,
@@ -1135,6 +1149,7 @@ static struct dvb_usb_device_properties mxl111sf_props_atsc = {
 	.i2c_algo          = &mxl111sf_i2c_algo,
 	.frontend_attach   = mxl111sf_frontend_attach_atsc,
 	.tuner_attach      = mxl111sf_attach_tuner,
+	.tuner_detach      = mxl111sf_detach_tuner,
 	.init              = mxl111sf_init,
 	.streaming_ctrl    = mxl111sf_ep6_streaming_ctrl,
 	.get_stream_config = mxl111sf_get_stream_config_atsc,
@@ -1177,6 +1192,7 @@ static struct dvb_usb_device_properties mxl111sf_props_mh = {
 	.i2c_algo          = &mxl111sf_i2c_algo,
 	.frontend_attach   = mxl111sf_frontend_attach_mh,
 	.tuner_attach      = mxl111sf_attach_tuner,
+	.tuner_detach      = mxl111sf_detach_tuner,
 	.init              = mxl111sf_init,
 	.streaming_ctrl    = mxl111sf_ep5_streaming_ctrl,
 	.get_stream_config = mxl111sf_get_stream_config_mh,
@@ -1246,6 +1262,7 @@ static struct dvb_usb_device_properties mxl111sf_props_atsc_mh = {
 	.i2c_algo          = &mxl111sf_i2c_algo,
 	.frontend_attach   = mxl111sf_frontend_attach_atsc_mh,
 	.tuner_attach      = mxl111sf_attach_tuner,
+	.tuner_detach      = mxl111sf_detach_tuner,
 	.init              = mxl111sf_init,
 	.streaming_ctrl    = mxl111sf_streaming_ctrl_atsc_mh,
 	.get_stream_config = mxl111sf_get_stream_config_atsc_mh,
@@ -1325,6 +1342,7 @@ static struct dvb_usb_device_properties mxl111sf_props_mercury = {
 	.i2c_algo          = &mxl111sf_i2c_algo,
 	.frontend_attach   = mxl111sf_frontend_attach_mercury,
 	.tuner_attach      = mxl111sf_attach_tuner,
+	.tuner_detach      = mxl111sf_detach_tuner,
 	.init              = mxl111sf_init,
 	.streaming_ctrl    = mxl111sf_streaming_ctrl_mercury,
 	.get_stream_config = mxl111sf_get_stream_config_mercury,
@@ -1396,6 +1414,7 @@ static struct dvb_usb_device_properties mxl111sf_props_mercury_mh = {
 	.i2c_algo          = &mxl111sf_i2c_algo,
 	.frontend_attach   = mxl111sf_frontend_attach_mercury_mh,
 	.tuner_attach      = mxl111sf_attach_tuner,
+	.tuner_detach      = mxl111sf_detach_tuner,
 	.init              = mxl111sf_init,
 	.streaming_ctrl    = mxl111sf_streaming_ctrl_mercury_mh,
 	.get_stream_config = mxl111sf_get_stream_config_mercury_mh,
Signature · 1 line
2.50.1 (Apple Git-155)