Re: [PATCH 3/8] watchdog: mtk_wdt: Remove #ifdef guards for PM related functions

From: Guenter Roeck
Date: Tue Jun 28 2022 - 16:12:24 EST


On Tue, Jun 28, 2022 at 08:34:44PM +0100, Paul Cercueil wrote:
> Use the new DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr() macros to
> handle the .suspend/.resume callbacks.
>
> These macros allow the suspend and resume functions to be automatically
> dropped by the compiler when CONFIG_SUSPEND is disabled, without having
> to use #ifdef guards. Not using #ifdef guards means that the code is
> always compiled independently of any Kconfig option, and thanks to that
> bugs and regressions are easier to catch.
>
> Signed-off-by: Paul Cercueil <paul@xxxxxxxxxxxxxxx>
> Cc: Matthias Brugger <matthias.bgg@xxxxxxxxx>
> Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> Cc: linux-mediatek@xxxxxxxxxxxxxxxxxxx

Reviewed-by: Guenter Roeck <linux@xxxxxxxxxxxx>

> ---
> drivers/watchdog/mtk_wdt.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/watchdog/mtk_wdt.c b/drivers/watchdog/mtk_wdt.c
> index f0d4e3cc7459..e97787536792 100644
> --- a/drivers/watchdog/mtk_wdt.c
> +++ b/drivers/watchdog/mtk_wdt.c
> @@ -401,7 +401,6 @@ static int mtk_wdt_probe(struct platform_device *pdev)
> return 0;
> }
>
> -#ifdef CONFIG_PM_SLEEP
> static int mtk_wdt_suspend(struct device *dev)
> {
> struct mtk_wdt_dev *mtk_wdt = dev_get_drvdata(dev);
> @@ -423,7 +422,6 @@ static int mtk_wdt_resume(struct device *dev)
>
> return 0;
> }
> -#endif
>
> static const struct of_device_id mtk_wdt_dt_ids[] = {
> { .compatible = "mediatek,mt2712-wdt", .data = &mt2712_data },
> @@ -437,16 +435,14 @@ static const struct of_device_id mtk_wdt_dt_ids[] = {
> };
> MODULE_DEVICE_TABLE(of, mtk_wdt_dt_ids);
>
> -static const struct dev_pm_ops mtk_wdt_pm_ops = {
> - SET_SYSTEM_SLEEP_PM_OPS(mtk_wdt_suspend,
> - mtk_wdt_resume)
> -};
> +static DEFINE_SIMPLE_DEV_PM_OPS(mtk_wdt_pm_ops,
> + mtk_wdt_suspend, mtk_wdt_resume);
>
> static struct platform_driver mtk_wdt_driver = {
> .probe = mtk_wdt_probe,
> .driver = {
> .name = DRV_NAME,
> - .pm = &mtk_wdt_pm_ops,
> + .pm = pm_sleep_ptr(&mtk_wdt_pm_ops),
> .of_match_table = mtk_wdt_dt_ids,
> },
> };
> --
> 2.35.1
>