From patchwork Fri Jan 18 16:00:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Murray X-Patchwork-Id: 10770755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37A106C5 for ; Fri, 18 Jan 2019 16:01:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 243812EC44 for ; Fri, 18 Jan 2019 16:01:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1638D2F232; Fri, 18 Jan 2019 16:01:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 86FA32EED1 for ; Fri, 18 Jan 2019 16:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=RS3bZ1+0wd6zzvh96SG0fQXlyYUbe/336OJ9Tbqqu+8=; b=RvP OiHz3qnHaBewpF7WgnFPW6QssCICFFfca5k3f6GEFQLaJFNWFCZwGNOhQW485MP2sjicbFjqfK0TX 3jCYECMyGumORshI8YKLYWcXLuUTRxJLjMORXXMjLvNsi6YrER5S0unW+5FpQcrkouoBh6xYbo5HY 7HEZ+0K9B3LDkQwPV4D0gVohd3KnpBT9pKSceH51PNcVs5Chi0KkZph4LsrhDm+jP3tpJm8pf882x 1m2scYnUaxCyXyyOik6e/8juXlyOgGW5zdTrAFb+fnEkfYeudPIAmhwf6it0w6JianNNtAMMiKNvd 8QpUf5hwCJ5kZqEbaQqDQThg/I0mf7A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkWaF-0006Rn-40; Fri, 18 Jan 2019 16:01:27 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkWZU-0006PJ-0i for linux-arm-kernel@lists.infradead.org; Fri, 18 Jan 2019 16:00:42 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 60AE9EBD; Fri, 18 Jan 2019 08:00:39 -0800 (PST) Received: from e119886-lin.cambridge.arm.com (unknown [10.37.6.11]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C14D63F557; Fri, 18 Jan 2019 08:00:36 -0800 (PST) From: Andrew Murray To: Masahiro Yamada , Arnd Bergmann , Kees Cook , Andrew Morton Subject: [Linux-eng] [RFC 0/3] Abstract empty functions with STUB_UNLESS macro Date: Fri, 18 Jan 2019 16:00:27 +0000 Message-Id: <1547827230-55132-1-git-send-email-andrew.murray@arm.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190118_080040_064627_CE1ED937 X-CRM114-Status: UNSURE ( 9.96 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: rjw@rjwysocki.net, Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, Steven Price , Grant Likely , Dave P Martin , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP A common pattern found in header files is a function declaration dependent on a CONFIG_ option being enabled, followed by an empty function for when that option isn't enabled. This boilerplate code can often take up a lot of space and impact code readability. This series introduces a STUB_UNLESS macro that simplifies header files as follows: STUB_UNLESS(CONFIG_FOO, [body], prototype) This evaluates to 'prototype' prepended with 'extern' if CONFIG_FOO is set to 'y'. Otherwise it will evaluate to 'prototype' prepended with 'static inline' followed by an empty function body. Where optional argument 'body' is present then 'body' will be used as the function body, intended to allow simple return statements. Using the macro results in hunks such as this: -#ifdef CONFIG_HAVE_HW_BREAKPOINT -extern void hw_breakpoint_thread_switch(struct task_struct *next); -extern void ptrace_hw_copy_thread(struct task_struct *task); -#else -static inline void hw_breakpoint_thread_switch(struct task_struct *next) -{ -} -static inline void ptrace_hw_copy_thread(struct task_struct *task) -{ -} -#endif +STUB_UNLESS(CONFIG_HAVE_HW_BREAKPOINT, +void hw_breakpoint_thread_switch(struct task_struct *next)); + +STUB_UNLESS(CONFIG_HAVE_HW_BREAKPOINT, +void ptrace_hw_copy_thread(struct task_struct *task)); This may or may not be considered as more desirable than the status quo. This series updates arm64 and perf to use the macro as an example. Andrew Murray (3): kconfig.h: abstract empty functions with STUB_UNLESS macro cpufreq: update headers to use STUB_UNLESS macro arm64: update headers to use STUB_UNLESS macro arch/arm64/include/asm/acpi.h | 38 +++++++++------------- arch/arm64/include/asm/alternative.h | 6 +--- arch/arm64/include/asm/cpufeature.h | 6 +--- arch/arm64/include/asm/cpuidle.h | 18 +++-------- arch/arm64/include/asm/debug-monitors.h | 10 ++---- arch/arm64/include/asm/fpsimd.h | 57 +++++++++++++-------------------- arch/arm64/include/asm/hw_breakpoint.h | 16 +++------ arch/arm64/include/asm/kasan.h | 9 ++---- arch/arm64/include/asm/numa.h | 19 ++++------- arch/arm64/include/asm/ptdump.h | 13 +++----- arch/arm64/include/asm/signal32.h | 29 +++++------------ include/linux/cpufreq.h | 21 ++++-------- include/linux/kconfig.h | 31 ++++++++++++++++++ 13 files changed, 110 insertions(+), 163 deletions(-)