[PATCH 2/6] media: staging: media: imx6-mipi-csi2: use devm_add_action_or_reset() to simplify code

Frank Li posted 6 patches 3 months ago
There is a newer version of this series
[PATCH 2/6] media: staging: media: imx6-mipi-csi2: use devm_add_action_or_reset() to simplify code
Posted by Frank Li 3 months ago
Use devm_add_action_or_reset() to simplify the code. No functional change.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/staging/media/imx/imx6-mipi-csi2.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c
index 42256441b881d9f132ad7ff899d6f1e35643b4ac..eba9a650030f5e380aa900b94728ad375171c6a5 100644
--- a/drivers/staging/media/imx/imx6-mipi-csi2.c
+++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
@@ -716,6 +716,14 @@ static int csi2_async_register(struct csi2_dev *csi2)
 	return ret;
 }
 
+static void csi2_nf_cleanup(void *data)
+{
+	struct csi2_dev *csi2 = data;
+
+	v4l2_async_nf_unregister(&csi2->notifier);
+	v4l2_async_nf_cleanup(&csi2->notifier);
+}
+
 static int csi2_probe(struct platform_device *pdev)
 {
 	struct csi2_dev *csi2;
@@ -749,6 +757,10 @@ static int csi2_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	ret = devm_add_action_or_reset(&pdev->dev, csi2_nf_cleanup, csi2);
+	if (ret)
+		return ret;
+
 	csi2->pllref_clk = devm_clk_get(&pdev->dev, "ref");
 	if (IS_ERR(csi2->pllref_clk)) {
 		v4l2_err(&csi2->sd, "failed to get pll reference clock\n");
@@ -800,8 +812,6 @@ static int csi2_probe(struct platform_device *pdev)
 	return 0;
 
 clean_notifier:
-	v4l2_async_nf_unregister(&csi2->notifier);
-	v4l2_async_nf_cleanup(&csi2->notifier);
 	clk_disable_unprepare(csi2->dphy_clk);
 pllref_off:
 	clk_disable_unprepare(csi2->pllref_clk);
@@ -815,8 +825,6 @@ static void csi2_remove(struct platform_device *pdev)
 	struct v4l2_subdev *sd = platform_get_drvdata(pdev);
 	struct csi2_dev *csi2 = sd_to_dev(sd);
 
-	v4l2_async_nf_unregister(&csi2->notifier);
-	v4l2_async_nf_cleanup(&csi2->notifier);
 	v4l2_async_unregister_subdev(sd);
 	clk_disable_unprepare(csi2->dphy_clk);
 	clk_disable_unprepare(csi2->pllref_clk);

-- 
2.34.1
Re: [PATCH 2/6] media: staging: media: imx6-mipi-csi2: use devm_add_action_or_reset() to simplify code
Posted by Philipp Zabel 3 months ago
On Fr, 2025-11-07 at 15:44 -0500, Frank Li wrote:
> Use devm_add_action_or_reset() to simplify the code. No functional change.
> 
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
>  drivers/staging/media/imx/imx6-mipi-csi2.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c
> index 42256441b881d9f132ad7ff899d6f1e35643b4ac..eba9a650030f5e380aa900b94728ad375171c6a5 100644
> --- a/drivers/staging/media/imx/imx6-mipi-csi2.c
> +++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
> @@ -716,6 +716,14 @@ static int csi2_async_register(struct csi2_dev *csi2)
>  	return ret;
>  }
>  
> +static void csi2_nf_cleanup(void *data)
> +{
> +	struct csi2_dev *csi2 = data;
> +
> +	v4l2_async_nf_unregister(&csi2->notifier);
> +	v4l2_async_nf_cleanup(&csi2->notifier);
> +}
> +
>  static int csi2_probe(struct platform_device *pdev)
>  {
>  	struct csi2_dev *csi2;
> @@ -749,6 +757,10 @@ static int csi2_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> +	ret = devm_add_action_or_reset(&pdev->dev, csi2_nf_cleanup, csi2);
> +	if (ret)
> +		return ret;
> +
>  	csi2->pllref_clk = devm_clk_get(&pdev->dev, "ref");
>  	if (IS_ERR(csi2->pllref_clk)) {
>  		v4l2_err(&csi2->sd, "failed to get pll reference clock\n");
> @@ -800,8 +812,6 @@ static int csi2_probe(struct platform_device *pdev)
>  	return 0;
>  
>  clean_notifier:
> -	v4l2_async_nf_unregister(&csi2->notifier);
> -	v4l2_async_nf_cleanup(&csi2->notifier);
>  	clk_disable_unprepare(csi2->dphy_clk);
>  pllref_off:
>  	clk_disable_unprepare(csi2->pllref_clk);
> @@ -815,8 +825,6 @@ static void csi2_remove(struct platform_device *pdev)
>  	struct v4l2_subdev *sd = platform_get_drvdata(pdev);
>  	struct csi2_dev *csi2 = sd_to_dev(sd);
>  
> -	v4l2_async_nf_unregister(&csi2->notifier);
> -	v4l2_async_nf_cleanup(&csi2->notifier);
>  	v4l2_async_unregister_subdev(sd);

This effectively moves the notifier unregister after the subdev
unregister. Is that safe to do?


regards
Philipp
Re: [PATCH 2/6] media: staging: media: imx6-mipi-csi2: use devm_add_action_or_reset() to simplify code
Posted by Frank Li 3 months ago
On Mon, Nov 10, 2025 at 09:28:24AM +0100, Philipp Zabel wrote:
> On Fr, 2025-11-07 at 15:44 -0500, Frank Li wrote:
> > Use devm_add_action_or_reset() to simplify the code. No functional change.
> >
> > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > ---
> >  drivers/staging/media/imx/imx6-mipi-csi2.c | 16 ++++++++++++----
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c
> > index 42256441b881d9f132ad7ff899d6f1e35643b4ac..eba9a650030f5e380aa900b94728ad375171c6a5 100644
> > --- a/drivers/staging/media/imx/imx6-mipi-csi2.c
> > +++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
> > @@ -716,6 +716,14 @@ static int csi2_async_register(struct csi2_dev *csi2)
> >  	return ret;
> >  }
> >
> > +static void csi2_nf_cleanup(void *data)
> > +{
> > +	struct csi2_dev *csi2 = data;
> > +
> > +	v4l2_async_nf_unregister(&csi2->notifier);
> > +	v4l2_async_nf_cleanup(&csi2->notifier);
> > +}
> > +
> >  static int csi2_probe(struct platform_device *pdev)
> >  {
> >  	struct csi2_dev *csi2;
> > @@ -749,6 +757,10 @@ static int csi2_probe(struct platform_device *pdev)
> >  	if (ret)
> >  		return ret;
> >
> > +	ret = devm_add_action_or_reset(&pdev->dev, csi2_nf_cleanup, csi2);
> > +	if (ret)
> > +		return ret;
> > +
> >  	csi2->pllref_clk = devm_clk_get(&pdev->dev, "ref");
> >  	if (IS_ERR(csi2->pllref_clk)) {
> >  		v4l2_err(&csi2->sd, "failed to get pll reference clock\n");
> > @@ -800,8 +812,6 @@ static int csi2_probe(struct platform_device *pdev)
> >  	return 0;
> >
> >  clean_notifier:
> > -	v4l2_async_nf_unregister(&csi2->notifier);
> > -	v4l2_async_nf_cleanup(&csi2->notifier);
> >  	clk_disable_unprepare(csi2->dphy_clk);
> >  pllref_off:
> >  	clk_disable_unprepare(csi2->pllref_clk);
> > @@ -815,8 +825,6 @@ static void csi2_remove(struct platform_device *pdev)
> >  	struct v4l2_subdev *sd = platform_get_drvdata(pdev);
> >  	struct csi2_dev *csi2 = sd_to_dev(sd);
> >
> > -	v4l2_async_nf_unregister(&csi2->notifier);
> > -	v4l2_async_nf_cleanup(&csi2->notifier);
> >  	v4l2_async_unregister_subdev(sd);
>
> This effectively moves the notifier unregister after the subdev
> unregister. Is that safe to do?

Good question:

I think, it'd better to provide devm_v4l2_*() helper functions for these.
I am not sure why there are not devm_v4l2*() helper functions now.

Frank
>
>
> regards
> Philipp