From patchwork Tue Dec 8 16:48:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 11959069 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=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 55FCAC4167B for ; Tue, 8 Dec 2020 16:50:05 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 07AAE23A79 for ; Tue, 8 Dec 2020 16:50:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07AAE23A79 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=crapouillou.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=PP48JvSo7/hD9kvxzOhQ3MCkliJsWrW/dD6Pr4soeHY=; b=ZU/5x7jbFDoRgZM3v5SlabQ5Uc Ejpb93K6VYYrEXTq8g1MmUkgyAC5vTBq8k0i+1giZ4Jns8l18iTLSJQJMpRyoi/wY59DL5eqhiKbw iivLdB23moYWTIRerDsH9DmEJiPTGf7qvsZKGLJbuaYWo0ZeAr70n0grFiE0XSSnoGGGr1uZulDFQ +AGmsOYn6TNIixuu9ukBKfgjP7DOTgKdE65pTIaURYaiHb+AAdzbnlfJKZYanDk1Hqvya5qdxBoVc 6GVvGNdK/CXHiTVMZpm5DatdEVWaeC+FokqsOcfuK3C1/5qsMGKYvLlhvlEF+nNibGEPO2cfltRfY qAs6NjbQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmgAY-0006rK-CV; Tue, 08 Dec 2020 16:48:54 +0000 Received: from aposti.net ([89.234.176.197]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmgAV-0006qA-O9 for linux-arm-kernel@lists.infradead.org; Tue, 08 Dec 2020 16:48:52 +0000 From: Paul Cercueil To: Linus Walleij Subject: [PATCH 1/2] if_enabled.h: Add IF_ENABLED_OR_ELSE() and IF_ENABLED() macros Date: Tue, 8 Dec 2020 16:48:20 +0000 Message-Id: <20201208164821.2686082-1-paul@crapouillou.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201208_114851_905829_269DB479 X-CRM114-Status: GOOD ( 18.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil , od@zcrc.me, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce a new header , that brings two new macros: IF_ENABLED_OR_ELSE() and IF_ENABLED(). IF_ENABLED_OR_ELSE(CONFIG_FOO, a, b) evaluates to (a) if CONFIG_FOO is set to 'y' or 'm', (b) otherwise. It is used internally to define the IF_ENABLED() macro. The (a) and (b) arguments must be of the same type. IF_ENABLED(CONFIG_FOO, ptr) evaluates to (ptr) if CONFIG_FOO is set to 'y' or 'm', NULL otherwise. The (ptr) argument must be a pointer. The IF_ENABLED() macro can be very useful to help GCC drop dead code. For instance, consider the following: #ifdef CONFIG_FOO_SUSPEND static int foo_suspend(struct device *dev) { ... } #endif static struct pm_ops foo_ops = { #ifdef CONFIG_FOO_SUSPEND .suspend = foo_suspend, #endif }; While this works, the foo_suspend() macro is compiled conditionally, only when CONFIG_FOO_SUSPEND is set. This is problematic, as there could be a build bug in this function, we wouldn't have a way to know unless the config option is set. An alternative is to declare foo_suspend() always, but mark it as maybe unused: static int __maybe_unused foo_suspend(struct device *dev) { ... } static struct pm_ops foo_ops = { #ifdef CONFIG_FOO_SUSPEND .suspend = foo_suspend, #endif }; Again, this works, but the __maybe_unused attribute is required to instruct the compiler that the function may not be referenced anywhere, and is safe to remove without making a fuss about it. This makes the programmer responsible for tagging the functions that can be garbage-collected. With this patch, it is now possible to write the following: static int foo_suspend(struct device *dev) { ... } static struct pm_ops foo_ops = { .suspend = IF_ENABLED(CONFIG_FOO_SUSPEND, foo_suspend), }; The foo_suspend() function will now be automatically dropped by the compiler, and it does not require any specific attribute. Signed-off-by: Paul Cercueil --- include/linux/if_enabled.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 include/linux/if_enabled.h diff --git a/include/linux/if_enabled.h b/include/linux/if_enabled.h new file mode 100644 index 000000000000..8189d1402340 --- /dev/null +++ b/include/linux/if_enabled.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_IF_ENABLED_H +#define __LINUX_IF_ENABLED_H + +#include +#include +#include + +/* + * IF_ENABLED_OR_ELSE(CONFIG_FOO, a, b) evaluates to (a) if CONFIG_FOO is set + * to 'y' or 'm', (b) otherwise. + */ +#define IF_ENABLED_OR_ELSE(option, a, b) \ + (BUILD_BUG_ON_ZERO(__same_type((a), (b))) || IS_ENABLED(option) ? (a) : (b)) + +/* + * IF_ENABLED(CONFIG_FOO, ptr) evaluates to (ptr) if CONFIG_FOO is set to 'y' + * or 'm', NULL otherwise. + */ +#define IF_ENABLED(option, ptr) IF_ENABLED_OR_ELSE(option, ptr, NULL) + +#endif /* __LINUX_IF_ENABLED_H */ From patchwork Tue Dec 8 16:48:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 11959071 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=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 05727C4361B for ; Tue, 8 Dec 2020 16:50:16 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9DDE023A79 for ; Tue, 8 Dec 2020 16:50:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9DDE023A79 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=crapouillou.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1oPLHavTdljCUA39st82QfH+5Ksm6ni0dzYc6rpoefo=; b=yinkeRCT7OSh+m/4Q4TwpZQpU NrpOBI1M9e6a1pr4KfohoKY44BU1D0qJKNZOPiuAuQBzeTUm/6FRym/3gC8CsAK3bLE+OM5fquwxe XH0NHEd9e9O10asrI9pZWdY68YmCmyG3J+gpjIKATIJYDQLKqurzR+T86BoBU2D0HJ0T+yOUGOTNq bsI9/8HYHDuD7QFv6zslizMmY+BvJVPA3iyDDbFymtFWAcAPyL+XpkuRjB/JyIReahfTLmJLc0xH7 5667covLJY3/5zpxB2eUWmnAUHNuvsIE9zFh+rbE2FhpURJ3PGUBbt6J7RLF/ZFofX4nFKzbiFEM2 IAGSwh/5g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmgAh-0006tn-PJ; Tue, 08 Dec 2020 16:49:03 +0000 Received: from aposti.net ([89.234.176.197]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmgAe-0006sp-SY for linux-arm-kernel@lists.infradead.org; Tue, 08 Dec 2020 16:49:01 +0000 From: Paul Cercueil To: Linus Walleij Subject: [PATCH 2/2] pinctrl: ingenic: Only support SoCs enabled in config Date: Tue, 8 Dec 2020 16:48:21 +0000 Message-Id: <20201208164821.2686082-2-paul@crapouillou.net> In-Reply-To: <20201208164821.2686082-1-paul@crapouillou.net> References: <20201208164821.2686082-1-paul@crapouillou.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201208_114901_129161_044B440B X-CRM114-Status: GOOD ( 13.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil , od@zcrc.me, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Tested on a JZ4740 system (ARCH=mips make qi_lb60_defconfig), this saves about 14 KiB, by allowing the compiler to garbage-collect all the functions and tables that correspond to SoCs that were disabled in the config. Signed-off-by: Paul Cercueil --- drivers/pinctrl/pinctrl-ingenic.c | 61 +++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/drivers/pinctrl/pinctrl-ingenic.c b/drivers/pinctrl/pinctrl-ingenic.c index a14938a7cc30..11f1bc90632d 100644 --- a/drivers/pinctrl/pinctrl-ingenic.c +++ b/drivers/pinctrl/pinctrl-ingenic.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -2384,6 +2385,12 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev) unsigned int i; int err; + chip_info = of_device_get_match_data(dev); + if (!chip_info) { + dev_err(dev, "Unsupported SoC\n"); + return -EINVAL; + } + jzpc = devm_kzalloc(dev, sizeof(*jzpc), GFP_KERNEL); if (!jzpc) return -ENOMEM; @@ -2400,7 +2407,7 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev) } jzpc->dev = dev; - jzpc->info = chip_info = of_device_get_match_data(dev); + jzpc->info = chip_info; pctl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctl_desc), GFP_KERNEL); if (!pctl_desc) @@ -2470,17 +2477,47 @@ 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 = &jz4740_chip_info }, - { .compatible = "ingenic,jz4725b-pinctrl", .data = &jz4725b_chip_info }, - { .compatible = "ingenic,jz4760-pinctrl", .data = &jz4760_chip_info }, - { .compatible = "ingenic,jz4760b-pinctrl", .data = &jz4760_chip_info }, - { .compatible = "ingenic,jz4770-pinctrl", .data = &jz4770_chip_info }, - { .compatible = "ingenic,jz4780-pinctrl", .data = &jz4780_chip_info }, - { .compatible = "ingenic,x1000-pinctrl", .data = &x1000_chip_info }, - { .compatible = "ingenic,x1000e-pinctrl", .data = &x1000_chip_info }, - { .compatible = "ingenic,x1500-pinctrl", .data = &x1500_chip_info }, - { .compatible = "ingenic,x1830-pinctrl", .data = &x1830_chip_info }, - {}, + { + .compatible = "ingenic,jz4740-pinctrl", + .data = IF_ENABLED(CONFIG_MACH_JZ4740, &jz4740_chip_info) + }, + { + .compatible = "ingenic,jz4725b-pinctrl", + .data = IF_ENABLED(CONFIG_MACH_JZ4725B, &jz4725b_chip_info) + }, + { + .compatible = "ingenic,jz4760-pinctrl", + .data = IF_ENABLED(CONFIG_MACH_JZ4760, &jz4760_chip_info) + }, + { + .compatible = "ingenic,jz4760b-pinctrl", + .data = IF_ENABLED(CONFIG_MACH_JZ4760, &jz4760_chip_info) + }, + { + .compatible = "ingenic,jz4770-pinctrl", + .data = IF_ENABLED(CONFIG_MACH_JZ4770, &jz4770_chip_info) + }, + { + .compatible = "ingenic,jz4780-pinctrl", + .data = IF_ENABLED(CONFIG_MACH_JZ4780, &jz4780_chip_info) + }, + { + .compatible = "ingenic,x1000-pinctrl", + .data = IF_ENABLED(CONFIG_MACH_X1000, &x1000_chip_info) + }, + { + .compatible = "ingenic,x1000e-pinctrl", + .data = IF_ENABLED(CONFIG_MACH_X1000, &x1000_chip_info) + }, + { + .compatible = "ingenic,x1500-pinctrl", + .data = IF_ENABLED(CONFIG_MACH_X1500, &x1500_chip_info) + }, + { + .compatible = "ingenic,x1830-pinctrl", + .data = IF_ENABLED(CONFIG_MACH_X1830, &x1830_chip_info) + }, + { /* sentinel */ }, }; static struct platform_driver ingenic_pinctrl_driver = {