diff mbox series

[v2,10/10] pinctrl: tegra: Switch to use DEFINE_NOIRQ_DEV_PM_OPS() helper

Message ID 20230717172821.62827-11-andriy.shevchenko@linux.intel.com
State Handled Elsewhere
Headers show
Series pinctrl: Provide NOIRQ PM helper and use it | expand

Commit Message

Andy Shevchenko July 17, 2023, 5:28 p.m. UTC
Since pm.h provides a helper for system no-IRQ PM callbacks,
switch the driver to use it instead of open coded variant.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/tegra/pinctrl-tegra.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Paul Cercueil July 17, 2023, 7:14 p.m. UTC | #1
Hi Andy,

Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a écrit :
> Since pm.h provides a helper for system no-IRQ PM callbacks,
> switch the driver to use it instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/pinctrl/tegra/pinctrl-tegra.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c
> b/drivers/pinctrl/tegra/pinctrl-tegra.c
> index 4547cf66d03b..734c71ef005b 100644
> --- a/drivers/pinctrl/tegra/pinctrl-tegra.c
> +++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
> @@ -747,10 +747,7 @@ static int tegra_pinctrl_resume(struct device
> *dev)
>         return 0;
>  }
>  
> -const struct dev_pm_ops tegra_pinctrl_pm = {
> -       .suspend_noirq = &tegra_pinctrl_suspend,
> -       .resume_noirq = &tegra_pinctrl_resume
> -};
> +DEFINE_NOIRQ_DEV_PM_OPS(tegra_pinctrl_pm, tegra_pinctrl_suspend,
> tegra_pinctrl_resume);
>  
>  static bool tegra_pinctrl_gpio_node_has_range(struct tegra_pmx *pmx)
>  {

Another driver where using EXPORT_GPL_DEV_PM_OPS() would make more
sense.

Cheers,
-Paul
Andy Shevchenko July 17, 2023, 7:39 p.m. UTC | #2
On Mon, Jul 17, 2023 at 10:14 PM Paul Cercueil <paul@crapouillou.net> wrote:
> Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a écrit :

...

> Another driver where using EXPORT_GPL_DEV_PM_OPS() would make more
> sense.

OK.

...

Thank you for the review of the series!
Thierry Reding July 18, 2023, 7:45 a.m. UTC | #3
On Mon, Jul 17, 2023 at 09:14:12PM +0200, Paul Cercueil wrote:
> Hi Andy,
> 
> Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a écrit :
> > Since pm.h provides a helper for system no-IRQ PM callbacks,
> > switch the driver to use it instead of open coded variant.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >  drivers/pinctrl/tegra/pinctrl-tegra.c | 5 +----
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> > 
> > diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > index 4547cf66d03b..734c71ef005b 100644
> > --- a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > +++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > @@ -747,10 +747,7 @@ static int tegra_pinctrl_resume(struct device
> > *dev)
> >         return 0;
> >  }
> >  
> > -const struct dev_pm_ops tegra_pinctrl_pm = {
> > -       .suspend_noirq = &tegra_pinctrl_suspend,
> > -       .resume_noirq = &tegra_pinctrl_resume
> > -};
> > +DEFINE_NOIRQ_DEV_PM_OPS(tegra_pinctrl_pm, tegra_pinctrl_suspend,
> > tegra_pinctrl_resume);
> >  
> >  static bool tegra_pinctrl_gpio_node_has_range(struct tegra_pmx *pmx)
> >  {
> 
> Another driver where using EXPORT_GPL_DEV_PM_OPS() would make more
> sense.

We don't currently export these PM ops because none of the Tegra pinctrl
drivers can be built as a module.

Thierry
Thierry Reding July 18, 2023, 7:46 a.m. UTC | #4
On Mon, Jul 17, 2023 at 08:28:21PM +0300, Andy Shevchenko wrote:
> Since pm.h provides a helper for system no-IRQ PM callbacks,
> switch the driver to use it instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/pinctrl/tegra/pinctrl-tegra.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)

Acked-by: Thierry Reding <treding@nvidia.com>
Paul Cercueil July 18, 2023, 8:42 a.m. UTC | #5
Hi Thierry,

Le mardi 18 juillet 2023 à 09:45 +0200, Thierry Reding a écrit :
> On Mon, Jul 17, 2023 at 09:14:12PM +0200, Paul Cercueil wrote:
> > Hi Andy,
> > 
> > Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a écrit :
> > > Since pm.h provides a helper for system no-IRQ PM callbacks,
> > > switch the driver to use it instead of open coded variant.
> > > 
> > > Signed-off-by: Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com>
> > > ---
> > >  drivers/pinctrl/tegra/pinctrl-tegra.c | 5 +----
> > >  1 file changed, 1 insertion(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > index 4547cf66d03b..734c71ef005b 100644
> > > --- a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > +++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > @@ -747,10 +747,7 @@ static int tegra_pinctrl_resume(struct
> > > device
> > > *dev)
> > >         return 0;
> > >  }
> > >  
> > > -const struct dev_pm_ops tegra_pinctrl_pm = {
> > > -       .suspend_noirq = &tegra_pinctrl_suspend,
> > > -       .resume_noirq = &tegra_pinctrl_resume
> > > -};
> > > +DEFINE_NOIRQ_DEV_PM_OPS(tegra_pinctrl_pm, tegra_pinctrl_suspend,
> > > tegra_pinctrl_resume);
> > >  
> > >  static bool tegra_pinctrl_gpio_node_has_range(struct tegra_pmx
> > > *pmx)
> > >  {
> > 
> > Another driver where using EXPORT_GPL_DEV_PM_OPS() would make more
> > sense.
> 
> We don't currently export these PM ops because none of the Tegra
> pinctrl
> drivers can be built as a module.

This doesn't change anything. You'd want to use EXPORT_GPL_DEV_PM_OPS
(or better, the namespaced version) so that the PM ops can be defined
in one file and referenced in another, while still having them garbage-
collected when CONFIG_PM is disabled.

Cheers,
-Paul
Jonathan Cameron July 18, 2023, 10:11 a.m. UTC | #6
On Mon, 17 Jul 2023 20:28:21 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Since pm.h provides a helper for system no-IRQ PM callbacks,
> switch the driver to use it instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

No pm_sleep_ptr()?

> ---
>  drivers/pinctrl/tegra/pinctrl-tegra.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c b/drivers/pinctrl/tegra/pinctrl-tegra.c
> index 4547cf66d03b..734c71ef005b 100644
> --- a/drivers/pinctrl/tegra/pinctrl-tegra.c
> +++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
> @@ -747,10 +747,7 @@ static int tegra_pinctrl_resume(struct device *dev)
>  	return 0;
>  }
>  
> -const struct dev_pm_ops tegra_pinctrl_pm = {
> -	.suspend_noirq = &tegra_pinctrl_suspend,
> -	.resume_noirq = &tegra_pinctrl_resume
> -};
> +DEFINE_NOIRQ_DEV_PM_OPS(tegra_pinctrl_pm, tegra_pinctrl_suspend, tegra_pinctrl_resume);
>  
>  static bool tegra_pinctrl_gpio_node_has_range(struct tegra_pmx *pmx)
>  {
Thierry Reding July 18, 2023, 11:38 a.m. UTC | #7
On Tue, Jul 18, 2023 at 11:11:43AM +0100, Jonathan Cameron wrote:
> On Mon, 17 Jul 2023 20:28:21 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > Since pm.h provides a helper for system no-IRQ PM callbacks,
> > switch the driver to use it instead of open coded variant.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> No pm_sleep_ptr()?

pm_sleep_ptr() is pointless on this driver. This driver is selected by
ARCH_TEGRA and ARCH_TEGRA also always selects PM.

Thierry
Thierry Reding July 18, 2023, 11:41 a.m. UTC | #8
On Tue, Jul 18, 2023 at 10:42:47AM +0200, Paul Cercueil wrote:
> Hi Thierry,
> 
> Le mardi 18 juillet 2023 à 09:45 +0200, Thierry Reding a écrit :
> > On Mon, Jul 17, 2023 at 09:14:12PM +0200, Paul Cercueil wrote:
> > > Hi Andy,
> > > 
> > > Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a écrit :
> > > > Since pm.h provides a helper for system no-IRQ PM callbacks,
> > > > switch the driver to use it instead of open coded variant.
> > > > 
> > > > Signed-off-by: Andy Shevchenko
> > > > <andriy.shevchenko@linux.intel.com>
> > > > ---
> > > >  drivers/pinctrl/tegra/pinctrl-tegra.c | 5 +----
> > > >  1 file changed, 1 insertion(+), 4 deletions(-)
> > > > 
> > > > diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > index 4547cf66d03b..734c71ef005b 100644
> > > > --- a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > +++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > @@ -747,10 +747,7 @@ static int tegra_pinctrl_resume(struct
> > > > device
> > > > *dev)
> > > >         return 0;
> > > >  }
> > > >  
> > > > -const struct dev_pm_ops tegra_pinctrl_pm = {
> > > > -       .suspend_noirq = &tegra_pinctrl_suspend,
> > > > -       .resume_noirq = &tegra_pinctrl_resume
> > > > -};
> > > > +DEFINE_NOIRQ_DEV_PM_OPS(tegra_pinctrl_pm, tegra_pinctrl_suspend,
> > > > tegra_pinctrl_resume);
> > > >  
> > > >  static bool tegra_pinctrl_gpio_node_has_range(struct tegra_pmx
> > > > *pmx)
> > > >  {
> > > 
> > > Another driver where using EXPORT_GPL_DEV_PM_OPS() would make more
> > > sense.
> > 
> > We don't currently export these PM ops because none of the Tegra
> > pinctrl
> > drivers can be built as a module.
> 
> This doesn't change anything. You'd want to use EXPORT_GPL_DEV_PM_OPS
> (or better, the namespaced version) so that the PM ops can be defined
> in one file and referenced in another, while still having them garbage-
> collected when CONFIG_PM is disabled.

Looking at the definition of EXPORT_GPL_DEV_PM_OPS(), it will cause an
EXPORT_SYMBOL_GPL() to be added. So there very well is a change. And
it's a completely bogus change because no module is ever going to use
that symbol. If we were to ever support building the pinctrl driver as
a module, then this would perhaps make sense, but we don't.

Thierry
Paul Cercueil July 18, 2023, 11:55 a.m. UTC | #9
Le mardi 18 juillet 2023 à 13:41 +0200, Thierry Reding a écrit :
> On Tue, Jul 18, 2023 at 10:42:47AM +0200, Paul Cercueil wrote:
> > Hi Thierry,
> > 
> > Le mardi 18 juillet 2023 à 09:45 +0200, Thierry Reding a écrit :
> > > On Mon, Jul 17, 2023 at 09:14:12PM +0200, Paul Cercueil wrote:
> > > > Hi Andy,
> > > > 
> > > > Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a
> > > > écrit :
> > > > > Since pm.h provides a helper for system no-IRQ PM callbacks,
> > > > > switch the driver to use it instead of open coded variant.
> > > > > 
> > > > > Signed-off-by: Andy Shevchenko
> > > > > <andriy.shevchenko@linux.intel.com>
> > > > > ---
> > > > >  drivers/pinctrl/tegra/pinctrl-tegra.c | 5 +----
> > > > >  1 file changed, 1 insertion(+), 4 deletions(-)
> > > > > 
> > > > > diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > index 4547cf66d03b..734c71ef005b 100644
> > > > > --- a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > +++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > @@ -747,10 +747,7 @@ static int tegra_pinctrl_resume(struct
> > > > > device
> > > > > *dev)
> > > > >         return 0;
> > > > >  }
> > > > >  
> > > > > -const struct dev_pm_ops tegra_pinctrl_pm = {
> > > > > -       .suspend_noirq = &tegra_pinctrl_suspend,
> > > > > -       .resume_noirq = &tegra_pinctrl_resume
> > > > > -};
> > > > > +DEFINE_NOIRQ_DEV_PM_OPS(tegra_pinctrl_pm,
> > > > > tegra_pinctrl_suspend,
> > > > > tegra_pinctrl_resume);
> > > > >  
> > > > >  static bool tegra_pinctrl_gpio_node_has_range(struct
> > > > > tegra_pmx
> > > > > *pmx)
> > > > >  {
> > > > 
> > > > Another driver where using EXPORT_GPL_DEV_PM_OPS() would make
> > > > more
> > > > sense.
> > > 
> > > We don't currently export these PM ops because none of the Tegra
> > > pinctrl
> > > drivers can be built as a module.
> > 
> > This doesn't change anything. You'd want to use
> > EXPORT_GPL_DEV_PM_OPS
> > (or better, the namespaced version) so that the PM ops can be
> > defined
> > in one file and referenced in another, while still having them
> > garbage-
> > collected when CONFIG_PM is disabled.
> 
> Looking at the definition of EXPORT_GPL_DEV_PM_OPS(), it will cause
> an
> EXPORT_SYMBOL_GPL() to be added. So there very well is a change. And
> it's a completely bogus change because no module is ever going to use
> that symbol. If we were to ever support building the pinctrl driver
> as
> a module, then this would perhaps make sense, but we don't.

In this particular case the EXPORT_SYMBOL_GPL() isn't really important,
the rest of EXPORT_GPL_DEV_PM_OPS() is.

I don't think having a symbol exported it is a big deal, TBH, if you
use the namespaced version. If you really don't want that, we need a
version of EXPORT_GPL_DEV_PM_OPS() that doesn't export the symbol.

-Paul
Paul Cercueil July 18, 2023, 12:01 p.m. UTC | #10
Hi Thierry,

Le mardi 18 juillet 2023 à 13:38 +0200, Thierry Reding a écrit :
> On Tue, Jul 18, 2023 at 11:11:43AM +0100, Jonathan Cameron wrote:
> > On Mon, 17 Jul 2023 20:28:21 +0300
> > Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > 
> > > Since pm.h provides a helper for system no-IRQ PM callbacks,
> > > switch the driver to use it instead of open coded variant.
> > > 
> > > Signed-off-by: Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com>
> > 
> > No pm_sleep_ptr()?
> 
> pm_sleep_ptr() is pointless on this driver. This driver is selected
> by
> ARCH_TEGRA and ARCH_TEGRA also always selects PM.

If I'm not mistaken, ARCH_TEGRA selects CONFIG_PM, not CONFIG_PM_SLEEP.

Cheers,
-Paul
Andy Shevchenko July 18, 2023, 12:50 p.m. UTC | #11
On Tue, Jul 18, 2023 at 2:55 PM Paul Cercueil <paul@crapouillou.net> wrote:
> Le mardi 18 juillet 2023 à 13:41 +0200, Thierry Reding a écrit :
> > On Tue, Jul 18, 2023 at 10:42:47AM +0200, Paul Cercueil wrote:

...

> > Looking at the definition of EXPORT_GPL_DEV_PM_OPS(), it will cause
> > an
> > EXPORT_SYMBOL_GPL() to be added. So there very well is a change. And
> > it's a completely bogus change because no module is ever going to use
> > that symbol. If we were to ever support building the pinctrl driver
> > as
> > a module, then this would perhaps make sense, but we don't.
>
> In this particular case the EXPORT_SYMBOL_GPL() isn't really important,
> the rest of EXPORT_GPL_DEV_PM_OPS() is.
>
> I don't think having a symbol exported it is a big deal, TBH, if you
> use the namespaced version. If you really don't want that, we need a
> version of EXPORT_GPL_DEV_PM_OPS() that doesn't export the symbol.

Ah, I agree with Thierry and it is another point why I do not like
those EXPORT*PM_OPS() macros.
Polluting an exported space (even namespaced) is a big deal, so,
definitely no from my side.
Andy Shevchenko July 18, 2023, 12:53 p.m. UTC | #12
On Tue, Jul 18, 2023 at 11:43 AM Paul Cercueil <paul@crapouillou.net> wrote:
> Le mardi 18 juillet 2023 à 09:45 +0200, Thierry Reding a écrit :

...

> (or better, the namespaced version)

I am all for consistency, I agree on this whenever the driver is
_already_ using namespaces. Having one macro with namespace and
disrupting tons of the drivers (MediaTek case?) is not an option in my
opinion.
Thierry Reding July 18, 2023, 1:07 p.m. UTC | #13
On Tue, Jul 18, 2023 at 02:01:27PM +0200, Paul Cercueil wrote:
> Hi Thierry,
> 
> Le mardi 18 juillet 2023 à 13:38 +0200, Thierry Reding a écrit :
> > On Tue, Jul 18, 2023 at 11:11:43AM +0100, Jonathan Cameron wrote:
> > > On Mon, 17 Jul 2023 20:28:21 +0300
> > > Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > > 
> > > > Since pm.h provides a helper for system no-IRQ PM callbacks,
> > > > switch the driver to use it instead of open coded variant.
> > > > 
> > > > Signed-off-by: Andy Shevchenko
> > > > <andriy.shevchenko@linux.intel.com>
> > > 
> > > No pm_sleep_ptr()?
> > 
> > pm_sleep_ptr() is pointless on this driver. This driver is selected
> > by
> > ARCH_TEGRA and ARCH_TEGRA also always selects PM.
> 
> If I'm not mistaken, ARCH_TEGRA selects CONFIG_PM, not CONFIG_PM_SLEEP.

Indeed. I suppose pm_sleep_ptr() would make sense, then.

Thierry
Thierry Reding July 18, 2023, 1:20 p.m. UTC | #14
On Tue, Jul 18, 2023 at 01:55:05PM +0200, Paul Cercueil wrote:
> Le mardi 18 juillet 2023 à 13:41 +0200, Thierry Reding a écrit :
> > On Tue, Jul 18, 2023 at 10:42:47AM +0200, Paul Cercueil wrote:
> > > Hi Thierry,
> > > 
> > > Le mardi 18 juillet 2023 à 09:45 +0200, Thierry Reding a écrit :
> > > > On Mon, Jul 17, 2023 at 09:14:12PM +0200, Paul Cercueil wrote:
> > > > > Hi Andy,
> > > > > 
> > > > > Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a
> > > > > écrit :
> > > > > > Since pm.h provides a helper for system no-IRQ PM callbacks,
> > > > > > switch the driver to use it instead of open coded variant.
> > > > > > 
> > > > > > Signed-off-by: Andy Shevchenko
> > > > > > <andriy.shevchenko@linux.intel.com>
> > > > > > ---
> > > > > >  drivers/pinctrl/tegra/pinctrl-tegra.c | 5 +----
> > > > > >  1 file changed, 1 insertion(+), 4 deletions(-)
> > > > > > 
> > > > > > diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > > b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > > index 4547cf66d03b..734c71ef005b 100644
> > > > > > --- a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > > +++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > > @@ -747,10 +747,7 @@ static int tegra_pinctrl_resume(struct
> > > > > > device
> > > > > > *dev)
> > > > > >         return 0;
> > > > > >  }
> > > > > >  
> > > > > > -const struct dev_pm_ops tegra_pinctrl_pm = {
> > > > > > -       .suspend_noirq = &tegra_pinctrl_suspend,
> > > > > > -       .resume_noirq = &tegra_pinctrl_resume
> > > > > > -};
> > > > > > +DEFINE_NOIRQ_DEV_PM_OPS(tegra_pinctrl_pm,
> > > > > > tegra_pinctrl_suspend,
> > > > > > tegra_pinctrl_resume);
> > > > > >  
> > > > > >  static bool tegra_pinctrl_gpio_node_has_range(struct
> > > > > > tegra_pmx
> > > > > > *pmx)
> > > > > >  {
> > > > > 
> > > > > Another driver where using EXPORT_GPL_DEV_PM_OPS() would make
> > > > > more
> > > > > sense.
> > > > 
> > > > We don't currently export these PM ops because none of the Tegra
> > > > pinctrl
> > > > drivers can be built as a module.
> > > 
> > > This doesn't change anything. You'd want to use
> > > EXPORT_GPL_DEV_PM_OPS
> > > (or better, the namespaced version) so that the PM ops can be
> > > defined
> > > in one file and referenced in another, while still having them
> > > garbage-
> > > collected when CONFIG_PM is disabled.
> > 
> > Looking at the definition of EXPORT_GPL_DEV_PM_OPS(), it will cause
> > an
> > EXPORT_SYMBOL_GPL() to be added. So there very well is a change. And
> > it's a completely bogus change because no module is ever going to use
> > that symbol. If we were to ever support building the pinctrl driver
> > as
> > a module, then this would perhaps make sense, but we don't.
> 
> In this particular case the EXPORT_SYMBOL_GPL() isn't really important,
> the rest of EXPORT_GPL_DEV_PM_OPS() is.
> 
> I don't think having a symbol exported it is a big deal, TBH, if you
> use the namespaced version. If you really don't want that, we need a
> version of EXPORT_GPL_DEV_PM_OPS() that doesn't export the symbol.

I do think it's a big deal to export a symbol if there's no reason to do
so.

And please, can we stop adding these macros for every possible scenario?
Maybe I'm just getting old, but I find it increasingly difficult to
understand what all of these are supposed to be. I get that people want
to get rid of boilerplate, but I think we need to more carefully balance
boilerplate vs. simplicity.

I'm seeing the same thing with stuff like those mass conversions to
atrocities like devm_platform_ioremap_resource() and
devm_platform_get_and_ioremap_resource(). There's so much churn involved
in getting those merged for usually saving a single line of code. And
it's not even mass conversions, but people tend to send these as one
patch per driver, which doesn't exactly help (except perhaps for patch
statistics).

Thierry
Paul Cercueil July 18, 2023, 1:48 p.m. UTC | #15
Hi Thierry,

Le mardi 18 juillet 2023 à 15:20 +0200, Thierry Reding a écrit :
> On Tue, Jul 18, 2023 at 01:55:05PM +0200, Paul Cercueil wrote:
> > Le mardi 18 juillet 2023 à 13:41 +0200, Thierry Reding a écrit :
> > > On Tue, Jul 18, 2023 at 10:42:47AM +0200, Paul Cercueil wrote:
> > > > Hi Thierry,
> > > > 
> > > > Le mardi 18 juillet 2023 à 09:45 +0200, Thierry Reding a
> > > > écrit :
> > > > > On Mon, Jul 17, 2023 at 09:14:12PM +0200, Paul Cercueil
> > > > > wrote:
> > > > > > Hi Andy,
> > > > > > 
> > > > > > Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a
> > > > > > écrit :
> > > > > > > Since pm.h provides a helper for system no-IRQ PM
> > > > > > > callbacks,
> > > > > > > switch the driver to use it instead of open coded
> > > > > > > variant.
> > > > > > > 
> > > > > > > Signed-off-by: Andy Shevchenko
> > > > > > > <andriy.shevchenko@linux.intel.com>
> > > > > > > ---
> > > > > > >  drivers/pinctrl/tegra/pinctrl-tegra.c | 5 +----
> > > > > > >  1 file changed, 1 insertion(+), 4 deletions(-)
> > > > > > > 
> > > > > > > diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > > > b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > > > index 4547cf66d03b..734c71ef005b 100644
> > > > > > > --- a/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > > > +++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
> > > > > > > @@ -747,10 +747,7 @@ static int
> > > > > > > tegra_pinctrl_resume(struct
> > > > > > > device
> > > > > > > *dev)
> > > > > > >         return 0;
> > > > > > >  }
> > > > > > >  
> > > > > > > -const struct dev_pm_ops tegra_pinctrl_pm = {
> > > > > > > -       .suspend_noirq = &tegra_pinctrl_suspend,
> > > > > > > -       .resume_noirq = &tegra_pinctrl_resume
> > > > > > > -};
> > > > > > > +DEFINE_NOIRQ_DEV_PM_OPS(tegra_pinctrl_pm,
> > > > > > > tegra_pinctrl_suspend,
> > > > > > > tegra_pinctrl_resume);
> > > > > > >  
> > > > > > >  static bool tegra_pinctrl_gpio_node_has_range(struct
> > > > > > > tegra_pmx
> > > > > > > *pmx)
> > > > > > >  {
> > > > > > 
> > > > > > Another driver where using EXPORT_GPL_DEV_PM_OPS() would
> > > > > > make
> > > > > > more
> > > > > > sense.
> > > > > 
> > > > > We don't currently export these PM ops because none of the
> > > > > Tegra
> > > > > pinctrl
> > > > > drivers can be built as a module.
> > > > 
> > > > This doesn't change anything. You'd want to use
> > > > EXPORT_GPL_DEV_PM_OPS
> > > > (or better, the namespaced version) so that the PM ops can be
> > > > defined
> > > > in one file and referenced in another, while still having them
> > > > garbage-
> > > > collected when CONFIG_PM is disabled.
> > > 
> > > Looking at the definition of EXPORT_GPL_DEV_PM_OPS(), it will
> > > cause
> > > an
> > > EXPORT_SYMBOL_GPL() to be added. So there very well is a change.
> > > And
> > > it's a completely bogus change because no module is ever going to
> > > use
> > > that symbol. If we were to ever support building the pinctrl
> > > driver
> > > as
> > > a module, then this would perhaps make sense, but we don't.
> > 
> > In this particular case the EXPORT_SYMBOL_GPL() isn't really
> > important,
> > the rest of EXPORT_GPL_DEV_PM_OPS() is.
> > 
> > I don't think having a symbol exported it is a big deal, TBH, if
> > you
> > use the namespaced version. If you really don't want that, we need
> > a
> > version of EXPORT_GPL_DEV_PM_OPS() that doesn't export the symbol.
> 
> I do think it's a big deal to export a symbol if there's no reason to
> do
> so.
> 
> And please, can we stop adding these macros for every possible
> scenario?

Yes, as you can read from my other responses, I am not really keen on
having a multiplication of these macros.

> Maybe I'm just getting old, but I find it increasingly difficult to
> understand what all of these are supposed to be. I get that people
> want
> to get rid of boilerplate, but I think we need to more carefully
> balance
> boilerplate vs. simplicity.

The EXPORT_GPL_DEV_PM_OPS() macro does more than get rid of
boilerplate, it gets rid of dead code.

If we take this driver as an example, before the patch the
"tegra_pinctrl_pm" struct, as well as the "tegra_pinctrl_suspend" and
"tegra_pinctrl_resume" functions were always compiled in, even if
CONFIG_PM_SLEEP is disabled in the config.

The status-quo before the introduction of the new PM macros was to just
wrap the dev_pm_ops struct + callbacks with a #ifdef CONFIG_PM_SLEEP.
This was pretty bad as the code was then conditionally compiled. With
the new PM macros this code is always compiled, independently of any
Kconfig option; and thanks to that, bugs and regressions are
subsequently easier to catch.

Cheers,
-Paul

> I'm seeing the same thing with stuff like those mass conversions to
> atrocities like devm_platform_ioremap_resource() and
> devm_platform_get_and_ioremap_resource(). There's so much churn
> involved
> in getting those merged for usually saving a single line of code. And
> it's not even mass conversions, but people tend to send these as one
> patch per driver, which doesn't exactly help (except perhaps for
> patch
> statistics).
> 
> Thierry
diff mbox series

Patch

diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c b/drivers/pinctrl/tegra/pinctrl-tegra.c
index 4547cf66d03b..734c71ef005b 100644
--- a/drivers/pinctrl/tegra/pinctrl-tegra.c
+++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
@@ -747,10 +747,7 @@  static int tegra_pinctrl_resume(struct device *dev)
 	return 0;
 }
 
-const struct dev_pm_ops tegra_pinctrl_pm = {
-	.suspend_noirq = &tegra_pinctrl_suspend,
-	.resume_noirq = &tegra_pinctrl_resume
-};
+DEFINE_NOIRQ_DEV_PM_OPS(tegra_pinctrl_pm, tegra_pinctrl_suspend, tegra_pinctrl_resume);
 
 static bool tegra_pinctrl_gpio_node_has_range(struct tegra_pmx *pmx)
 {