[PATCH] mmc: core: Switch to use pm_ptr() for mmc_host_class_dev_pm_ops

Shawn Lin posted 1 patch 6 days, 11 hours ago
drivers/mmc/core/host.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
[PATCH] mmc: core: Switch to use pm_ptr() for mmc_host_class_dev_pm_ops
Posted by Shawn Lin 6 days, 11 hours ago
Currently, the mmc_host_class_dev_pm_ops and its callback
functions are wrapped in #ifdef CONFIG_PM_SLEEP to handle the
conditional compilation when PM support is disabled.

Replace this #ifdef usage with the standard pm_ptr() helpers. This
allows the compiler to automatically optimize away the unused code
paths when CONFIG_PM_SLEEP is not selected, resulting in cleaner and
more maintainable code.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 drivers/mmc/core/host.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 4e1514b..b7ce313 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -33,7 +33,6 @@
 
 static DEFINE_IDA(mmc_host_ida);
 
-#ifdef CONFIG_PM_SLEEP
 static int mmc_host_class_prepare(struct device *dev)
 {
 	struct mmc_host *host = cls_dev_to_mmc_host(dev);
@@ -60,15 +59,10 @@ static void mmc_host_class_complete(struct device *dev)
 }
 
 static const struct dev_pm_ops mmc_host_class_dev_pm_ops = {
-	.prepare = mmc_host_class_prepare,
-	.complete = mmc_host_class_complete,
+	.prepare = pm_sleep_ptr(mmc_host_class_prepare),
+	.complete = pm_sleep_ptr(mmc_host_class_complete),
 };
 
-#define MMC_HOST_CLASS_DEV_PM_OPS (&mmc_host_class_dev_pm_ops)
-#else
-#define MMC_HOST_CLASS_DEV_PM_OPS NULL
-#endif
-
 static void mmc_host_classdev_release(struct device *dev)
 {
 	struct mmc_host *host = cls_dev_to_mmc_host(dev);
@@ -90,7 +84,7 @@ static const struct class mmc_host_class = {
 	.name		= "mmc_host",
 	.dev_release	= mmc_host_classdev_release,
 	.shutdown_pre	= mmc_host_classdev_shutdown,
-	.pm		= MMC_HOST_CLASS_DEV_PM_OPS,
+	.pm		= pm_ptr(&mmc_host_class_dev_pm_ops),
 };
 
 int mmc_register_host_class(void)
-- 
2.7.4
Re: [PATCH] mmc: core: Switch to use pm_ptr() for mmc_host_class_dev_pm_ops
Posted by Ulf Hansson 6 days, 6 hours ago
On Fri, 27 Mar 2026 at 05:11, Shawn Lin <shawn.lin@rock-chips.com> wrote:
>
> Currently, the mmc_host_class_dev_pm_ops and its callback
> functions are wrapped in #ifdef CONFIG_PM_SLEEP to handle the
> conditional compilation when PM support is disabled.
>
> Replace this #ifdef usage with the standard pm_ptr() helpers. This
> allows the compiler to automatically optimize away the unused code
> paths when CONFIG_PM_SLEEP is not selected, resulting in cleaner and
> more maintainable code.
>
> Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>

Applied for next, thanks!

Kind regards
Uffe


> ---
>
>  drivers/mmc/core/host.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
> index 4e1514b..b7ce313 100644
> --- a/drivers/mmc/core/host.c
> +++ b/drivers/mmc/core/host.c
> @@ -33,7 +33,6 @@
>
>  static DEFINE_IDA(mmc_host_ida);
>
> -#ifdef CONFIG_PM_SLEEP
>  static int mmc_host_class_prepare(struct device *dev)
>  {
>         struct mmc_host *host = cls_dev_to_mmc_host(dev);
> @@ -60,15 +59,10 @@ static void mmc_host_class_complete(struct device *dev)
>  }
>
>  static const struct dev_pm_ops mmc_host_class_dev_pm_ops = {
> -       .prepare = mmc_host_class_prepare,
> -       .complete = mmc_host_class_complete,
> +       .prepare = pm_sleep_ptr(mmc_host_class_prepare),
> +       .complete = pm_sleep_ptr(mmc_host_class_complete),
>  };
>
> -#define MMC_HOST_CLASS_DEV_PM_OPS (&mmc_host_class_dev_pm_ops)
> -#else
> -#define MMC_HOST_CLASS_DEV_PM_OPS NULL
> -#endif
> -
>  static void mmc_host_classdev_release(struct device *dev)
>  {
>         struct mmc_host *host = cls_dev_to_mmc_host(dev);
> @@ -90,7 +84,7 @@ static const struct class mmc_host_class = {
>         .name           = "mmc_host",
>         .dev_release    = mmc_host_classdev_release,
>         .shutdown_pre   = mmc_host_classdev_shutdown,
> -       .pm             = MMC_HOST_CLASS_DEV_PM_OPS,
> +       .pm             = pm_ptr(&mmc_host_class_dev_pm_ops),
>  };
>
>  int mmc_register_host_class(void)
> --
> 2.7.4
>