linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Paul Cercueil <paul@crapouillou.net>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
	Pavel Machek <pavel@ucw.cz>, Len Brown <len.brown@intel.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Arnd Bergmann <arnd@arndb.de>,
	list@opendingux.net, linux-mips@vger.kernel.org,
	linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH 2/5] PM: core: Redefine pm_ptr() macro
Date: Thu, 16 Dec 2021 11:10:21 +0000	[thread overview]
Message-ID: <20211216111021.7b3eaada@jic23-huawei> (raw)
In-Reply-To: <20211207002102.26414-3-paul@crapouillou.net>

On Tue,  7 Dec 2021 00:20:59 +0000
Paul Cercueil <paul@crapouillou.net> wrote:

> The pm_ptr() macro was previously conditionally defined, according to
> the value of the CONFIG_PM option. This meant that the pointed structure
> was either referenced (if CONFIG_PM was set), or never referenced (if
> CONFIG_PM was not set), causing it to be detected as unused by the
> compiler.
> 
> This worked fine, but required the __maybe_unused compiler attribute to
> be used to every symbol pointed to by a pointer wrapped with pm_ptr().
> 
> We can do better. With this change, the pm_ptr() is now defined the
> same, independently of the value of CONFIG_PM. It now uses the (?:)
> ternary operator to conditionally resolve to its argument. Since the
> condition is known at compile time, the compiler will then choose to
> discard the unused symbols, which won't need to be tagged with
> __maybe_unused anymore.
> 
> This pm_ptr() macro is usually used with pointers to dev_pm_ops
> structures created with SIMPLE_DEV_PM_OPS() or similar macros. These do
> use a __maybe_unused flag, which is now useless with this change, so it
> later can be removed. However in the meantime it causes no harm, and all
> the drivers still compile fine with the new pm_ptr() macro.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  include/linux/pm.h | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index 1d8209c09686..b88ac7dcf2a2 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -373,11 +373,7 @@ const struct dev_pm_ops __maybe_unused name = { \
>  	SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
>  }
>  
> -#ifdef CONFIG_PM
> -#define pm_ptr(_ptr) (_ptr)
> -#else
> -#define pm_ptr(_ptr) NULL
> -#endif
> +#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), (_ptr))
>  
>  /*
>   * PM_EVENT_ messages


  reply	other threads:[~2021-12-16 11:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-07  0:20 [PATCH 0/5] Rework pm_ptr() and *_PM_OPS macros Paul Cercueil
2021-12-07  0:20 ` [PATCH 1/5] r8169: Avoid misuse of pm_ptr() macro Paul Cercueil
2021-12-07  0:20 ` [PATCH 2/5] PM: core: Redefine " Paul Cercueil
2021-12-16 11:10   ` Jonathan Cameron [this message]
2021-12-07  0:21 ` [PATCH 3/5] PM: core: Add new *_PM_OPS macros, deprecate old ones Paul Cercueil
2021-12-16 11:09   ` Jonathan Cameron
2021-12-07  0:21 ` [PATCH 4/5] mmc: jz4740: Use the new PM macros Paul Cercueil
2021-12-07  0:21 ` [PATCH 5/5] mmc: mxc: " Paul Cercueil
2021-12-07  9:22 ` [PATCH 0/5] Rework pm_ptr() and *_PM_OPS macros Arnd Bergmann
2021-12-17 15:07   ` Rafael J. Wysocki
2021-12-17 17:16     ` Ulf Hansson
2021-12-17 18:22       ` Rafael J. Wysocki

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=20211216111021.7b3eaada@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=arnd@arndb.de \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=list@opendingux.net \
    --cc=netdev@vger.kernel.org \
    --cc=paul@crapouillou.net \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    --cc=ulf.hansson@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).