From patchwork Mon Nov 20 18:23:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 10066921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C3576038F for ; Mon, 20 Nov 2017 18:27:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 121A5290D6 for ; Mon, 20 Nov 2017 18:27:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06880293CB; Mon, 20 Nov 2017 18:27:38 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5777290D6 for ; Mon, 20 Nov 2017 18:27:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752280AbdKTSYa (ORCPT ); Mon, 20 Nov 2017 13:24:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:57424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752233AbdKTSY0 (ORCPT ); Mon, 20 Nov 2017 13:24:26 -0500 Received: from garbanzo.do-not-panic.com (c-73-15-241-2.hsd1.ca.comcast.net [73.15.241.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 906EF2199E; Mon, 20 Nov 2017 18:24:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 906EF2199E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mcgrof@kernel.org From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: akpm@linux-foundation.org, keescook@chromium.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, markivx@codeaurora.org, stephen.boyd@linaro.org, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, bjorn.andersson@linaro.org, jewalt@lgsinnovations.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Luis R. Rodriguez" Subject: [PATCH v2 12/23] firmware: replace #ifdef over FW_OPT_FALLBACK with function checks Date: Mon, 20 Nov 2017 10:23:58 -0800 Message-Id: <20171120182409.27348-13-mcgrof@kernel.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20171120182409.27348-1-mcgrof@kernel.org> References: <20171120182409.27348-1-mcgrof@kernel.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Its not easy to follow the logic behind making FW_OPT_FALLBACK map to an existing flag only if a kernel configuration option was set. Its much easier to retpresent what was intended with function helpers which make it clear that if CONFIG_FW_LOADER_USER_HELPER_FALLBACK is set we force running the fallback mechanism unless a caller specifically never wants to run it, such as request_firmware_direct(). Prior and after this change we upkeep the tradition: CONFIG_FW_LOADER_USER_HELPER_FALLBACK request_firmware() force fallback request_firmware_into_buf() force fallback request_firmware_nowait() force fallback request_firmware_direct() always ignore fallback !CONFIG_FW_LOADER_USER_HELPER_FALLBACK request_firmware() ignore fallback request_firmware_into_buf() ignore fallback request_firmware_nowait() depends on uevent flag request_firmware_direct() always ignore fallback Signed-off-by: Luis R. Rodriguez --- drivers/base/firmware_class.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 316991429032..43b97a8137f7 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -62,13 +62,9 @@ struct fw_state { #define FW_OPT_UEVENT (1U << 0) #define FW_OPT_NOWAIT (1U << 1) #define FW_OPT_USERHELPER (1U << 2) -#ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK -#define FW_OPT_FALLBACK FW_OPT_USERHELPER -#else -#define FW_OPT_FALLBACK 0 -#endif #define FW_OPT_NO_WARN (1U << 3) #define FW_OPT_NOCACHE (1U << 4) +#define FW_OPT_NOFALLBACK (1U << 5) struct firmware_cache { /* firmware_buf instance will be added into the below list */ @@ -1154,12 +1150,34 @@ static int fw_load_from_user_helper(struct firmware *firmware, return ret; } +#ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK +static bool fw_force_sysfs_fallback(unsigned int opt_flags) +{ + return true; +} +#else +static bool fw_force_sysfs_fallback(unsigned int opt_flags) +{ + if (!(opt_flags & FW_OPT_USERHELPER)) + return false; + return true; +} +#endif + +static bool fw_run_sysfs_fallback(unsigned int opt_flags) +{ + if ((opt_flags & FW_OPT_NOFALLBACK)) + return false; + + return fw_force_sysfs_fallback(opt_flags); +} + static int fw_sysfs_fallback(struct firmware *fw, const char *name, struct device *device, unsigned int opt_flags, int ret) { - if (!(opt_flags & FW_OPT_USERHELPER)) + if (!fw_run_sysfs_fallback(opt_flags)) return ret; dev_warn(device, "Falling back to user helper\n"); @@ -1326,7 +1344,7 @@ request_firmware(const struct firmware **firmware_p, const char *name, /* Need to pin this module until return */ __module_get(THIS_MODULE); ret = _request_firmware(firmware_p, name, device, NULL, 0, - FW_OPT_UEVENT | FW_OPT_FALLBACK); + FW_OPT_UEVENT); module_put(THIS_MODULE); return ret; } @@ -1350,7 +1368,8 @@ int request_firmware_direct(const struct firmware **firmware_p, __module_get(THIS_MODULE); ret = _request_firmware(firmware_p, name, device, NULL, 0, - FW_OPT_UEVENT | FW_OPT_NO_WARN); + FW_OPT_UEVENT | FW_OPT_NO_WARN | + FW_OPT_NOFALLBACK); module_put(THIS_MODULE); return ret; } @@ -1379,8 +1398,7 @@ request_firmware_into_buf(const struct firmware **firmware_p, const char *name, __module_get(THIS_MODULE); ret = _request_firmware(firmware_p, name, device, buf, size, - FW_OPT_UEVENT | FW_OPT_FALLBACK | - FW_OPT_NOCACHE); + FW_OPT_UEVENT | FW_OPT_NOCACHE); module_put(THIS_MODULE); return ret; } @@ -1472,7 +1490,7 @@ request_firmware_nowait( fw_work->device = device; fw_work->context = context; fw_work->cont = cont; - fw_work->opt_flags = FW_OPT_NOWAIT | FW_OPT_FALLBACK | + fw_work->opt_flags = FW_OPT_NOWAIT | (uevent ? FW_OPT_UEVENT : FW_OPT_USERHELPER); if (!try_module_get(module)) {