Received: by 10.223.185.111 with SMTP id b44csp850875wrg; Fri, 9 Mar 2018 15:10:45 -0800 (PST) X-Google-Smtp-Source: AG47ELtvBe/iNrNEbBZDp1qxL+EziVgIPkoCk/sob/+MA4pChR/chjk2q9fIcOpdLDB+3yewCrYW X-Received: by 2002:a17:902:8487:: with SMTP id c7-v6mr142965plo.143.1520637045839; Fri, 09 Mar 2018 15:10:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520637045; cv=none; d=google.com; s=arc-20160816; b=eT4RbvbbHU1DDrk6QUmjJPpLkM8MQ/M3F8tla6jya6GHYVOa9MQwTVRZWRWP4vFwa9 VTor2r5U67HmB1mdb57wiBU79CRktR+h05M9IHxWwbVFvL7I9vo7zzPKq79RN8g8DvkP 9sQULVz7BLZV9L2t2vlh35eX/4ZRegORZZ23dBxjbIOPX4fTCeCNFrdj3Y9RnWHRFhnC DtSTP5TXEQHaUzpM+PYvGgkhvwLn1PPqaaPKLC9hHJjJt6pmd8ZsJBZYOaldKpqIJ2BC 8Ka/4sKNGn9m6ITmjp5ANvKEfiIMiOqQF4Cs1i/bQf48do05j7/+rkDtlNcVwXoDDvZs rwpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=uGMcrkEOeTgEmayqpZ9Z1uBt4nbq8u4a9XMY9h4E3wY=; b=Ux4JoR4LlFFtK6gAqaN7e7KsJFmGxAiKYvKm+W1E+F4lXjsALl6UmElUNF1oSqFh4A Gy2gbzQy7ahJsw5uNH1CxA63cg90JzYQrROWPjLXlWP9qtG+vVKbzRqiBZQdYpbpTvTd BKXv2LcmvYajG3/gmdwgF+PFrn/Chc9E0pO4ZmRK/iE+YZCvWJofWzV+8q/7y1VqH5jb V3l6vpzhKQBh0m8ueESURdaFvEwyVw7btFssQqa4sxS2uXtUGnUne0eKGaNeL5HurxO3 wnmpf7ODjah/L0V89O7q3WI1Eeb3G6L2tAr/ZBiHe0VbwHrridd5+8uKHKEmDLbghQ7/ Mzng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mXApy5wN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c15-v6si1663460plo.28.2018.03.09.15.10.31; Fri, 09 Mar 2018 15:10:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mXApy5wN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932714AbeCIXJj (ORCPT + 99 others); Fri, 9 Mar 2018 18:09:39 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:40539 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932320AbeCIXJi (ORCPT ); Fri, 9 Mar 2018 18:09:38 -0500 Received: by mail-it0-f65.google.com with SMTP id e64-v6so4762054ita.5 for ; Fri, 09 Mar 2018 15:09:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uGMcrkEOeTgEmayqpZ9Z1uBt4nbq8u4a9XMY9h4E3wY=; b=mXApy5wNfoc7jVT06FFKQIAXhRVXL54bs9Z6YcnJAaehUfQEepEcyD02oNtsvrQuXl AOkCBe+ApPL8Kibasw7CgttIuS6SLrEOvqgdNp5DOMn/kLFp4/Zz2SWBT7vu+J2FpP1s mwBuBirWlCxS40cEROhgjNVMHNS6RThSy+bvLQcSaUeJXWXFnNDUvxLfovUUJlww779r UPOL81q9U66WFJhmhzkd7X+5DCeLqN5a+zHTUnGTjswfhOjtnMnjSPDgWkGFjuJ3oUB+ kVkzwCNcvPsstjoxvZ3XYGicLu0GMU0uXJ0B/OsUGIMjFWdL4utjHQ0TjmZ3CtH+jMWN YtKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uGMcrkEOeTgEmayqpZ9Z1uBt4nbq8u4a9XMY9h4E3wY=; b=OLr1fhqy5nJDua3CT6Dc2UVGXn2B27IVo6IgF9f6rPYtyeePyhgpKOAu0UDd2SYCSu 7yZ70y72mB9ZuOpzHFHK7DhUQeRkZ2jihOTrlzHbaVxkYhyYWHN6Sg+tZUh/GqO47C16 5MhOXNAgwLPtyM/pLuMAPdsBeFAzoseGtJlDQv/uB07eM95xcZtQ5RLcDhm8Z6Z6V3uP 4WstyQOiRIVCH3z7rPA/WTS+XRVmeJh4M1st1cpCbft/fKlR/y2AuPW0CiRo4AU2eXwJ BDG3uAkCQUzJProUVJdQgjSMIZFNtWCDmA8udL2bXkvPwClIpWon6P8SYtlm2Ua2w5iE G1mQ== X-Gm-Message-State: AElRT7HyLnozBtw7YI52+FtSoBAMvs7AIEbxhL6FA35smqqtzGnE0djc As/SYl1b+Yi/rWodIlqOj9rFvybE X-Received: by 10.36.33.17 with SMTP id e17mr791989ita.44.1520636977382; Fri, 09 Mar 2018 15:09:37 -0800 (PST) Received: from localhost.localdomain (184-175-36-239.dsl.teksavvy.com. [184.175.36.239]) by smtp.gmail.com with ESMTPSA id e138sm1785284itc.10.2018.03.09.15.09.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Mar 2018 15:09:36 -0800 (PST) From: Andres Rodriguez To: linux-kernel@vger.kernel.org Cc: andresx7@gmail.com, gregkh@linuxfoundation.org, mcgrof@kernel.org Subject: [PATCH] firmware: add a function to load optional firmware v2 Date: Fri, 9 Mar 2018 18:09:25 -0500 Message-Id: <20180309230925.3573-1-andresx7@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180309221243.15489-2-andresx7@gmail.com> References: <20180309221243.15489-2-andresx7@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the firmware loader only exposes one silent path for querying optional firmware, and that is request_firmware_direct(). This function also disables the usermodehelper fallback which might not always be the desired behaviour. This patch introduces request_firmware_optional(), which will not produce error/warning messages if the firmware file is not found, but will still attempt to query the usermodehelper for the optional firmware. Effectively, FW_OPT_UEVENT | FW_OPT_FALLBACK | FW_OPT_NO_WARN. v2: add header prototype, use updated opt_flags Signed-off-by: Andres Rodriguez --- Sorry, I messed up the v1 patch and sent the wrong one from before I rebased. drivers/base/firmware_class.c | 26 +++++++++++++++++++++++++- include/linux/firmware.h | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 7dd36ace6152..4e1eddea241b 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -1181,7 +1181,7 @@ static int fw_sysfs_fallback(struct firmware *fw, const char *name, if (!fw_run_sysfs_fallback(opt_flags)) return ret; - dev_warn(device, "Falling back to user helper\n"); + dev_warn(device, "Falling back to user helper for %s\n", name); return fw_load_from_user_helper(fw, name, device, opt_flags); } #else /* CONFIG_FW_LOADER_USER_HELPER */ @@ -1351,6 +1351,30 @@ request_firmware(const struct firmware **firmware_p, const char *name, } EXPORT_SYMBOL(request_firmware); +/** + * request_firmware_optional: - request for an optional fw module + * @firmware_p: pointer to firmware image + * @name: name of firmware file + * @device: device for which firmware is being loaded + * + * This function is similar in behaviour to request_firmware(), except + * it doesn't produce warning messages when the file is not found. + **/ +int +request_firmware_optional(const struct firmware **firmware_p, const char *name, + struct device *device) +{ + int ret; + + /* 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_NO_WARN ); + module_put(THIS_MODULE); + return ret; +} +EXPORT_SYMBOL(request_firmware_optional); + /** * request_firmware_direct: - load firmware directly without usermode helper * @firmware_p: pointer to firmware image diff --git a/include/linux/firmware.h b/include/linux/firmware.h index d4508080348d..6f386eeb8efc 100644 --- a/include/linux/firmware.h +++ b/include/linux/firmware.h @@ -46,6 +46,8 @@ int request_firmware_nowait( struct module *module, bool uevent, const char *name, struct device *device, gfp_t gfp, void *context, void (*cont)(const struct firmware *fw, void *context)); +int request_firmware_optional(const struct firmware **fw, const char *name, + struct device *device); int request_firmware_direct(const struct firmware **fw, const char *name, struct device *device); int request_firmware_into_buf(const struct firmware **firmware_p, -- 2.14.1