lkml.org 
[lkml]   [2020]   [Dec]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] mmc: mediatek: mark PM functions as __maybe_unused
On Fri, Dec 4, 2020 at 3:38 PM Ulf Hansson <ulf.hansson@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

\
 
 \ /
  Last update: 2020-12-04 15:56    [W:0.109 / U:0.400 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site