mbox series

[v1,0/3] pinctrl: intel: Get rid of ifdeffery leftovers

Message ID 20240903170752.3564538-1-andriy.shevchenko@linux.intel.com
Headers show
Series pinctrl: intel: Get rid of ifdeffery leftovers | expand

Message

Andy Shevchenko Sept. 3, 2024, 5:04 p.m. UTC
There are two benefits of this series:
1) no more ugly ifdeffery in the code;
2) the PM callbacks are all being synchronised via using the same macro,
i.e. pm_sleep_ptr() everywhere.

Andy Shevchenko (3):
  pinctrl: intel: Replace ifdeffery by pm_sleep_ptr() macro
  pinctrl: baytrail: Replace ifdeffery by pm_sleep_ptr() macro
  pinctrl: cherryview: Replace ifdeffery by pm_sleep_ptr() macro

 drivers/pinctrl/intel/pinctrl-baytrail.c   | 21 ++++++++++++++-------
 drivers/pinctrl/intel/pinctrl-cherryview.c | 20 +++++++++++++-------
 drivers/pinctrl/intel/pinctrl-intel.c      |  5 +----
 3 files changed, 28 insertions(+), 18 deletions(-)

Comments

Andy Shevchenko Sept. 4, 2024, 7:47 a.m. UTC | #1
On Wed, Sep 4, 2024 at 8:05 AM Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
> On Tue, Sep 03, 2024 at 08:04:49PM +0300, Andy Shevchenko wrote:
> > Explicit ifdeffery is ugly and theoretically might be not synchronised
> > with the rest of functions that are assigned via pm_sleep_ptr() macro.
> > Replace ifdeffery by pm_sleep_ptr() macro to improve this.

...

> Can't we make this a stub when !PM_SLEEP?
>
> #ifdef CONFIG_PM_SLEEP
> static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)
> {
> ...
> }
> #else
> static inline int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)
> {
>         return 0;
> }
> #endif

There is no benefit. It's actually the opposite, i.e. it expands more ifdeffery.

...

> > -     ret = intel_pinctrl_pm_init(pctrl);
> > +     ret = pm_sleep_ptr(intel_pinctrl_pm_init) ? intel_pinctrl_pm_init(pctrl) : 0;
>
> Then this still looks like a function call and not like some weird
> conditional.

I understand that, but the point is to make all PM callbacks use the
same approach against kernel configuration. Current state of affairs
is simple inconsistency, but it might, however quite unlikely, lead to
desynchronization between two pm_sleep_ptr() and ifdeffery approaches.

Approach that I have before this one (and I kinda agree that ternary
here looks a bit weird) is to typedef the function and do something
like

pinctrl-intel.h:

typedef alloc_fn;

static inline int ctx_alloc(pctrl, alloc_fn)
{
  if (alloc_fn)
    return alloc_fn(pctrl);

  return 0;
}

pinctrl-intel.c:

  ret = ctx_alloc(pctrl, pm_sleep_ptr(_pm_init))
  if (ret)
    return ret;

Altogether it will be ~20+ LoCs in addition to the current codebase.