mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andres Rodriguez <andresx7@gmail.com>
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	[thread overview]
Message-ID: <20180309230925.3573-1-andresx7@gmail.com> (raw)
In-Reply-To: <20180309221243.15489-2-andresx7@gmail.com>

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 <andresx7@gmail.com>
---

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

  reply	other threads:[~2018-03-09 23:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-09 22:12 [RFC 0/1] Loading optional firmware Andres Rodriguez
2018-03-09 22:12 ` [PATCH 1/1] firmware: add a function to load " Andres Rodriguez
2018-03-09 23:09   ` Andres Rodriguez [this message]
2018-03-10 14:35     ` [PATCH] firmware: add a function to load optional firmware v2 Luis R. Rodriguez
2018-03-10 14:40       ` Luis R. Rodriguez
2018-03-11 16:05         ` Andres Rodriguez
2018-03-11 23:10           ` Arend van Spriel
2018-03-12 19:27             ` Luis R. Rodriguez
2018-03-13 13:39               ` Kalle Valo
2018-03-13 16:25                 ` Andres Rodriguez
2018-03-13 16:38                 ` Luis R. Rodriguez
2018-03-20  2:21                   ` Andres Rodriguez
2018-03-13 13:35             ` Kalle Valo
2018-03-13 13:16       ` Kalle Valo
2018-03-13 16:40         ` Luis R. Rodriguez
2018-03-13 16:42           ` Andres Rodriguez
2018-03-13 16:46           ` Kalle Valo
2018-03-14  8:24             ` Arend van Spriel
2018-03-14  8:48               ` Kalle Valo
2018-03-11 23:18     ` Arend van Spriel
2018-03-10 14:18 ` [RFC 0/1] Loading optional firmware Luis R. Rodriguez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180309230925.3573-1-andresx7@gmail.com \
    --to=andresx7@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome