Introduce v4l2_async_nf_unregister_cleanup
Subsystems (46)
cover Introduce v4l2_async_nf_unregister_cleanup
Many drivers has
v4l2_async_nf_unregister(¬ifier);
v4l2_async_nf_cleanup(¬ifier);
Introduce a helper function to call both functions in one line.
---
Julien Massot (2):
media: v4l: async: Add v4l2_async_nf_unregister_cleanup
media: convert all drivers to use v4l2_async_nf_unregister_cleanup
drivers/media/i2c/ds90ub913.c | 10 ++-------- drivers/media/i2c/ds90ub953.c | 10 ++-------- drivers/media/i2c/ds90ub960.c | 10 ++-------- drivers/media/i2c/max9286.c | 3 +-- drivers/media/i2c/st-mipid02.c | 6 ++---- drivers/media/i2c/tc358746.c | 3 +-- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 6 ++---- drivers/media/pci/intel/ipu6/ipu6-isys.c | 8 +------- drivers/media/pci/intel/ivsc/mei_csi.c | 6 ++---- drivers/media/platform/atmel/atmel-isi.c | 3 +-- drivers/media/platform/cadence/cdns-csi2rx.c | 6 ++---- drivers/media/platform/intel/pxa_camera.c | 3 +-- drivers/media/platform/marvell/mcam-core.c | 6 ++---- drivers/media/platform/microchip/microchip-csi2dc.c | 3 +-- drivers/media/platform/microchip/microchip-isc-base.c | 6 ++---- drivers/media/platform/nxp/imx-mipi-csis.c | 6 ++---- drivers/media/platform/nxp/imx7-media-csi.c | 3 +-- drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c | 3 +-- drivers/media/platform/nxp/imx8mq-mipi-csi2.c | 6 ++---- drivers/media/platform/qcom/camss/camss.c | 3 +-- drivers/media/platform/renesas/rcar-csi2.c | 6 ++---- drivers/media/platform/renesas/rcar-isp.c | 6 ++---- drivers/media/platform/renesas/rcar-vin/rcar-core.c | 9 +++------ drivers/media/platform/renesas/rcar_drif.c | 3 +-- drivers/media/platform/renesas/renesas-ceu.c | 4 +--- drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c | 3 +-- drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c | 6 ++---- drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 3 +-- drivers/media/platform/samsung/exynos4-is/media-dev.c | 3 +-- drivers/media/platform/st/stm32/stm32-dcmi.c | 3 +-- .../media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c | 3 +-- drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c | 3 +-- .../media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.c | 3 +-- .../platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c | 3 +-- .../sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c | 3 +-- drivers/media/platform/ti/am437x/am437x-vpfe.c | 3 +-- drivers/media/platform/ti/cal/cal.c | 8 +------- drivers/media/platform/ti/davinci/vpif_capture.c | 3 +-- drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 10 ++-------- drivers/media/platform/ti/omap3isp/isp.c | 3 +-- drivers/media/platform/video-mux.c | 3 +-- drivers/media/platform/xilinx/xilinx-vipp.c | 3 +-- drivers/staging/media/deprecated/atmel/atmel-isc-base.c | 6 ++---- drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_proc.c | 3 +-- drivers/staging/media/tegra-video/vi.c | 3 +-- include/media/v4l2-async.h | 17 +++++++++++++++++ 46 files changed, 80 insertions(+), 153 deletions(-)
---
base-commit: 843a9f4a7a85988f2f3af98adf21797c2fd05ab1
change-id: 20240502-master-5deee133b4f5
Best regards,
Signature · 1 line
Julien Massot <[email protected]>
PATCH 1/2 media: v4l: async: Add v4l2_async_nf_unregister_cleanup
Many drivers are calling v4l2_async_nf_unregister, and v4l2_async_nf_cleanup, add a function to do it.
--- include/media/v4l2-async.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
include/media/v4l2-async.h +17 -0
@@ -304,6 +304,23 @@ void v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier);*/ void v4l2_async_nf_cleanup (struct v4l2_async_notifier *notifier); +/** +* v4l2_async_nf_unregister_cleanup - unregister and clean up notifier resources +* @notifier: the notifier the notifier to unregister and for which +* the resources are to be cleaned up +* +* Unregister a subdevice asynchronous device and release memory resources +* related to a notifier. +* Convenient function to call v4l2_async_nf_unregister() and +* v4l2_async_nf_cleanup(). +*/ +static inline void +v4l2_async_nf_unregister_cleanup (struct v4l2_async_notifier *notifier) +{ +v4l2_async_nf_unregister (notifier); +v4l2_async_nf_cleanup (notifier); +}; +/** * v4l2_async_register_subdev - registers a sub-device to the asynchronous * subdevice framework
Signature · 1 line
2.44.0
PATCH 2/2 media: convert all drivers to use v4l2_async_nf_unregister_cleanup
In reply to Julien MassotNow that we have a function to unregister and cleanup a notifier, use it!
This patch has been generated using the following Coccinelle script:
---------8<------------
@@
expression E1;
@@
- v4l2_async_nf_unregister(E1);
- v4l2_async_nf_cleanup(E1);
+ v4l2_async_nf_unregister_cleanup(E1);
---------8<------------
Manually removed helper functions doing the same
in various driver.
--- drivers/media/i2c/ds90ub913.c | 10 ++-------- drivers/media/i2c/ds90ub953.c | 10 ++-------- drivers/media/i2c/ds90ub960.c | 10 ++-------- drivers/media/i2c/max9286.c | 3 +-- drivers/media/i2c/st-mipid02.c | 6 ++---- drivers/media/i2c/tc358746.c | 3 +-- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 6 ++---- drivers/media/pci/intel/ipu6/ipu6-isys.c | 8 +------- drivers/media/pci/intel/ivsc/mei_csi.c | 6 ++---- drivers/media/platform/atmel/atmel-isi.c | 3 +-- drivers/media/platform/cadence/cdns-csi2rx.c | 6 ++---- drivers/media/platform/intel/pxa_camera.c | 3 +-- drivers/media/platform/marvell/mcam-core.c | 6 ++---- drivers/media/platform/microchip/microchip-csi2dc.c | 3 +-- drivers/media/platform/microchip/microchip-isc-base.c | 6 ++---- drivers/media/platform/nxp/imx-mipi-csis.c | 6 ++---- drivers/media/platform/nxp/imx7-media-csi.c | 3 +-- drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c | 3 +-- drivers/media/platform/nxp/imx8mq-mipi-csi2.c | 6 ++---- drivers/media/platform/qcom/camss/camss.c | 3 +-- drivers/media/platform/renesas/rcar-csi2.c | 6 ++---- drivers/media/platform/renesas/rcar-isp.c | 6 ++---- drivers/media/platform/renesas/rcar-vin/rcar-core.c | 9 +++------ drivers/media/platform/renesas/rcar_drif.c | 3 +-- drivers/media/platform/renesas/renesas-ceu.c | 4 +--- drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c | 3 +-- drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c | 6 ++---- drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 3 +-- drivers/media/platform/samsung/exynos4-is/media-dev.c | 3 +-- drivers/media/platform/st/stm32/stm32-dcmi.c | 3 +-- drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c | 3 +-- drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c | 3 +-- drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.c | 3 +-- drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c | 3 +-- .../platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c | 3 +-- drivers/media/platform/ti/am437x/am437x-vpfe.c | 3 +-- drivers/media/platform/ti/cal/cal.c | 8 +------- drivers/media/platform/ti/davinci/vpif_capture.c | 3 +-- drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 10 ++-------- drivers/media/platform/ti/omap3isp/isp.c | 3 +-- drivers/media/platform/video-mux.c | 3 +-- drivers/media/platform/xilinx/xilinx-vipp.c | 3 +-- drivers/staging/media/deprecated/atmel/atmel-isc-base.c | 6 ++---- drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_proc.c | 3 +-- drivers/staging/media/tegra-video/vi.c | 3 +-- 45 files changed, 63 insertions(+), 153 deletions(-)
drivers/media/i2c/ds90ub913.c +2 -8
@@ -595,12 +595,6 @@ static int ub913_v4l2_notifier_register(struct ub913_data *priv)return 0 ; } -static void ub913_v4l2_nf_unregister (struct ub913_data *priv) -{ -v4l2_async_nf_unregister (&priv->notifier); -v4l2_async_nf_cleanup (&priv->notifier); -} -static int ub913_register_clkout (struct ub913_data *priv) {struct device *dev = &priv->client->dev;
@@ -779,7 +773,7 @@ static int ub913_subdev_init(struct ub913_data *priv)return 0 ; err_unreg_notif: -ub913_v4l2_nf_unregister (priv); +v4l2_async_nf_unregister_cleanup (&priv->notifier); err_subdev_cleanup:v4l2_subdev_cleanup (&priv->sd); err_entity_cleanup:
@@ -791,7 +785,7 @@ static int ub913_subdev_init(struct ub913_data *priv)static void ub913_subdev_uninit (struct ub913_data *priv) {v4l2_async_unregister_subdev (&priv->sd); -ub913_v4l2_nf_unregister (priv); +v4l2_async_nf_unregister_cleanup (&priv->notifier);v4l2_subdev_cleanup (&priv->sd);fwnode_handle_put (priv->sd.fwnode);media_entity_cleanup (&priv->sd.entity);
drivers/media/i2c/ds90ub953.c +2 -8
@@ -811,12 +811,6 @@ static int ub953_v4l2_notifier_register(struct ub953_data *priv)return 0 ; } -static void ub953_v4l2_notifier_unregister (struct ub953_data *priv) -{ -v4l2_async_nf_unregister (&priv->notifier); -v4l2_async_nf_cleanup (&priv->notifier); -} -/* * Probing */
@@ -1277,7 +1271,7 @@ static int ub953_subdev_init(struct ub953_data *priv)return 0 ; err_unreg_notif: -ub953_v4l2_notifier_unregister (priv); +v4l2_async_nf_unregister_cleanup (&priv->notifier); err_free_state:v4l2_subdev_cleanup (&priv->sd); err_entity_cleanup:
@@ -1289,7 +1283,7 @@ static int ub953_subdev_init(struct ub953_data *priv)static void ub953_subdev_uninit (struct ub953_data *priv) {v4l2_async_unregister_subdev (&priv->sd); -ub953_v4l2_notifier_unregister (priv); +v4l2_async_nf_unregister_cleanup (&priv->notifier);v4l2_subdev_cleanup (&priv->sd);fwnode_handle_put (priv->sd.fwnode);media_entity_cleanup (&priv->sd.entity);
drivers/media/i2c/ds90ub960.c +2 -8
@@ -3639,12 +3639,6 @@ static int ub960_v4l2_notifier_register(struct ub960_data *priv)return 0 ; } -static void ub960_v4l2_notifier_unregister (struct ub960_data *priv) -{ -v4l2_async_nf_unregister (&priv->notifier); -v4l2_async_nf_cleanup (&priv->notifier); -} -static int ub960_create_subdev (struct ub960_data *priv) {struct device *dev = &priv->client->dev;
@@ -3705,7 +3699,7 @@ static int ub960_create_subdev(struct ub960_data *priv)return 0 ; err_unreg_notif: -ub960_v4l2_notifier_unregister (priv); +v4l2_async_nf_unregister_cleanup (&priv->notifier); err_subdev_cleanup:v4l2_subdev_cleanup (&priv->sd); err_entity_cleanup:
@@ -3718,7 +3712,7 @@ static int ub960_create_subdev(struct ub960_data *priv)static void ub960_destroy_subdev (struct ub960_data *priv) { -ub960_v4l2_notifier_unregister (priv); +v4l2_async_nf_unregister_cleanup (&priv->notifier);v4l2_async_unregister_subdev (&priv->sd);v4l2_subdev_cleanup (&priv->sd);
drivers/media/i2c/max9286.c +1 -2
@@ -781,8 +781,7 @@ static void max9286_v4l2_notifier_unregister(struct max9286_priv *priv)if (!priv->nsources)return ; -v4l2_async_nf_unregister (&priv->notifier); -v4l2_async_nf_cleanup (&priv->notifier); +v4l2_async_nf_unregister_cleanup (&priv->notifier); }static int max9286_s_stream (struct v4l2_subdev *sd,int enable)
drivers/media/i2c/st-mipid02.c +2 -4
@@ -909,8 +909,7 @@ static int mipid02_probe(struct i2c_client *client)return 0 ; unregister_notifier: -v4l2_async_nf_unregister (&bridge->notifier); -v4l2_async_nf_cleanup (&bridge->notifier); +v4l2_async_nf_unregister_cleanup (&bridge->notifier); power_off:mipid02_set_power_off (bridge); entity_cleanup:
@@ -924,8 +923,7 @@ static void mipid02_remove(struct i2c_client *client)struct v4l2_subdev *sd =i2c_get_clientdata (client);struct mipid02_dev *bridge =to_mipid02_dev (sd); -v4l2_async_nf_unregister (&bridge->notifier); -v4l2_async_nf_cleanup (&bridge->notifier); +v4l2_async_nf_unregister_cleanup (&bridge->notifier);v4l2_async_unregister_subdev (&bridge->sd);mipid02_set_power_off (bridge);media_entity_cleanup (&bridge->sd.entity);
drivers/media/i2c/tc358746.c +1 -2
@@ -1607,8 +1607,7 @@ static void tc358746_remove(struct i2c_client *client)v4l2_subdev_cleanup (sd);v4l2_ctrl_handler_free (&tc358746->ctrl_hdl);v4l2_fwnode_endpoint_free (&tc358746->csi_vep); -v4l2_async_nf_unregister (&tc358746->notifier); -v4l2_async_nf_cleanup (&tc358746->notifier); +v4l2_async_nf_unregister_cleanup (&tc358746->notifier);v4l2_async_unregister_subdev (sd);media_entity_cleanup (&sd->entity);
drivers/media/pci/intel/ipu3/ipu3-cio2.c +2 -4
@@ -1770,8 +1770,7 @@ static int cio2_pci_probe(struct pci_dev *pci_dev,return 0 ; fail_clean_notifier: -v4l2_async_nf_unregister (&cio2->notifier); -v4l2_async_nf_cleanup (&cio2->notifier); +v4l2_async_nf_unregister_cleanup (&cio2->notifier);cio2_queues_exit (cio2); fail_v4l2_device_unregister:v4l2_device_unregister (&cio2->v4l2_dev);
@@ -1790,8 +1789,7 @@ static void cio2_pci_remove(struct pci_dev *pci_dev)struct cio2_device *cio2 =pci_get_drvdata (pci_dev);media_device_unregister (&cio2->media_dev); -v4l2_async_nf_unregister (&cio2->notifier); -v4l2_async_nf_cleanup (&cio2->notifier); +v4l2_async_nf_unregister_cleanup (&cio2->notifier);cio2_queues_exit (cio2);cio2_fbpt_exit_dummy (cio2);v4l2_device_unregister (&cio2->v4l2_dev);
drivers/media/pci/intel/ipu6/ipu6-isys.c +1 -7
@@ -767,12 +767,6 @@ static int isys_notifier_init(struct ipu6_isys *isys)return ret; } -static void isys_notifier_cleanup (struct ipu6_isys *isys) -{ -v4l2_async_nf_unregister (&isys->notifier); -v4l2_async_nf_cleanup (&isys->notifier); -} -static int isys_register_devices (struct ipu6_isys *isys) {struct device *dev = &isys->adev->auxdev.dev;
@@ -942,7 +936,7 @@ static void isys_remove(struct auxiliary_device *auxdev) fwmsg, fwmsg->dma_addr, 0);isys_unregister_devices (isys); -isys_notifier_cleanup (isys); +v4l2_async_nf_unregister_cleanup (&isys->notifier);cpu_latency_qos_remove_request (&isys->pm_qos);
drivers/media/pci/intel/ivsc/mei_csi.c +2 -4
@@ -752,8 +752,7 @@ static int mei_csi_probe(struct mei_cl_device *cldev, err_ctrl_handler:v4l2_ctrl_handler_free (&csi->ctrl_handler); -v4l2_async_nf_unregister (&csi->notifier); -v4l2_async_nf_cleanup (&csi->notifier); +v4l2_async_nf_unregister_cleanup (&csi->notifier); err_disable:mei_cldev_disable (cldev);
@@ -768,8 +767,7 @@ static void mei_csi_remove(struct mei_cl_device *cldev) {struct mei_csi *csi =mei_cldev_get_drvdata (cldev); -v4l2_async_nf_unregister (&csi->notifier); -v4l2_async_nf_cleanup (&csi->notifier); +v4l2_async_nf_unregister_cleanup (&csi->notifier);v4l2_ctrl_handler_free (&csi->ctrl_handler);v4l2_async_unregister_subdev (&csi->subdev);v4l2_subdev_cleanup (&csi->subdev);
drivers/media/platform/atmel/atmel-isi.c +1 -2
@@ -1327,8 +1327,7 @@ static void atmel_isi_remove(struct platform_device *pdev) isi->p_fb_descriptors, isi->fb_descriptors_phys);pm_runtime_disable (&pdev->dev); -v4l2_async_nf_unregister (&isi->notifier); -v4l2_async_nf_cleanup (&isi->notifier); +v4l2_async_nf_unregister_cleanup (&isi->notifier);v4l2_device_unregister (&isi->v4l2_dev); }
drivers/media/platform/cadence/cdns-csi2rx.c +2 -4
@@ -722,8 +722,7 @@ static int csi2rx_probe(struct platform_device *pdev) err_free_state:v4l2_subdev_cleanup (&csi2rx->subdev); err_cleanup: -v4l2_async_nf_unregister (&csi2rx->notifier); -v4l2_async_nf_cleanup (&csi2rx->notifier); +v4l2_async_nf_unregister_cleanup (&csi2rx->notifier);media_entity_cleanup (&csi2rx->subdev.entity); err_free_priv:kfree (csi2rx);
@@ -734,8 +733,7 @@ static void csi2rx_remove(struct platform_device *pdev) {struct csi2rx_priv *csi2rx =platform_get_drvdata (pdev); -v4l2_async_nf_unregister (&csi2rx->notifier); -v4l2_async_nf_cleanup (&csi2rx->notifier); +v4l2_async_nf_unregister_cleanup (&csi2rx->notifier);v4l2_async_unregister_subdev (&csi2rx->subdev);v4l2_subdev_cleanup (&csi2rx->subdev);media_entity_cleanup (&csi2rx->subdev.entity);
drivers/media/platform/intel/pxa_camera.c +1 -2
@@ -2433,8 +2433,7 @@ static void pxa_camera_remove(struct platform_device *pdev)dma_release_channel (pcdev->dma_chans[1 ]);dma_release_channel (pcdev->dma_chans[2 ]); -v4l2_async_nf_unregister (&pcdev->notifier); -v4l2_async_nf_cleanup (&pcdev->notifier); +v4l2_async_nf_unregister_cleanup (&pcdev->notifier);v4l2_device_unregister (&pcdev->v4l2_dev);
drivers/media/platform/marvell/mcam-core.c +2 -4
@@ -1907,8 +1907,7 @@ int mccic_register(struct mcam_camera *cam)return 0 ; out: -v4l2_async_nf_unregister (&cam->notifier); -v4l2_async_nf_cleanup (&cam->notifier); +v4l2_async_nf_unregister_cleanup (&cam->notifier);return ret; }EXPORT_SYMBOL_GPL (mccic_register);
@@ -1928,8 +1927,7 @@ void mccic_shutdown(struct mcam_camera *cam)if (cam->buffer_mode == B_vmalloc)mcam_free_dma_bufs (cam);v4l2_ctrl_handler_free (&cam->ctrl_handler); -v4l2_async_nf_unregister (&cam->notifier); -v4l2_async_nf_cleanup (&cam->notifier); +v4l2_async_nf_unregister_cleanup (&cam->notifier); }EXPORT_SYMBOL_GPL (mccic_shutdown);
drivers/media/platform/microchip/microchip-csi2dc.c +1 -2
@@ -750,8 +750,7 @@ static void csi2dc_remove(struct platform_device *pdev)pm_runtime_disable (&pdev->dev);v4l2_async_unregister_subdev (&csi2dc->csi2dc_sd); -v4l2_async_nf_unregister (&csi2dc->notifier); -v4l2_async_nf_cleanup (&csi2dc->notifier); +v4l2_async_nf_unregister_cleanup (&csi2dc->notifier);media_entity_cleanup (&csi2dc->csi2dc_sd.entity); }
drivers/media/platform/microchip/microchip-isc-base.c +2 -4
@@ -1856,10 +1856,8 @@ void microchip_isc_subdev_cleanup(struct isc_device *isc) {struct isc_subdev_entity *subdev_entity; -list_for_each_entry (subdev_entity, &isc->subdev_entities, list) { -v4l2_async_nf_unregister (&subdev_entity->notifier); -v4l2_async_nf_cleanup (&subdev_entity->notifier); - } +list_for_each_entry (subdev_entity, &isc->subdev_entities, list) +v4l2_async_nf_unregister_cleanup (&subdev_entity->notifier);INIT_LIST_HEAD (&isc->subdev_entities); }
drivers/media/platform/nxp/imx-mipi-csis.c +2 -4
@@ -1513,8 +1513,7 @@ static int mipi_csis_probe(struct platform_device *pdev) err_cleanup:v4l2_subdev_cleanup (&csis->sd);media_entity_cleanup (&csis->sd.entity); -v4l2_async_nf_unregister (&csis->notifier); -v4l2_async_nf_cleanup (&csis->notifier); +v4l2_async_nf_unregister_cleanup (&csis->notifier);v4l2_async_unregister_subdev (&csis->sd);return ret;
@@ -1526,8 +1525,7 @@ static void mipi_csis_remove(struct platform_device *pdev)struct mipi_csis_device *csis =sd_to_mipi_csis_device (sd);mipi_csis_debugfs_exit (csis); -v4l2_async_nf_unregister (&csis->notifier); -v4l2_async_nf_cleanup (&csis->notifier); +v4l2_async_nf_unregister_cleanup (&csis->notifier);v4l2_async_unregister_subdev (&csis->sd);if (!pm_runtime_enabled (&pdev->dev))
drivers/media/platform/nxp/imx7-media-csi.c +1 -2
@@ -2266,8 +2266,7 @@ static void imx7_csi_remove(struct platform_device *pdev)imx7_csi_media_cleanup (csi); -v4l2_async_nf_unregister (&csi->notifier); -v4l2_async_nf_cleanup (&csi->notifier); +v4l2_async_nf_unregister_cleanup (&csi->notifier);v4l2_async_unregister_subdev (&csi->sd); }
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c +1 -2
@@ -223,8 +223,7 @@ static void mxc_isi_v4l2_cleanup(struct mxc_isi_dev *isi) {unsigned int i; -v4l2_async_nf_unregister (&isi->notifier); -v4l2_async_nf_cleanup (&isi->notifier); +v4l2_async_nf_unregister_cleanup (&isi->notifier);v4l2_device_unregister (&isi->v4l2_dev);media_device_unregister (&isi->media_dev);
drivers/media/platform/nxp/imx8mq-mipi-csi2.c +2 -4
@@ -917,8 +917,7 @@ static int imx8mq_mipi_csi_probe(struct platform_device *pdev)media_entity_cleanup (&state->sd.entity);v4l2_subdev_cleanup (&state->sd); -v4l2_async_nf_unregister (&state->notifier); -v4l2_async_nf_cleanup (&state->notifier); +v4l2_async_nf_unregister_cleanup (&state->notifier);v4l2_async_unregister_subdev (&state->sd); icc:imx8mq_mipi_csi_release_icc (pdev);
@@ -933,8 +932,7 @@ static void imx8mq_mipi_csi_remove(struct platform_device *pdev)struct v4l2_subdev *sd =platform_get_drvdata (pdev);struct csi_state *state =mipi_sd_to_csi2_state (sd); -v4l2_async_nf_unregister (&state->notifier); -v4l2_async_nf_cleanup (&state->notifier); +v4l2_async_nf_unregister_cleanup (&state->notifier);v4l2_async_unregister_subdev (&state->sd);pm_runtime_disable (&pdev->dev);
drivers/media/platform/qcom/camss/camss.c +1 -2
@@ -2052,8 +2052,7 @@ static void camss_remove(struct platform_device *pdev) {struct camss *camss =platform_get_drvdata (pdev); -v4l2_async_nf_unregister (&camss->notifier); -v4l2_async_nf_cleanup (&camss->notifier); +v4l2_async_nf_unregister_cleanup (&camss->notifier);camss_unregister_entities (camss);if (atomic_read (&camss->ref_count) ==0 )
drivers/media/platform/renesas/rcar-csi2.c +2 -4
@@ -1921,8 +1921,7 @@ static int rcsi2_probe(struct platform_device *pdev)return 0 ; error_async: -v4l2_async_nf_unregister (&priv->notifier); -v4l2_async_nf_cleanup (&priv->notifier); +v4l2_async_nf_unregister_cleanup (&priv->notifier); error_mutex:mutex_destroy (&priv->lock);
@@ -1933,8 +1932,7 @@ static void rcsi2_remove(struct platform_device *pdev) {struct rcar_csi2 *priv =platform_get_drvdata (pdev); -v4l2_async_nf_unregister (&priv->notifier); -v4l2_async_nf_cleanup (&priv->notifier); +v4l2_async_nf_unregister_cleanup (&priv->notifier);v4l2_async_unregister_subdev (&priv->subdev);pm_runtime_disable (&pdev->dev);
drivers/media/platform/renesas/rcar-isp.c +2 -4
@@ -491,8 +491,7 @@ static int risp_probe(struct platform_device *pdev)return 0 ; error_notifier: -v4l2_async_nf_unregister (&isp->notifier); -v4l2_async_nf_cleanup (&isp->notifier); +v4l2_async_nf_unregister_cleanup (&isp->notifier); error_pm:pm_runtime_disable (&pdev->dev); error_mutex:
@@ -505,8 +504,7 @@ static void risp_remove(struct platform_device *pdev) {struct rcar_isp *isp =platform_get_drvdata (pdev); -v4l2_async_nf_unregister (&isp->notifier); -v4l2_async_nf_cleanup (&isp->notifier); +v4l2_async_nf_unregister_cleanup (&isp->notifier);v4l2_async_unregister_subdev (&isp->subdev);
drivers/media/platform/renesas/rcar-vin/rcar-core.c +3 -6
@@ -345,10 +345,8 @@ static int rvin_group_parse_of(struct rvin_dev *vin, unsigned int port,static void rvin_group_notifier_cleanup (struct rvin_dev *vin) { -if (&vin->v4l2_dev == vin->group->notifier.v4l2_dev) { -v4l2_async_nf_unregister (&vin->group->notifier); -v4l2_async_nf_cleanup (&vin->group->notifier); - } +if (&vin->v4l2_dev == vin->group->notifier.v4l2_dev) +v4l2_async_nf_unregister_cleanup (&vin->group->notifier); } static int rvin_group_notifier_init(struct rvin_dev *vin, unsigned int port,
@@ -704,8 +702,7 @@ static int rvin_parallel_parse_of(struct rvin_dev *vin)static void rvin_parallel_cleanup (struct rvin_dev *vin) { -v4l2_async_nf_unregister (&vin->notifier); -v4l2_async_nf_cleanup (&vin->notifier); +v4l2_async_nf_unregister_cleanup (&vin->notifier); }static int rvin_parallel_init (struct rvin_dev *vin)
drivers/media/platform/renesas/rcar_drif.c +1 -2
@@ -1361,8 +1361,7 @@ static int rcar_drif_sdr_probe(struct rcar_drif_sdr *sdr)/* V4L2 SDR device remove */ static void rcar_drif_sdr_remove (struct rcar_drif_sdr *sdr) { -v4l2_async_nf_unregister (&sdr->notifier); -v4l2_async_nf_cleanup (&sdr->notifier); +v4l2_async_nf_unregister_cleanup (&sdr->notifier);v4l2_device_unregister (&sdr->v4l2_dev); }
drivers/media/platform/renesas/renesas-ceu.c +1 -3
@@ -1701,9 +1701,7 @@ static void ceu_remove(struct platform_device *pdev)pm_runtime_disable (ceudev->dev); -v4l2_async_nf_unregister (&ceudev->notifier); - -v4l2_async_nf_cleanup (&ceudev->notifier); +v4l2_async_nf_unregister_cleanup (&ceudev->notifier);v4l2_device_unregister (&ceudev->v4l2_dev);
drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c +1 -2
@@ -303,8 +303,7 @@ static void rzg2l_cru_remove(struct platform_device *pdev)pm_runtime_disable (&pdev->dev); -v4l2_async_nf_unregister (&cru->notifier); -v4l2_async_nf_cleanup (&cru->notifier); +v4l2_async_nf_unregister_cleanup (&cru->notifier);rzg2l_cru_video_unregister (cru);media_device_cleanup (&cru->mdev);
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +2 -4
@@ -819,8 +819,7 @@ static int rzg2l_csi2_probe(struct platform_device *pdev) error_subdev:v4l2_subdev_cleanup (&csi2->subdev); error_async: -v4l2_async_nf_unregister (&csi2->notifier); -v4l2_async_nf_cleanup (&csi2->notifier); +v4l2_async_nf_unregister_cleanup (&csi2->notifier);media_entity_cleanup (&csi2->subdev.entity); error_pm:pm_runtime_disable (&pdev->dev);
@@ -832,8 +831,7 @@ static void rzg2l_csi2_remove(struct platform_device *pdev) {struct rzg2l_csi2 *csi2 =platform_get_drvdata (pdev); -v4l2_async_nf_unregister (&csi2->notifier); -v4l2_async_nf_cleanup (&csi2->notifier); +v4l2_async_nf_unregister_cleanup (&csi2->notifier);v4l2_async_unregister_subdev (&csi2->subdev);v4l2_subdev_cleanup (&csi2->subdev);media_entity_cleanup (&csi2->subdev.entity);
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +1 -2
@@ -720,8 +720,7 @@ static void rkisp1_remove(struct platform_device *pdev) {struct rkisp1_device *rkisp1 =platform_get_drvdata (pdev); -v4l2_async_nf_unregister (&rkisp1->notifier); -v4l2_async_nf_cleanup (&rkisp1->notifier); +v4l2_async_nf_unregister_cleanup (&rkisp1->notifier);rkisp1_entities_unregister (rkisp1);if (rkisp1_has_feature (rkisp1,MIPI_CSI2 ))
drivers/media/platform/samsung/exynos4-is/media-dev.c +1 -2
@@ -1538,8 +1538,7 @@ static void fimc_md_remove(struct platform_device *pdev)return ;fimc_md_unregister_clk_provider (fmd); -v4l2_async_nf_unregister (&fmd->subdev_notifier); -v4l2_async_nf_cleanup (&fmd->subdev_notifier); +v4l2_async_nf_unregister_cleanup (&fmd->subdev_notifier);v4l2_device_unregister (&fmd->v4l2_dev);device_remove_file (&pdev->dev, &dev_attr_subdev_conf_mode);
drivers/media/platform/st/stm32/stm32-dcmi.c +1 -2
@@ -2089,8 +2089,7 @@ static void dcmi_remove(struct platform_device *pdev)pm_runtime_disable (&pdev->dev); -v4l2_async_nf_unregister (&dcmi->notifier); -v4l2_async_nf_cleanup (&dcmi->notifier); +v4l2_async_nf_unregister_cleanup (&dcmi->notifier);media_entity_cleanup (&dcmi->vdev->entity);v4l2_device_unregister (&dcmi->v4l2_dev);media_device_cleanup (&dcmi->mdev);
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c +1 -2
@@ -524,8 +524,7 @@ static void dcmipp_remove(struct platform_device *pdev)pm_runtime_disable (&pdev->dev); -v4l2_async_nf_unregister (&dcmipp->notifier); -v4l2_async_nf_cleanup (&dcmipp->notifier); +v4l2_async_nf_unregister_cleanup (&dcmipp->notifier);for (i =0 ; i < dcmipp->pipe_cfg->num_ents; i++) dcmipp->pipe_cfg->ents[i].release (dcmipp->entity[i]);
drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c +1 -2
@@ -265,8 +265,7 @@ static void sun4i_csi_remove(struct platform_device *pdev)struct sun4i_csi *csi =platform_get_drvdata (pdev);pm_runtime_disable (&pdev->dev); -v4l2_async_nf_unregister (&csi->notifier); -v4l2_async_nf_cleanup (&csi->notifier); +v4l2_async_nf_unregister_cleanup (&csi->notifier);vb2_video_unregister_device (&csi->vdev);media_device_unregister (&csi->mdev);sun4i_csi_dma_unregister (csi);
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.c +1 -2
@@ -863,8 +863,7 @@ void sun6i_csi_bridge_cleanup(struct sun6i_csi_device *csi_dev)struct v4l2_subdev *subdev = &csi_dev->bridge.subdev;struct v4l2_async_notifier *notifier = &csi_dev->bridge.notifier; -v4l2_async_nf_unregister (notifier); -v4l2_async_nf_cleanup (notifier); +v4l2_async_nf_unregister_cleanup (notifier);v4l2_device_unregister_subdev (subdev);
drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c +1 -2
@@ -577,8 +577,7 @@ sun6i_mipi_csi2_bridge_cleanup(struct sun6i_mipi_csi2_device *csi2_dev)struct v4l2_async_notifier *notifier = &csi2_dev->bridge.notifier;v4l2_async_unregister_subdev (subdev); -v4l2_async_nf_unregister (notifier); -v4l2_async_nf_cleanup (notifier); +v4l2_async_nf_unregister_cleanup (notifier);media_entity_cleanup (&subdev->entity); }
drivers/media/platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c +1 -2
@@ -615,8 +615,7 @@ sun8i_a83t_mipi_csi2_bridge_cleanup(struct sun8i_a83t_mipi_csi2_device *csi2_devstruct v4l2_async_notifier *notifier = &csi2_dev->bridge.notifier;v4l2_async_unregister_subdev (subdev); -v4l2_async_nf_unregister (notifier); -v4l2_async_nf_cleanup (notifier); +v4l2_async_nf_unregister_cleanup (notifier);media_entity_cleanup (&subdev->entity); }
drivers/media/platform/ti/am437x/am437x-vpfe.c +1 -2
@@ -2485,8 +2485,7 @@ static void vpfe_remove(struct platform_device *pdev)pm_runtime_disable (&pdev->dev); -v4l2_async_nf_unregister (&vpfe->notifier); -v4l2_async_nf_cleanup (&vpfe->notifier); +v4l2_async_nf_unregister_cleanup (&vpfe->notifier);video_unregister_device (&vpfe->video_dev);v4l2_device_unregister (&vpfe->v4l2_dev); }
drivers/media/platform/ti/cal/cal.c +1 -7
@@ -902,12 +902,6 @@ static int cal_async_notifier_register(struct cal_dev *cal)return ret; } -static void cal_async_notifier_unregister (struct cal_dev *cal) -{ -v4l2_async_nf_unregister (&cal->notifier); -v4l2_async_nf_cleanup (&cal->notifier); -} -/* ------------------------------------------------------------------ * Media and V4L2 device handling * ------------------------------------------------------------------
@@ -952,7 +946,7 @@ static void cal_media_unregister(struct cal_dev *cal)for (i =0 ; i < cal->num_contexts; i++)cal_ctx_v4l2_unregister (cal->ctx[i]); -cal_async_notifier_unregister (cal); +v4l2_async_nf_unregister_cleanup (&cal->notifier);media_device_unregister (&cal->mdev); }
drivers/media/platform/ti/davinci/vpif_capture.c +1 -2
@@ -1720,8 +1720,7 @@ static void vpif_remove(struct platform_device *device)struct channel_obj *ch;int i; -v4l2_async_nf_unregister (&vpif_obj.notifier); -v4l2_async_nf_cleanup (&vpif_obj.notifier); +v4l2_async_nf_unregister_cleanup (&vpif_obj.notifier);v4l2_device_unregister (&vpif_obj.v4l2_dev);kfree (vpif_obj.sd);
drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +2 -8
@@ -1074,12 +1074,6 @@ static void ti_csi2rx_cleanup_v4l2(struct ti_csi2rx_dev *csi)media_device_cleanup (&csi->mdev); } -static void ti_csi2rx_cleanup_subdev (struct ti_csi2rx_dev *csi) -{ -v4l2_async_nf_unregister (&csi->notifier); -v4l2_async_nf_cleanup (&csi->notifier); -} -static void ti_csi2rx_cleanup_vb2q (struct ti_csi2rx_dev *csi) {vb2_queue_release (&csi->vidq);
@@ -1129,7 +1123,7 @@ static int ti_csi2rx_probe(struct platform_device *pdev)return 0 ; err_subdev: -ti_csi2rx_cleanup_subdev (csi); +v4l2_async_nf_unregister_cleanup (&csi->notifier); err_vb2q:ti_csi2rx_cleanup_vb2q (csi); err_v4l2:
@@ -1148,7 +1142,7 @@ static void ti_csi2rx_remove(struct platform_device *pdev)video_unregister_device (&csi->vdev);ti_csi2rx_cleanup_vb2q (csi); -ti_csi2rx_cleanup_subdev (csi); +v4l2_async_nf_unregister_cleanup (&csi->notifier);ti_csi2rx_cleanup_v4l2 (csi);ti_csi2rx_cleanup_dma (csi);
drivers/media/platform/ti/omap3isp/isp.c +1 -2
@@ -2001,8 +2001,7 @@ static void isp_remove(struct platform_device *pdev) {struct isp_device *isp =platform_get_drvdata (pdev); -v4l2_async_nf_unregister (&isp->notifier); -v4l2_async_nf_cleanup (&isp->notifier); +v4l2_async_nf_unregister_cleanup (&isp->notifier);isp_unregister_entities (isp);isp_cleanup_modules (isp);isp_xclk_cleanup (isp);
drivers/media/platform/video-mux.c +1 -2
@@ -471,8 +471,7 @@ static void video_mux_remove(struct platform_device *pdev)struct video_mux *vmux =platform_get_drvdata (pdev);struct v4l2_subdev *sd = &vmux->subdev; -v4l2_async_nf_unregister (&vmux->notifier); -v4l2_async_nf_cleanup (&vmux->notifier); +v4l2_async_nf_unregister_cleanup (&vmux->notifier);v4l2_async_unregister_subdev (sd);v4l2_subdev_cleanup (sd);media_entity_cleanup (&sd->entity);
drivers/media/platform/xilinx/xilinx-vipp.c +1 -2
@@ -481,8 +481,7 @@ static void xvip_graph_cleanup(struct xvip_composite_device *xdev)struct xvip_dma *dmap;struct xvip_dma *dma; -v4l2_async_nf_unregister (&xdev->notifier); -v4l2_async_nf_cleanup (&xdev->notifier); +v4l2_async_nf_unregister_cleanup (&xdev->notifier);list_for_each_entry_safe (dma, dmap, &xdev->dmas, list) {xvip_dma_cleanup (dma);
drivers/staging/media/deprecated/atmel/atmel-isc-base.c +2 -4
@@ -1944,10 +1944,8 @@ void atmel_isc_subdev_cleanup(struct isc_device *isc) {struct isc_subdev_entity *subdev_entity; -list_for_each_entry (subdev_entity, &isc->subdev_entities, list) { -v4l2_async_nf_unregister (&subdev_entity->notifier); -v4l2_async_nf_cleanup (&subdev_entity->notifier); - } +list_for_each_entry (subdev_entity, &isc->subdev_entities, list) +v4l2_async_nf_unregister_cleanup (&subdev_entity->notifier);INIT_LIST_HEAD (&isc->subdev_entities); }
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_proc.c +1 -2
@@ -573,8 +573,7 @@ void sun6i_isp_proc_cleanup(struct sun6i_isp_device *isp_dev)struct v4l2_async_notifier *notifier = &isp_dev->proc.notifier;struct v4l2_subdev *subdev = &isp_dev->proc.subdev; -v4l2_async_nf_unregister (notifier); -v4l2_async_nf_cleanup (notifier); +v4l2_async_nf_unregister_cleanup (notifier);v4l2_device_unregister_subdev (subdev);media_entity_cleanup (&subdev->entity);
drivers/staging/media/tegra-video/vi.c +1 -2
@@ -1802,8 +1802,7 @@ static void tegra_vi_graph_cleanup(struct tegra_vi *vi)list_for_each_entry (chan, &vi->vi_chans, list) {vb2_video_unregister_device (&chan->video); -v4l2_async_nf_unregister (&chan->notifier); -v4l2_async_nf_cleanup (&chan->notifier); +v4l2_async_nf_unregister_cleanup (&chan->notifier); } }
Signature · 1 line
2.44.0
Laurent Pinchart
maintainerHi Julien,
Quoted 5 lines · Julien Massot
Many drivers has
v4l2_async_nf_unregister(¬ifier);
v4l2_async_nf_cleanup(¬ifier);Introduce a helper function to call both functions in one line.
Does this really go in the right direction ? For other objects (video devices, media devices, ...), the unregistration should be done at .remove() time, and the cleanup at .release() time (the operation called when the last reference to the object is released). This is needed to ensure proper lifetime management of the objects, and avoid a use-after-free for objects that can be reached from userspace.
It could be argued that the notifier isn't exposed to userspace, but can we guarantee that no driver will have a need to access the notifier in a code path triggered by a userspace operation ? I think it would be safer to adopt the same split for the nofifier unregistration and cleanup. In my opinion using the same rule across different APIs also make it easier for driver authors and for reviewers to get it right.
As shown by your series, lots of drivers call v4l2_async_nf_cleanup() and .remove() time instead of .release(). That's because most drivers get lifetime management wrong and don't even implement .release(). That's something Sakari is addressing with ongoing work. This patch series seems to go in the opposite direction.
Quoted 55 lines
---
Julien Massot (2):
media: v4l: async: Addv4l2_async_nf_unregister_cleanup
media: convert all drivers to usev4l2_async_nf_unregister_cleanupdrivers/media/i2c/ds90ub913.c | 10 ++-------- drivers/media/i2c/ds90ub953.c | 10 ++-------- drivers/media/i2c/ds90ub960.c | 10 ++-------- drivers/media/i2c/max9286.c | 3 +-- drivers/media/i2c/st-mipid02.c | 6 ++---- drivers/media/i2c/tc358746.c | 3 +-- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 6 ++---- drivers/media/pci/intel/ipu6/ipu6-isys.c | 8 +------- drivers/media/pci/intel/ivsc/mei_csi.c | 6 ++---- drivers/media/platform/atmel/atmel-isi.c | 3 +-- drivers/media/platform/cadence/cdns-csi2rx.c | 6 ++---- drivers/media/platform/intel/pxa_camera.c | 3 +-- drivers/media/platform/marvell/mcam-core.c | 6 ++---- drivers/media/platform/microchip/microchip-csi2dc.c | 3 +-- drivers/media/platform/microchip/microchip-isc-base.c | 6 ++---- drivers/media/platform/nxp/imx-mipi-csis.c | 6 ++---- drivers/media/platform/nxp/imx7-media-csi.c | 3 +-- drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c | 3 +-- drivers/media/platform/nxp/imx8mq-mipi-csi2.c | 6 ++---- drivers/media/platform/qcom/camss/camss.c | 3 +-- drivers/media/platform/renesas/rcar-csi2.c | 6 ++---- drivers/media/platform/renesas/rcar-isp.c | 6 ++---- drivers/media/platform/renesas/rcar-vin/rcar-core.c | 9 +++------ drivers/media/platform/renesas/rcar_drif.c | 3 +-- drivers/media/platform/renesas/renesas-ceu.c | 4 +--- drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c | 3 +-- drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c | 6 ++---- drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 3 +-- drivers/media/platform/samsung/exynos4-is/media-dev.c | 3 +-- drivers/media/platform/st/stm32/stm32-dcmi.c | 3 +-- .../media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c | 3 +-- drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c | 3 +-- .../media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.c | 3 +-- .../platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c | 3 +-- .../sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c | 3 +-- drivers/media/platform/ti/am437x/am437x-vpfe.c | 3 +-- drivers/media/platform/ti/cal/cal.c | 8 +------- drivers/media/platform/ti/davinci/vpif_capture.c | 3 +-- drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 10 ++-------- drivers/media/platform/ti/omap3isp/isp.c | 3 +-- drivers/media/platform/video-mux.c | 3 +-- drivers/media/platform/xilinx/xilinx-vipp.c | 3 +-- drivers/staging/media/deprecated/atmel/atmel-isc-base.c | 6 ++---- drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_proc.c | 3 +-- drivers/staging/media/tegra-video/vi.c | 3 +-- include/media/v4l2-async.h | 17 +++++++++++++++++ 46 files changed, 80 insertions(+), 153 deletions(-)---
base-commit:843a9f4a7a85988f2f3af98adf21797c2fd05ab1
change-id: 20240502-master-5deee133b4f5
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerHi Laurent,
Quoted 23 lines · Laurent Pinchart
Hi Julien,
Quoted 5 lines · Julien Massot
Many drivers has
v4l2_async_nf_unregister(¬ifier);
v4l2_async_nf_cleanup(¬ifier);Introduce a helper function to call both functions in one line.
Does this really go in the right direction ? For other objects (video devices, media devices, ...), the unregistration should be done at .remove() time, and the cleanup at .release() time (the operation called when the last reference to the object is released). This is needed to ensure proper lifetime management of the objects, and avoid a use-after-free for objects that can be reached from userspace.
It could be argued that the notifier isn't exposed to userspace, but can we guarantee that no driver will have a need to access the notifier in a code path triggered by a userspace operation ? I think it would be safer to adopt the same split for the nofifier unregistration and cleanup. In my opinion using the same rule across different APIs also make it easier for driver authors and for reviewers to get it right.
Quoted 5 lines
As shown by your series, lots of drivers call
v4l2_async_nf_cleanup()and .remove() time instead of .release(). That's because most drivers get lifetime management wrong and don't even implement .release(). That's something Sakari is addressing with ongoing work. This patch series seems to go in the opposite direction.
This still avoids the driver authors feeling they need to implement wrapper functions for v4l2_async_nf_{unregister,cleanup}. I'd be in favour merging this.
I don't see this getting in the way of adding use counts as the code will need to be changed in any case.
Signature · 3 lines
Regards, Sakari Ailus
Laurent Pinchart
maintainerQuoted 28 lines · Sakari Ailus
Quoted 21 lines · Laurent Pinchart
Quoted 5 lines · Julien Massot
Many drivers has
v4l2_async_nf_unregister(¬ifier);
v4l2_async_nf_cleanup(¬ifier);Introduce a helper function to call both functions in one line.
Does this really go in the right direction ? For other objects (video devices, media devices, ...), the unregistration should be done at .remove() time, and the cleanup at .release() time (the operation called when the last reference to the object is released). This is needed to ensure proper lifetime management of the objects, and avoid a use-after-free for objects that can be reached from userspace.
It could be argued that the notifier isn't exposed to userspace, but can we guarantee that no driver will have a need to access the notifier in a code path triggered by a userspace operation ? I think it would be safer to adopt the same split for the nofifier unregistration and cleanup. In my opinion using the same rule across different APIs also make it easier for driver authors and for reviewers to get it right.
Quoted 5 lines
As shown by your series, lots of drivers call
v4l2_async_nf_cleanup()and .remove() time instead of .release(). That's because most drivers get lifetime management wrong and don't even implement .release(). That's something Sakari is addressing with ongoing work. This patch series seems to go in the opposite direction.
Quoted 6 lines
This still avoids the driver authors feeling they need to implement wrapper functions for v4l2_async_nf_{unregister,cleanup}. I'd be in favour merging this.
I don't see this getting in the way of adding use counts as the code will need to be changed in any case.
Fixing the lifetime issues would essentially revert 2/2 and move the v4l2_async_nf_cleanup() call to .remove(). I don't think providing a helper that forces the cleanup at .remove() time is a good idea, it gives a false sense of doing things right to drivers. This is the same reason why devm_kzalloc() is so harmful, it gave the wrong message, and created (or participated in) all those lifetime issues.
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerHi Laurent,
Quoted 36 lines · Laurent Pinchart
Quoted 28 lines · Sakari Ailus
Quoted 21 lines · Laurent Pinchart
Quoted 5 lines · Julien Massot
Many drivers has
v4l2_async_nf_unregister(¬ifier);
v4l2_async_nf_cleanup(¬ifier);Introduce a helper function to call both functions in one line.
Does this really go in the right direction ? For other objects (video devices, media devices, ...), the unregistration should be done at .remove() time, and the cleanup at .release() time (the operation called when the last reference to the object is released). This is needed to ensure proper lifetime management of the objects, and avoid a use-after-free for objects that can be reached from userspace.
It could be argued that the notifier isn't exposed to userspace, but can we guarantee that no driver will have a need to access the notifier in a code path triggered by a userspace operation ? I think it would be safer to adopt the same split for the nofifier unregistration and cleanup. In my opinion using the same rule across different APIs also make it easier for driver authors and for reviewers to get it right.
Quoted 5 lines
As shown by your series, lots of drivers call
v4l2_async_nf_cleanup()and .remove() time instead of .release(). That's because most drivers get lifetime management wrong and don't even implement .release(). That's something Sakari is addressing with ongoing work. This patch series seems to go in the opposite direction.Quoted 6 lines
This still avoids the driver authors feeling they need to implement wrapper functions for v4l2_async_nf_{unregister,cleanup}. I'd be in favour merging this.
I don't see this getting in the way of adding use counts as the code will need to be changed in any case.
Quoted 6 lines
Fixing the lifetime issues would essentially revert 2/2 and move the
v4l2_async_nf_cleanup()call to .remove(). I don't think providing a helper that forces the cleanup at .remove() time is a good idea, it gives a false sense of doing things right to drivers. This is the same reason whydevm_kzalloc()is so harmful, it gave the wrong message, and created (or participated in) all those lifetime issues.
I still prefer having devm_*alloc() functions than having the drivers open coding the same -- with the same result. The frameworks won't enable doing this right at the moment and I don't think drivers (or us!) should be penalised for that. The driver authors will only change what they do, with these patches or without, when told so. But we don't really have an alternative today.
A similar situation exists with clk_unprepare() and clk_disable().
Signature · 3 lines
Kind regards, Sakari Ailus
Laurent Pinchart
maintainerQuoted 44 lines · Sakari Ailus
Quoted 36 lines · Laurent Pinchart
Quoted 28 lines · Sakari Ailus
Quoted 21 lines · Laurent Pinchart
Quoted 5 lines · Julien Massot
Many drivers has
v4l2_async_nf_unregister(¬ifier);
v4l2_async_nf_cleanup(¬ifier);Introduce a helper function to call both functions in one line.
Does this really go in the right direction ? For other objects (video devices, media devices, ...), the unregistration should be done at .remove() time, and the cleanup at .release() time (the operation called when the last reference to the object is released). This is needed to ensure proper lifetime management of the objects, and avoid a use-after-free for objects that can be reached from userspace.
It could be argued that the notifier isn't exposed to userspace, but can we guarantee that no driver will have a need to access the notifier in a code path triggered by a userspace operation ? I think it would be safer to adopt the same split for the nofifier unregistration and cleanup. In my opinion using the same rule across different APIs also make it easier for driver authors and for reviewers to get it right.
Quoted 5 lines
As shown by your series, lots of drivers call
v4l2_async_nf_cleanup()and .remove() time instead of .release(). That's because most drivers get lifetime management wrong and don't even implement .release(). That's something Sakari is addressing with ongoing work. This patch series seems to go in the opposite direction.Quoted 6 lines
This still avoids the driver authors feeling they need to implement wrapper functions for v4l2_async_nf_{unregister,cleanup}. I'd be in favour merging this.
I don't see this getting in the way of adding use counts as the code will need to be changed in any case.
Quoted 6 lines
Fixing the lifetime issues would essentially revert 2/2 and move the
v4l2_async_nf_cleanup()call to .remove(). I don't think providing a helper that forces the cleanup at .remove() time is a good idea, it gives a false sense of doing things right to drivers. This is the same reason whydevm_kzalloc()is so harmful, it gave the wrong message, and created (or participated in) all those lifetime issues.
Quoted 4 lines
I still prefer having devm_*alloc() functions than having the drivers open coding the same -- with the same result. The frameworks won't enable doing this right at the moment and I don't think drivers (or us!) should be penalised for that.
I don't really see where the penalty is. What's the urgency to switch from calling v4l2_async_nf_unregister() and v4l2_async_nf_cleanup() to a helper that we know goes in the wrong direction ?
Quoted 3 lines
The driver authors will only change what they do, with these patches or without, when told so. But we don't really have an alternative today.
There's already a .release() callback that can be used, and some drivers use it.
Quoted 1 line
A similar situation exists with
clk_unprepare()andclk_disable().
Signature · 3 lines
Regards, Laurent Pinchart