From patchwork Thu Apr 8 20:58:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 417726 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B30BC433B4 for ; Thu, 8 Apr 2021 21:10:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED7E6611AD for ; Thu, 8 Apr 2021 21:10:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232327AbhDHVKN (ORCPT ); Thu, 8 Apr 2021 17:10:13 -0400 Received: from condef-06.nifty.com ([202.248.20.71]:26702 "EHLO condef-06.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbhDHVKN (ORCPT ); Thu, 8 Apr 2021 17:10:13 -0400 Received: from conuserg-09.nifty.com ([10.126.8.72])by condef-06.nifty.com with ESMTP id 138KxkNo002647 for ; Fri, 9 Apr 2021 05:59:46 +0900 Received: from localhost.localdomain (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-09.nifty.com with ESMTP id 138Kx470002644; Fri, 9 Apr 2021 05:59:05 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com 138Kx470002644 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1617915545; bh=li+MZgWK1zbowIjt4vew6oW8eQO9xUf7NDfIE5qrd/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q6tCSszvXF5B4p66VXsQCP5aJi+AyC6AWK4jGea6kk9qDk0GZaiZqfo5IjJrb8kA6 INS3rY66896AlpYPyNfK7Utz082+29QzhOABzalEBnsiyqV1SjqzpIgPQPmUE733/g DSJZpI//Vy0TSTxlY0Swgzms2LEkEo3qw75xVDIPsnOrUi/lMkR8DX8kClRlHHkwSB VzbtXIVtG+hwjah7iLN0a+JaqmlqN5N8oP4TBVSbkjx+alwsVV2SB2SJY4cUswNny8 3dw4EqaZ06dQ1Ur3bi4/74FaQa9pBAHA8WF0yNe0+jmy0k9ExPyWsadNC5T5WOqFpJ VtG7bRRNu/+Qg== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-gpio@vger.kernel.org, Arnd Bergmann , Paul Cercueil , Masahiro Yamada , Linus Walleij , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org Subject: [PATCH 1/2] linux/kconfig.h: replace IF_ENABLED() with PTR_IF() in Date: Fri, 9 Apr 2021 05:58:57 +0900 Message-Id: <20210408205858.51751-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210408205858.51751-1-masahiroy@kernel.org> References: <20210408205858.51751-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org is included from all the kernel-space source files, including C, assembly, linker scripts. It is intended to contain minimal set of macros to evaluate CONFIG options. IF_ENABLED() is an intruder here because (x ? y : z) is C code, which should not be included from assembly files or linker scripts. Also, is no longer self-contained because NULL is defined in . Move IF_ENABLED() out to as PTR_IF(). PTR_IF(IS_ENABLED(CONFIG_FOO), ...) is slightly longer than IF_ENABLED(CONFIG_FOO, ...), but it is not a big deal because sub-systems often define dedicated macros such as of_match_ptr(), pm_ptr() etc. for common use-cases. Signed-off-by: Masahiro Yamada --- drivers/pinctrl/pinctrl-ingenic.c | 20 ++++++++++---------- include/linux/kconfig.h | 6 ------ include/linux/kernel.h | 2 ++ 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/pinctrl/pinctrl-ingenic.c b/drivers/pinctrl/pinctrl-ingenic.c index f2746125b077..b21e2ae4528d 100644 --- a/drivers/pinctrl/pinctrl-ingenic.c +++ b/drivers/pinctrl/pinctrl-ingenic.c @@ -2496,43 +2496,43 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev) static const struct of_device_id ingenic_pinctrl_of_match[] = { { .compatible = "ingenic,jz4740-pinctrl", - .data = IF_ENABLED(CONFIG_MACH_JZ4740, &jz4740_chip_info) + .data = PTR_IF(IS_ENABLED(CONFIG_MACH_JZ4740), &jz4740_chip_info) }, { .compatible = "ingenic,jz4725b-pinctrl", - .data = IF_ENABLED(CONFIG_MACH_JZ4725B, &jz4725b_chip_info) + .data = PTR_IF(IS_ENABLED(CONFIG_MACH_JZ4725B), &jz4725b_chip_info) }, { .compatible = "ingenic,jz4760-pinctrl", - .data = IF_ENABLED(CONFIG_MACH_JZ4760, &jz4760_chip_info) + .data = PTR_IF(IS_ENABLED(CONFIG_MACH_JZ4760), &jz4760_chip_info) }, { .compatible = "ingenic,jz4760b-pinctrl", - .data = IF_ENABLED(CONFIG_MACH_JZ4760, &jz4760_chip_info) + .data = PTR_IF(IS_ENABLED(CONFIG_MACH_JZ4760), &jz4760_chip_info) }, { .compatible = "ingenic,jz4770-pinctrl", - .data = IF_ENABLED(CONFIG_MACH_JZ4770, &jz4770_chip_info) + .data = PTR_IF(IS_ENABLED(CONFIG_MACH_JZ4770), &jz4770_chip_info) }, { .compatible = "ingenic,jz4780-pinctrl", - .data = IF_ENABLED(CONFIG_MACH_JZ4780, &jz4780_chip_info) + .data = PTR_IF(IS_ENABLED(CONFIG_MACH_JZ4780), &jz4780_chip_info) }, { .compatible = "ingenic,x1000-pinctrl", - .data = IF_ENABLED(CONFIG_MACH_X1000, &x1000_chip_info) + .data = PTR_IF(IS_ENABLED(CONFIG_MACH_X1000), &x1000_chip_info) }, { .compatible = "ingenic,x1000e-pinctrl", - .data = IF_ENABLED(CONFIG_MACH_X1000, &x1000_chip_info) + .data = PTR_IF(IS_ENABLED(CONFIG_MACH_X1000), &x1000_chip_info) }, { .compatible = "ingenic,x1500-pinctrl", - .data = IF_ENABLED(CONFIG_MACH_X1500, &x1500_chip_info) + .data = PTR_IF(IS_ENABLED(CONFIG_MACH_X1500), &x1500_chip_info) }, { .compatible = "ingenic,x1830-pinctrl", - .data = IF_ENABLED(CONFIG_MACH_X1830, &x1830_chip_info) + .data = PTR_IF(IS_ENABLED(CONFIG_MACH_X1830), &x1830_chip_info) }, { /* sentinel */ }, }; diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h index 24a59cb06963..cc8fa109cfa3 100644 --- a/include/linux/kconfig.h +++ b/include/linux/kconfig.h @@ -70,10 +70,4 @@ */ #define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option)) -/* - * IF_ENABLED(CONFIG_FOO, ptr) evaluates to (ptr) if CONFIG_FOO is set to 'y' - * or 'm', NULL otherwise. - */ -#define IF_ENABLED(option, ptr) (IS_ENABLED(option) ? (ptr) : NULL) - #endif /* __LINUX_KCONFIG_H */ diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 5b7ed6dc99ac..8685ca4cf287 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -38,6 +38,8 @@ #define PTR_ALIGN_DOWN(p, a) ((typeof(p))ALIGN_DOWN((unsigned long)(p), (a))) #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) +#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) + /* generic data direction definitions */ #define READ 0 #define WRITE 1 From patchwork Thu Apr 8 20:58:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 417727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE5D3C433B4 for ; Thu, 8 Apr 2021 21:01:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88D5561179 for ; Thu, 8 Apr 2021 21:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232373AbhDHVCD (ORCPT ); Thu, 8 Apr 2021 17:02:03 -0400 Received: from condef-02.nifty.com ([202.248.20.67]:36740 "EHLO condef-02.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232345AbhDHVCC (ORCPT ); Thu, 8 Apr 2021 17:02:02 -0400 Received: from conuserg-09.nifty.com ([10.126.8.72])by condef-02.nifty.com with ESMTP id 138KxvMA004966; Fri, 9 Apr 2021 05:59:57 +0900 Received: from localhost.localdomain (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-09.nifty.com with ESMTP id 138Kx471002644; Fri, 9 Apr 2021 05:59:06 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com 138Kx471002644 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1617915546; bh=piA+8z078kwb/KfPJ/8L0g75CBWXThZTe0VPYso6g/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E65GbUOUKULlL/mKzA0AVQ65w88zN1o5uif53wxAmxGkhdZqItC49y4rWkJOjItNJ tLVX6tAyd6DCAdOQi4Q9iODqSvyhaZpq1G3MGyCAqWx9BS7IxNeVuPI52RwF/I1mKM +0V0UVCeASxlppgX6piANkaMLhn4EPqvs4OyKv+2eE8tUq2MLgR84FxMdKuVYsh+fS OocOwD5+NGyVq5Oz29d3cGRt56StEw9e0mB4RldDJE5kU0GuJmHDbWYmjsMzuVJPyR WcNIsANqTZ2NaqQ7xrAM3Z36qfPcbMNMYisubExgEllrLizap3fossetR+MCScZVMA MLPM5V2rgSV5g== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-gpio@vger.kernel.org, Arnd Bergmann , Paul Cercueil , Masahiro Yamada , Len Brown , Pavel Machek , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 2/2] pm: allow drivers to drop #ifdef and __maybe_unused from pm callbacks Date: Fri, 9 Apr 2021 05:58:58 +0900 Message-Id: <20210408205858.51751-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210408205858.51751-1-masahiroy@kernel.org> References: <20210408205858.51751-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Drivers typically surround suspend and resume callbacks with #ifdef CONFIG_PM(_SLEEP) or mark them as __maybe_unused in order to avoid -Wunused-const-variable warnings. With this commit, drivers will be able to remove #ifdef CONFIG_PM(_SLEEP) and __maybe_unsed because unused functions are dropped by the compiler instead of the preprocessor. Signed-off-by: Masahiro Yamada Reported-by: kernel test robot --- include/linux/pm.h | 67 +++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 43 deletions(-) diff --git a/include/linux/pm.h b/include/linux/pm.h index 482313a8ccfc..ca764566692a 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -301,50 +301,37 @@ struct dev_pm_ops { int (*runtime_idle)(struct device *dev); }; -#ifdef CONFIG_PM_SLEEP +#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), _ptr) +#define pm_sleep_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM_SLEEP), _ptr) + #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ - .suspend = suspend_fn, \ - .resume = resume_fn, \ - .freeze = suspend_fn, \ - .thaw = resume_fn, \ - .poweroff = suspend_fn, \ - .restore = resume_fn, -#else -#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) -#endif + .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), -#ifdef CONFIG_PM_SLEEP #define SET_LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ - .suspend_late = suspend_fn, \ - .resume_early = resume_fn, \ - .freeze_late = suspend_fn, \ - .thaw_early = resume_fn, \ - .poweroff_late = suspend_fn, \ - .restore_early = resume_fn, -#else -#define SET_LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) -#endif + .suspend_late = pm_sleep_ptr(suspend_fn), \ + .resume_early = pm_sleep_ptr(resume_fn), \ + .freeze_late = pm_sleep_ptr(suspend_fn), \ + .thaw_early = pm_sleep_ptr(resume_fn), \ + .poweroff_late = pm_sleep_ptr(suspend_fn), \ + .restore_early = pm_sleep_ptr(resume_fn), -#ifdef CONFIG_PM_SLEEP #define SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ - .suspend_noirq = suspend_fn, \ - .resume_noirq = resume_fn, \ - .freeze_noirq = suspend_fn, \ - .thaw_noirq = resume_fn, \ - .poweroff_noirq = suspend_fn, \ - .restore_noirq = resume_fn, -#else -#define SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) -#endif + .suspend_noirq = pm_sleep_ptr(suspend_fn), \ + .resume_noirq = pm_sleep_ptr(resume_fn), \ + .freeze_noirq = pm_sleep_ptr(suspend_fn), \ + .thaw_noirq = pm_sleep_ptr(resume_fn), \ + .poweroff_noirq = pm_sleep_ptr(suspend_fn), \ + .restore_noirq = pm_sleep_ptr(resume_fn), -#ifdef CONFIG_PM #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \ - .runtime_suspend = suspend_fn, \ - .runtime_resume = resume_fn, \ - .runtime_idle = idle_fn, -#else -#define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) -#endif + .runtime_suspend = pm_ptr(suspend_fn), \ + .runtime_resume = pm_ptr(resume_fn), \ + .runtime_idle = pm_ptr(idle_fn), /* * Use this if you want to use the same suspend and resume callbacks for suspend @@ -374,12 +361,6 @@ 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 - /* * PM_EVENT_ messages *