All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: Stephen Zhang <starzhangzsd@gmail.com>
Cc: linux-kernel@vger.kernel.org, zhangshida@kylinos.cn,
	k2ci <kernel-bot@kylinos.cn>
Subject: Re: [PATCH] mfd: cs42l43: fix defined but not used warnings
Date: Thu, 21 Sep 2023 11:37:51 +0100	[thread overview]
Message-ID: <20230921103751.GD3449785@google.com> (raw)
In-Reply-To: <CANubcdVuiBciEQu14hOUvgSYo2+1okQ4ed-tJJa5Xo_3jieGzg@mail.gmail.com>

On Thu, 21 Sep 2023, Stephen Zhang wrote:

> Lee Jones <lee@kernel.org> 于2023年9月20日周三 17:52写道:
> >
> > On Tue, 05 Sep 2023, zhangshida wrote:
> >
> > > From: Shida Zhang <zhangshida@kylinos.cn>
> > >
> > > Warnings were generated during compiling for functions like
> > > cs42l43_*_{resume,suspend}:
> > >
> > > ../drivers/mfd/cs42l43.c:1138:12: error: ‘cs42l43_runtime_resume’ defined but not used [-Werror=unused-function]
> > >  1138 | static int cs42l43_runtime_resume(struct device *dev)
> > >       |            ^~~~~~~~~~~~~~~~~~~~~~
> > > ../drivers/mfd/cs42l43.c:1124:12: error: ‘cs42l43_runtime_suspend’ defined but not used [-Werror=unused-function]
> > >  1124 | static int cs42l43_runtime_suspend(struct device *dev)
> > >       |            ^~~~~~~~~~~~~~~~~~~~~~~
> > > ../drivers/mfd/cs42l43.c:1106:12: error: ‘cs42l43_resume’ defined but not used [-Werror=unused-function]
> > >  1106 | static int cs42l43_resume(struct device *dev)
> > >       |            ^~~~~~~~~~~~~~
> > > ../drivers/mfd/cs42l43.c:1076:12: error: ‘cs42l43_suspend’ defined but not used [-Werror=unused-function]
> > >  1076 | static int cs42l43_suspend(struct device *dev)
> > >
> > > Fix it by guarding it with CONFIG_PM/CONFIG_PM_SLEEP.
> > >
> > > Reported-by: k2ci <kernel-bot@kylinos.cn>
> > > Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
> > > ---
> > >  drivers/mfd/cs42l43.c | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > >
> > > diff --git a/drivers/mfd/cs42l43.c b/drivers/mfd/cs42l43.c
> > > index 37b23e9bae82..e589a61c118d 100644
> > > --- a/drivers/mfd/cs42l43.c
> > > +++ b/drivers/mfd/cs42l43.c
> > > @@ -1073,6 +1073,7 @@ void cs42l43_dev_remove(struct cs42l43 *cs42l43)
> > >  }
> > >  EXPORT_SYMBOL_NS_GPL(cs42l43_dev_remove, MFD_CS42L43);
> > >
> > > +#ifdef CONFIG_PM_SLEEP
> > >  static int cs42l43_suspend(struct device *dev)
> > >  {
> > >       struct cs42l43 *cs42l43 = dev_get_drvdata(dev);
> > > @@ -1120,7 +1121,9 @@ static int cs42l43_resume(struct device *dev)
> > >
> > >       return 0;
> > >  }
> > > +#endif
> > >
> > > +#ifdef CONFIG_PM
> > >  static int cs42l43_runtime_suspend(struct device *dev)
> > >  {
> > >       struct cs42l43 *cs42l43 = dev_get_drvdata(dev);
> > > @@ -1176,6 +1179,7 @@ static int cs42l43_runtime_resume(struct device *dev)
> > >
> > >       return ret;
> > >  }
> > > +#endif
> > >
> > >  EXPORT_NS_GPL_DEV_PM_OPS(cs42l43_pm_ops, MFD_CS42L43) = {
> > >       SET_SYSTEM_SLEEP_PM_OPS(cs42l43_suspend, cs42l43_resume)
> >
> > I see a bunch of drivers using PM helpers and not many of them are
> > are being guarded by ugly #ifery.  Please find out what they're doing to
> > solve the same issue and replicate that instead.
> >
> > Here's a really big hint:
> >
> >   `git log --oneline 02313a90095fb`
> >
> 
> Thanks, I've learned something from the hint.
> 
> And I also checked the code:
> -----
> EXPORT_NS_GPL_DEV_PM_OPS(cs42l43_pm_ops, MFD_CS42L43) = {
>         SET_SYSTEM_SLEEP_PM_OPS(cs42l43_suspend, cs42l43_resume)
>         SET_RUNTIME_PM_OPS(cs42l43_runtime_suspend,
> cs42l43_runtime_resume, NULL)
> };
> ----
> #ifdef CONFIG_PM_SLEEP
> #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
>         SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
> #else
> #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
> #endif
> ----
> #define SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
>         .suspend = pm_sleep_ptr(suspend_fn), \
>         .resume = pm_sleep_ptr(resume_fn), \
>         .freeze = pm_sleep_ptr(suspend_fn), \
>         .thaw = pm_sleep_ptr(resume_fn), \
>         .poweroff = pm_sleep_ptr(suspend_fn), \
>         .restore = pm_sleep_ptr(resume_fn),
> ----
> The technique has already been used by the marcos, but it still
> reports the defined-but-not-used warning.

The MACROS can use #ifery since they are located in header files.

#ifery in C files is to be avoided if at all possible.

> Maybe some compilers still choose to compile these functions in...
> Anyway, I will just leave it alone since it is really not a big problem...

If you're seeing an error, it should be fixed.

Why is this not an issue anywhere else?

Does the same build complain about all the other drivers too?

-- 
Lee Jones [李琼斯]

  reply	other threads:[~2023-09-21 20:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-05  2:12 [PATCH] mfd: cs42l43: fix defined but not used warnings zhangshida
2023-09-20  9:52 ` Lee Jones
2023-09-21  2:46   ` Stephen Zhang
2023-09-21 10:37     ` Lee Jones [this message]
2023-09-22  2:01       ` Stephen Zhang
2023-09-22  7:26   ` Geert Uytterhoeven
2023-09-25  7:56     ` Lee Jones
2023-09-25  8:31       ` Geert Uytterhoeven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230921103751.GD3449785@google.com \
    --to=lee@kernel.org \
    --cc=kernel-bot@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=starzhangzsd@gmail.com \
    --cc=zhangshida@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.