[PATCH] mmc: mediatek: mark PM functions as __maybe_unused

Arnd Bergmann arnd at kernel.org
Fri Dec 4 09:55:05 EST 2020


On Fri, Dec 4, 2020 at 3:38 PM Ulf Hansson <ulf.hansson at linaro.org> wrote:
.
> >
> > I don't see a lot of other instances of that yet, and it's fairly new.
> > Maybe we should fix it before it gets propagated further.
> >
> > I would suggest we redefine pm_ptr like
> >
> > #define pm_ptr(_ptr) (IS_ENABLED(CONFIG_PM) ? (_ptr) : NULL)
>
> Why is this better than the original definition?

It tells the compiler that the _ptr is referenced from here, so it does
not warn about an unused symbol, but at the same time it still
knows that it can discard it along with the functions referenced by
it and should not emit any of that output.

> > and remove the __maybe_unused annotations on those that we
> > already have. This also has the effect of dropping the unused
> > data from the object, but without having to an an #ifdef or
> > __maybe_unused.
>
> I didn't quite get this (sorry it's Friday afternoon... getting
> tired), can you perhaps give a concrete example?

These work:

a)
static const struct dev_pm_ops __maybe_unused ops = { ... };
...
      .ops = &ops,
...

b)
static const struct dev_pm_ops ops = { ... };
...
      .ops = &ops,
...

c)
#ifdef CONFIG_PM
static const struct dev_pm_ops ops = { ... };
#endif
...
#ifdef CONFIG_PM
     .ops = ops,
#endif
...

d)
static const struct dev_pm_ops __maybe_unused ops = { ... };
...
#ifdef CONFIG_PM
     .ops = ops,
#endif
...

e)
static const struct dev_pm_ops ops = { ... };
...
     .ops = IS_ENABLED(CONFIG_PM) ? ops : NULL,
...

But these do not work:

f)
#ifdef CONFIG_PM
static const struct dev_pm_ops ops = { ... };
#endif
...
/* error: missing declaration for ops */
     .ops = IS_ENABLED(CONFIG_PM) ? ops : NULL,
...

g)
static struct dev_pm_ops ops = { ... };
...
/* warning: unused variable */
#ifndef CONFIG_PM
     .ops = NULL,
#else
    .ops = ops,
#endif
...

       Arnd



More information about the Linux-mediatek mailing list