linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] counter/ftm-quaddec: Use device-managed registration API
@ 2019-07-26  2:28 Chuhong Yuan
  2019-07-26 12:51 ` Patrick Havelange
  0 siblings, 1 reply; 8+ messages in thread
From: Chuhong Yuan @ 2019-07-26  2:28 UTC (permalink / raw)
  Cc: Patrick Havelange, William Breathitt Gray, linux-iio,
	linux-kernel, Chuhong Yuan

Make use of devm_counter_register.
Then we can remove redundant unregistration API
usage to make code simpler.

Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
Changes in v2:
  - Use devm_add_action_or_reset to keep
    resource release order.
  - _remove() function is redundant now,
    delete it.

 drivers/counter/ftm-quaddec.c | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
index 68a9b7393457..76c70a6c3593 100644
--- a/drivers/counter/ftm-quaddec.c
+++ b/drivers/counter/ftm-quaddec.c
@@ -100,16 +100,17 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
 	ftm_set_write_protection(ftm);
 }
 
-static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
+static void ftm_quaddec_disable(void *ftm)
 {
-	ftm_clear_write_protection(ftm);
-	ftm_write(ftm, FTM_MODE, 0);
-	ftm_write(ftm, FTM_QDCTRL, 0);
+	struct ftm_quaddec *ftm_qua = ftm;

+	ftm_clear_write_protection(ftm_qua);
+	ftm_write(ftm_qua, FTM_MODE, 0);
+	ftm_write(ftm_qua, FTM_QDCTRL, 0);
 	/*
 	 * This is enough to disable the counter. No clock has been
 	 * selected by writing to FTM_SC in init()
 	 */
-	ftm_set_write_protection(ftm);
+	ftm_set_write_protection(ftm_qua);
 }
 
 static int ftm_quaddec_get_prescaler(struct counter_device *counter,
@@ -316,22 +317,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
 	mutex_init(&ftm->ftm_quaddec_mutex);
 
 	ftm_quaddec_init(ftm);
-
-	ret = counter_register(&ftm->counter);
+	ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
 	if (ret)
-		ftm_quaddec_disable(ftm);
-
-	return ret;
-}
-
-static int ftm_quaddec_remove(struct platform_device *pdev)
-{
-	struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
-
-	counter_unregister(&ftm->counter);
-
-	ftm_quaddec_disable(ftm);
+		return ret;
 
+	ret = devm_counter_register(&pdev->dev, &ftm->counter);
+	if (ret)
+		return ret;
 	return 0;
 }
 
@@ -346,7 +338,6 @@ static struct platform_driver ftm_quaddec_driver = {
 		.of_match_table = ftm_quaddec_match,
 	},
 	.probe = ftm_quaddec_probe,
-	.remove = ftm_quaddec_remove,
 };
 
 module_platform_driver(ftm_quaddec_driver);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] counter/ftm-quaddec: Use device-managed registration API
  2019-07-26  2:28 [PATCH v2] counter/ftm-quaddec: Use device-managed registration API Chuhong Yuan
@ 2019-07-26 12:51 ` Patrick Havelange
  2019-07-26 13:21   ` Chuhong Yuan
  2019-07-27 13:31   ` Jonathan Cameron
  0 siblings, 2 replies; 8+ messages in thread
From: Patrick Havelange @ 2019-07-26 12:51 UTC (permalink / raw)
  To: Chuhong Yuan; +Cc: William Breathitt Gray, linux-iio, linux-kernel

Hello,

On Fri, Jul 26, 2019 at 4:28 AM Chuhong Yuan <hslester96@gmail.com> wrote:
>
> Make use of devm_counter_register.
> Then we can remove redundant unregistration API
> usage to make code simpler.
>
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
> Changes in v2:
>   - Use devm_add_action_or_reset to keep
>     resource release order.

This is better now indeed.

However it seems there is an issue with the mail/patch format, I'm
unable to apply it with git am, and if you look at
https://lore.kernel.org/patchwork/patch/1105782/ the diff section is
missing the beginning of the patch. I don't know why, but I think it
should be looked into.

Otherwise, it's fine by me.

Regards,

Patrick Havelange


>   - _remove() function is redundant now,
>     delete it.
>
>  drivers/counter/ftm-quaddec.c | 31 +++++++++++--------------------
>  1 file changed, 11 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> index 68a9b7393457..76c70a6c3593 100644
> --- a/drivers/counter/ftm-quaddec.c
> +++ b/drivers/counter/ftm-quaddec.c
> @@ -100,16 +100,17 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
>         ftm_set_write_protection(ftm);
>  }
>
> -static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
> +static void ftm_quaddec_disable(void *ftm)
>  {
> -       ftm_clear_write_protection(ftm);
> -       ftm_write(ftm, FTM_MODE, 0);
> -       ftm_write(ftm, FTM_QDCTRL, 0);
> +       struct ftm_quaddec *ftm_qua = ftm;
>
> +       ftm_clear_write_protection(ftm_qua);
> +       ftm_write(ftm_qua, FTM_MODE, 0);
> +       ftm_write(ftm_qua, FTM_QDCTRL, 0);
>         /*
>          * This is enough to disable the counter. No clock has been
>          * selected by writing to FTM_SC in init()
>          */
> -       ftm_set_write_protection(ftm);
> +       ftm_set_write_protection(ftm_qua);
>  }
>
>  static int ftm_quaddec_get_prescaler(struct counter_device *counter,
> @@ -316,22 +317,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
>         mutex_init(&ftm->ftm_quaddec_mutex);
>
>         ftm_quaddec_init(ftm);
> -
> -       ret = counter_register(&ftm->counter);
> +       ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
>         if (ret)
> -               ftm_quaddec_disable(ftm);
> -
> -       return ret;
> -}
> -
> -static int ftm_quaddec_remove(struct platform_device *pdev)
> -{
> -       struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
> -
> -       counter_unregister(&ftm->counter);
> -
> -       ftm_quaddec_disable(ftm);
> +               return ret;
>
> +       ret = devm_counter_register(&pdev->dev, &ftm->counter);
> +       if (ret)
> +               return ret;
>         return 0;
>  }
>
> @@ -346,7 +338,6 @@ static struct platform_driver ftm_quaddec_driver = {
>                 .of_match_table = ftm_quaddec_match,
>         },
>         .probe = ftm_quaddec_probe,
> -       .remove = ftm_quaddec_remove,
>  };
>
>  module_platform_driver(ftm_quaddec_driver);
> --
> 2.20.1
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] counter/ftm-quaddec: Use device-managed registration API
  2019-07-26 12:51 ` Patrick Havelange
@ 2019-07-26 13:21   ` Chuhong Yuan
  2019-07-27 13:31   ` Jonathan Cameron
  1 sibling, 0 replies; 8+ messages in thread
From: Chuhong Yuan @ 2019-07-26 13:21 UTC (permalink / raw)
  To: Patrick Havelange; +Cc: William Breathitt Gray, linux-iio, linux-kernel

Patrick Havelange <patrick.havelange@essensium.com> 于2019年7月26日周五 下午8:51写道:
>
> Hello,
>
> On Fri, Jul 26, 2019 at 4:28 AM Chuhong Yuan <hslester96@gmail.com> wrote:
> >
> > Make use of devm_counter_register.
> > Then we can remove redundant unregistration API
> > usage to make code simpler.
> >
> > Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> > ---
> > Changes in v2:
> >   - Use devm_add_action_or_reset to keep
> >     resource release order.
>
> This is better now indeed.
>
> However it seems there is an issue with the mail/patch format, I'm
> unable to apply it with git am, and if you look at
> https://lore.kernel.org/patchwork/patch/1105782/ the diff section is
> missing the beginning of the patch. I don't know why, but I think it
> should be looked into.
>
> Otherwise, it's fine by me.
>
> Regards,
>
> Patrick Havelange

I am also not clear about why this issue happened.
Maybe it is caused by changelog format.
I will revise changelog and resend it later.



>
>
> >   - _remove() function is redundant now,
> >     delete it.
> >
> >  drivers/counter/ftm-quaddec.c | 31 +++++++++++--------------------
> >  1 file changed, 11 insertions(+), 20 deletions(-)
> >
> > diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> > index 68a9b7393457..76c70a6c3593 100644
> > --- a/drivers/counter/ftm-quaddec.c
> > +++ b/drivers/counter/ftm-quaddec.c
> > @@ -100,16 +100,17 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
> >         ftm_set_write_protection(ftm);
> >  }
> >
> > -static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
> > +static void ftm_quaddec_disable(void *ftm)
> >  {
> > -       ftm_clear_write_protection(ftm);
> > -       ftm_write(ftm, FTM_MODE, 0);
> > -       ftm_write(ftm, FTM_QDCTRL, 0);
> > +       struct ftm_quaddec *ftm_qua = ftm;
> >
> > +       ftm_clear_write_protection(ftm_qua);
> > +       ftm_write(ftm_qua, FTM_MODE, 0);
> > +       ftm_write(ftm_qua, FTM_QDCTRL, 0);
> >         /*
> >          * This is enough to disable the counter. No clock has been
> >          * selected by writing to FTM_SC in init()
> >          */
> > -       ftm_set_write_protection(ftm);
> > +       ftm_set_write_protection(ftm_qua);
> >  }
> >
> >  static int ftm_quaddec_get_prescaler(struct counter_device *counter,
> > @@ -316,22 +317,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
> >         mutex_init(&ftm->ftm_quaddec_mutex);
> >
> >         ftm_quaddec_init(ftm);
> > -
> > -       ret = counter_register(&ftm->counter);
> > +       ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
> >         if (ret)
> > -               ftm_quaddec_disable(ftm);
> > -
> > -       return ret;
> > -}
> > -
> > -static int ftm_quaddec_remove(struct platform_device *pdev)
> > -{
> > -       struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
> > -
> > -       counter_unregister(&ftm->counter);
> > -
> > -       ftm_quaddec_disable(ftm);
> > +               return ret;
> >
> > +       ret = devm_counter_register(&pdev->dev, &ftm->counter);
> > +       if (ret)
> > +               return ret;
> >         return 0;
> >  }
> >
> > @@ -346,7 +338,6 @@ static struct platform_driver ftm_quaddec_driver = {
> >                 .of_match_table = ftm_quaddec_match,
> >         },
> >         .probe = ftm_quaddec_probe,
> > -       .remove = ftm_quaddec_remove,
> >  };
> >
> >  module_platform_driver(ftm_quaddec_driver);
> > --
> > 2.20.1
> >

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] counter/ftm-quaddec: Use device-managed registration API
  2019-07-26 12:51 ` Patrick Havelange
  2019-07-26 13:21   ` Chuhong Yuan
@ 2019-07-27 13:31   ` Jonathan Cameron
  2019-07-27 18:13     ` William Breathitt Gray
  1 sibling, 1 reply; 8+ messages in thread
From: Jonathan Cameron @ 2019-07-27 13:31 UTC (permalink / raw)
  To: Patrick Havelange
  Cc: Chuhong Yuan, William Breathitt Gray, linux-iio, linux-kernel

On Fri, 26 Jul 2019 14:51:30 +0200
Patrick Havelange <patrick.havelange@essensium.com> wrote:

> Hello,
> 
> On Fri, Jul 26, 2019 at 4:28 AM Chuhong Yuan <hslester96@gmail.com> wrote:
> >
> > Make use of devm_counter_register.
> > Then we can remove redundant unregistration API
> > usage to make code simpler.
> >
> > Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> > ---
> > Changes in v2:
> >   - Use devm_add_action_or_reset to keep
> >     resource release order.  
> 
> This is better now indeed.
> 
> However it seems there is an issue with the mail/patch format, I'm
> unable to apply it with git am, and if you look at
> https://lore.kernel.org/patchwork/patch/1105782/ the diff section is
> missing the beginning of the patch. I don't know why, but I think it
> should be looked into.
> 
> Otherwise, it's fine by me.
Hi Patrick,

A formal, Acked-by or Reviewed-by definitely preferred if you are happy
to give one.

This looks fine to me as well. William, if you are happy with the resend
of this, then let me know if you want me to queue it up.

Thanks,

Jonathan

> 
> Regards,
> 
> Patrick Havelange
> 
> 
> >   - _remove() function is redundant now,
> >     delete it.
> >
> >  drivers/counter/ftm-quaddec.c | 31 +++++++++++--------------------
> >  1 file changed, 11 insertions(+), 20 deletions(-)
> >
> > diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> > index 68a9b7393457..76c70a6c3593 100644
> > --- a/drivers/counter/ftm-quaddec.c
> > +++ b/drivers/counter/ftm-quaddec.c
> > @@ -100,16 +100,17 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
> >         ftm_set_write_protection(ftm);
> >  }
> >
> > -static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
> > +static void ftm_quaddec_disable(void *ftm)
> >  {
> > -       ftm_clear_write_protection(ftm);
> > -       ftm_write(ftm, FTM_MODE, 0);
> > -       ftm_write(ftm, FTM_QDCTRL, 0);
> > +       struct ftm_quaddec *ftm_qua = ftm;
> >
> > +       ftm_clear_write_protection(ftm_qua);
> > +       ftm_write(ftm_qua, FTM_MODE, 0);
> > +       ftm_write(ftm_qua, FTM_QDCTRL, 0);
> >         /*
> >          * This is enough to disable the counter. No clock has been
> >          * selected by writing to FTM_SC in init()
> >          */
> > -       ftm_set_write_protection(ftm);
> > +       ftm_set_write_protection(ftm_qua);
> >  }
> >
> >  static int ftm_quaddec_get_prescaler(struct counter_device *counter,
> > @@ -316,22 +317,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
> >         mutex_init(&ftm->ftm_quaddec_mutex);
> >
> >         ftm_quaddec_init(ftm);
> > -
> > -       ret = counter_register(&ftm->counter);
> > +       ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
> >         if (ret)
> > -               ftm_quaddec_disable(ftm);
> > -
> > -       return ret;
> > -}
> > -
> > -static int ftm_quaddec_remove(struct platform_device *pdev)
> > -{
> > -       struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
> > -
> > -       counter_unregister(&ftm->counter);
> > -
> > -       ftm_quaddec_disable(ftm);
> > +               return ret;
> >
> > +       ret = devm_counter_register(&pdev->dev, &ftm->counter);
> > +       if (ret)
> > +               return ret;
> >         return 0;
> >  }
> >
> > @@ -346,7 +338,6 @@ static struct platform_driver ftm_quaddec_driver = {
> >                 .of_match_table = ftm_quaddec_match,
> >         },
> >         .probe = ftm_quaddec_probe,
> > -       .remove = ftm_quaddec_remove,
> >  };
> >
> >  module_platform_driver(ftm_quaddec_driver);
> > --
> > 2.20.1
> >  


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] counter/ftm-quaddec: Use device-managed registration API
  2019-07-27 13:31   ` Jonathan Cameron
@ 2019-07-27 18:13     ` William Breathitt Gray
  0 siblings, 0 replies; 8+ messages in thread
From: William Breathitt Gray @ 2019-07-27 18:13 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Patrick Havelange, Chuhong Yuan, linux-iio, linux-kernel

On Sat, Jul 27, 2019 at 02:31:33PM +0100, Jonathan Cameron wrote:
> On Fri, 26 Jul 2019 14:51:30 +0200
> Patrick Havelange <patrick.havelange@essensium.com> wrote:
> 
> > Hello,
> > 
> > On Fri, Jul 26, 2019 at 4:28 AM Chuhong Yuan <hslester96@gmail.com> wrote:
> > >
> > > Make use of devm_counter_register.
> > > Then we can remove redundant unregistration API
> > > usage to make code simpler.
> > >
> > > Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> > > ---
> > > Changes in v2:
> > >   - Use devm_add_action_or_reset to keep
> > >     resource release order.  
> > 
> > This is better now indeed.
> > 
> > However it seems there is an issue with the mail/patch format, I'm
> > unable to apply it with git am, and if you look at
> > https://lore.kernel.org/patchwork/patch/1105782/ the diff section is
> > missing the beginning of the patch. I don't know why, but I think it
> > should be looked into.
> > 
> > Otherwise, it's fine by me.
> Hi Patrick,
> 
> A formal, Acked-by or Reviewed-by definitely preferred if you are happy
> to give one.
> 
> This looks fine to me as well. William, if you are happy with the resend
> of this, then let me know if you want me to queue it up.
> 
> Thanks,
> 
> Jonathan

I'm all right with these changes too. Feel free to queue up the resend
version in your tree when you are ready.

William Breathitt Gray

> 
> > 
> > Regards,
> > 
> > Patrick Havelange
> > 
> > 
> > >   - _remove() function is redundant now,
> > >     delete it.
> > >
> > >  drivers/counter/ftm-quaddec.c | 31 +++++++++++--------------------
> > >  1 file changed, 11 insertions(+), 20 deletions(-)
> > >
> > > diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> > > index 68a9b7393457..76c70a6c3593 100644
> > > --- a/drivers/counter/ftm-quaddec.c
> > > +++ b/drivers/counter/ftm-quaddec.c
> > > @@ -100,16 +100,17 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
> > >         ftm_set_write_protection(ftm);
> > >  }
> > >
> > > -static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
> > > +static void ftm_quaddec_disable(void *ftm)
> > >  {
> > > -       ftm_clear_write_protection(ftm);
> > > -       ftm_write(ftm, FTM_MODE, 0);
> > > -       ftm_write(ftm, FTM_QDCTRL, 0);
> > > +       struct ftm_quaddec *ftm_qua = ftm;
> > >
> > > +       ftm_clear_write_protection(ftm_qua);
> > > +       ftm_write(ftm_qua, FTM_MODE, 0);
> > > +       ftm_write(ftm_qua, FTM_QDCTRL, 0);
> > >         /*
> > >          * This is enough to disable the counter. No clock has been
> > >          * selected by writing to FTM_SC in init()
> > >          */
> > > -       ftm_set_write_protection(ftm);
> > > +       ftm_set_write_protection(ftm_qua);
> > >  }
> > >
> > >  static int ftm_quaddec_get_prescaler(struct counter_device *counter,
> > > @@ -316,22 +317,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
> > >         mutex_init(&ftm->ftm_quaddec_mutex);
> > >
> > >         ftm_quaddec_init(ftm);
> > > -
> > > -       ret = counter_register(&ftm->counter);
> > > +       ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
> > >         if (ret)
> > > -               ftm_quaddec_disable(ftm);
> > > -
> > > -       return ret;
> > > -}
> > > -
> > > -static int ftm_quaddec_remove(struct platform_device *pdev)
> > > -{
> > > -       struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
> > > -
> > > -       counter_unregister(&ftm->counter);
> > > -
> > > -       ftm_quaddec_disable(ftm);
> > > +               return ret;
> > >
> > > +       ret = devm_counter_register(&pdev->dev, &ftm->counter);
> > > +       if (ret)
> > > +               return ret;
> > >         return 0;
> > >  }
> > >
> > > @@ -346,7 +338,6 @@ static struct platform_driver ftm_quaddec_driver = {
> > >                 .of_match_table = ftm_quaddec_match,
> > >         },
> > >         .probe = ftm_quaddec_probe,
> > > -       .remove = ftm_quaddec_remove,
> > >  };
> > >
> > >  module_platform_driver(ftm_quaddec_driver);
> > > --
> > > 2.20.1
> > >  
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] counter/ftm-quaddec: Use device-managed registration API
  2019-07-26 13:39 Chuhong Yuan
  2019-07-27 21:27 ` Jonathan Cameron
@ 2019-07-29 11:52 ` Patrick Havelange
  1 sibling, 0 replies; 8+ messages in thread
From: Patrick Havelange @ 2019-07-29 11:52 UTC (permalink / raw)
  To: Chuhong Yuan; +Cc: William Breathitt Gray, linux-iio, linux-kernel

On Fri, Jul 26, 2019 at 3:39 PM Chuhong Yuan <hslester96@gmail.com> wrote:
>
> Make use of devm_counter_register.
> Then we can remove redundant unregistration API
> usage to make code simpler.
>
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>

Reviewed-by: Patrick Havelange <patrick.havelange@essensium.com>

Maybe a bit too late, sorry for that. Thanks for the patch.

Patrick H.

> ---
> Changes in v2:
>   - Use devm_add_action_or_reset to keep
>     resource release order.
>   - remove() function is redundant now,
>     delete it.
>
>  drivers/counter/ftm-quaddec.c | 30 ++++++++++++------------------
>  1 file changed, 12 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> index 68a9b7393457..4046aa9f9234 100644
> --- a/drivers/counter/ftm-quaddec.c
> +++ b/drivers/counter/ftm-quaddec.c
> @@ -100,16 +100,18 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
>         ftm_set_write_protection(ftm);
>  }
>
> -static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
> +static void ftm_quaddec_disable(void *ftm)
>  {
> -       ftm_clear_write_protection(ftm);
> -       ftm_write(ftm, FTM_MODE, 0);
> -       ftm_write(ftm, FTM_QDCTRL, 0);
> +       struct ftm_quaddec *ftm_qua = ftm;
> +
> +       ftm_clear_write_protection(ftm_qua);
> +       ftm_write(ftm_qua, FTM_MODE, 0);
> +       ftm_write(ftm_qua, FTM_QDCTRL, 0);
>         /*
>          * This is enough to disable the counter. No clock has been
>          * selected by writing to FTM_SC in init()
>          */
> -       ftm_set_write_protection(ftm);
> +       ftm_set_write_protection(ftm_qua);
>  }
>
>  static int ftm_quaddec_get_prescaler(struct counter_device *counter,
> @@ -317,20 +319,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
>
>         ftm_quaddec_init(ftm);
>
> -       ret = counter_register(&ftm->counter);
> +       ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
>         if (ret)
> -               ftm_quaddec_disable(ftm);
> -
> -       return ret;
> -}
> +               return ret;
>
> -static int ftm_quaddec_remove(struct platform_device *pdev)
> -{
> -       struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
> -
> -       counter_unregister(&ftm->counter);
> -
> -       ftm_quaddec_disable(ftm);
> +       ret = devm_counter_register(&pdev->dev, &ftm->counter);
> +       if (ret)
> +               return ret;
>
>         return 0;
>  }
> @@ -346,7 +341,6 @@ static struct platform_driver ftm_quaddec_driver = {
>                 .of_match_table = ftm_quaddec_match,
>         },
>         .probe = ftm_quaddec_probe,
> -       .remove = ftm_quaddec_remove,
>  };
>
>  module_platform_driver(ftm_quaddec_driver);
> --
> 2.20.1
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] counter/ftm-quaddec: Use device-managed registration API
  2019-07-26 13:39 Chuhong Yuan
@ 2019-07-27 21:27 ` Jonathan Cameron
  2019-07-29 11:52 ` Patrick Havelange
  1 sibling, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2019-07-27 21:27 UTC (permalink / raw)
  To: Chuhong Yuan
  Cc: Patrick Havelange, William Breathitt Gray, linux-iio, linux-kernel

On Fri, 26 Jul 2019 21:39:16 +0800
Chuhong Yuan <hslester96@gmail.com> wrote:

> Make use of devm_counter_register.
> Then we can remove redundant unregistration API
> usage to make code simpler.
> 
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
> Changes in v2:
>   - Use devm_add_action_or_reset to keep
>     resource release order.
>   - remove() function is redundant now,
>     delete it.
> 
>  drivers/counter/ftm-quaddec.c | 30 ++++++++++++------------------
>  1 file changed, 12 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> index 68a9b7393457..4046aa9f9234 100644
> --- a/drivers/counter/ftm-quaddec.c
> +++ b/drivers/counter/ftm-quaddec.c
> @@ -100,16 +100,18 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
>  	ftm_set_write_protection(ftm);
>  }
>  
> -static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
> +static void ftm_quaddec_disable(void *ftm)
>  {
> -	ftm_clear_write_protection(ftm);
> -	ftm_write(ftm, FTM_MODE, 0);
> -	ftm_write(ftm, FTM_QDCTRL, 0);
> +	struct ftm_quaddec *ftm_qua = ftm;
> +
> +	ftm_clear_write_protection(ftm_qua);
> +	ftm_write(ftm_qua, FTM_MODE, 0);
> +	ftm_write(ftm_qua, FTM_QDCTRL, 0);
>  	/*
>  	 * This is enough to disable the counter. No clock has been
>  	 * selected by writing to FTM_SC in init()
>  	 */
> -	ftm_set_write_protection(ftm);
> +	ftm_set_write_protection(ftm_qua);
>  }
>  
>  static int ftm_quaddec_get_prescaler(struct counter_device *counter,
> @@ -317,20 +319,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
>  
>  	ftm_quaddec_init(ftm);
>  
> -	ret = counter_register(&ftm->counter);
> +	ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
>  	if (ret)
> -		ftm_quaddec_disable(ftm);
> -
> -	return ret;
> -}
> +		return ret;
>  
> -static int ftm_quaddec_remove(struct platform_device *pdev)
> -{
> -	struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
> -
> -	counter_unregister(&ftm->counter);
> -
> -	ftm_quaddec_disable(ftm);
> +	ret = devm_counter_register(&pdev->dev, &ftm->counter);
> +	if (ret)
> +		return ret;
>  
>  	return 0;
>  }
> @@ -346,7 +341,6 @@ static struct platform_driver ftm_quaddec_driver = {
>  		.of_match_table = ftm_quaddec_match,
>  	},
>  	.probe = ftm_quaddec_probe,
> -	.remove = ftm_quaddec_remove,
>  };
>  
>  module_platform_driver(ftm_quaddec_driver);


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] counter/ftm-quaddec: Use device-managed registration API
@ 2019-07-26 13:39 Chuhong Yuan
  2019-07-27 21:27 ` Jonathan Cameron
  2019-07-29 11:52 ` Patrick Havelange
  0 siblings, 2 replies; 8+ messages in thread
From: Chuhong Yuan @ 2019-07-26 13:39 UTC (permalink / raw)
  Cc: Patrick Havelange, William Breathitt Gray, linux-iio,
	linux-kernel, Chuhong Yuan

Make use of devm_counter_register.
Then we can remove redundant unregistration API
usage to make code simpler.

Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
Changes in v2:
  - Use devm_add_action_or_reset to keep
    resource release order.
  - remove() function is redundant now,
    delete it.

 drivers/counter/ftm-quaddec.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
index 68a9b7393457..4046aa9f9234 100644
--- a/drivers/counter/ftm-quaddec.c
+++ b/drivers/counter/ftm-quaddec.c
@@ -100,16 +100,18 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
 	ftm_set_write_protection(ftm);
 }
 
-static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
+static void ftm_quaddec_disable(void *ftm)
 {
-	ftm_clear_write_protection(ftm);
-	ftm_write(ftm, FTM_MODE, 0);
-	ftm_write(ftm, FTM_QDCTRL, 0);
+	struct ftm_quaddec *ftm_qua = ftm;
+
+	ftm_clear_write_protection(ftm_qua);
+	ftm_write(ftm_qua, FTM_MODE, 0);
+	ftm_write(ftm_qua, FTM_QDCTRL, 0);
 	/*
 	 * This is enough to disable the counter. No clock has been
 	 * selected by writing to FTM_SC in init()
 	 */
-	ftm_set_write_protection(ftm);
+	ftm_set_write_protection(ftm_qua);
 }
 
 static int ftm_quaddec_get_prescaler(struct counter_device *counter,
@@ -317,20 +319,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
 
 	ftm_quaddec_init(ftm);
 
-	ret = counter_register(&ftm->counter);
+	ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
 	if (ret)
-		ftm_quaddec_disable(ftm);
-
-	return ret;
-}
+		return ret;
 
-static int ftm_quaddec_remove(struct platform_device *pdev)
-{
-	struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
-
-	counter_unregister(&ftm->counter);
-
-	ftm_quaddec_disable(ftm);
+	ret = devm_counter_register(&pdev->dev, &ftm->counter);
+	if (ret)
+		return ret;
 
 	return 0;
 }
@@ -346,7 +341,6 @@ static struct platform_driver ftm_quaddec_driver = {
 		.of_match_table = ftm_quaddec_match,
 	},
 	.probe = ftm_quaddec_probe,
-	.remove = ftm_quaddec_remove,
 };
 
 module_platform_driver(ftm_quaddec_driver);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-07-29 11:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-26  2:28 [PATCH v2] counter/ftm-quaddec: Use device-managed registration API Chuhong Yuan
2019-07-26 12:51 ` Patrick Havelange
2019-07-26 13:21   ` Chuhong Yuan
2019-07-27 13:31   ` Jonathan Cameron
2019-07-27 18:13     ` William Breathitt Gray
2019-07-26 13:39 Chuhong Yuan
2019-07-27 21:27 ` Jonathan Cameron
2019-07-29 11:52 ` Patrick Havelange

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).