mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Ming Lei <ming.lei@canonical.com>
Subject: [PATCH 1/3] firmware: Avoid superfluous usermodehelper lock
Date: Wed,  8 May 2013 08:56:35 +0200	[thread overview]
Message-ID: <1367996197-32748-2-git-send-email-tiwai@suse.de> (raw)
In-Reply-To: <1367996197-32748-1-git-send-email-tiwai@suse.de>

When a firmware file can be loaded directly, there is no good reason
to lock usermodehelper.  It's needed only when the direct fw load
fails and falls back to the user-mode helper.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 drivers/base/firmware_class.c | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 4b1f926..9e1d39e 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -1006,7 +1006,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
 		  struct device *device, bool uevent, bool nowait)
 {
 	struct firmware *fw;
-	long timeout;
+	bool usermode_locked = false;
 	int ret;
 
 	if (!firmware_p)
@@ -1017,31 +1017,35 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
 		goto out;
 
 	ret = 0;
-	timeout = firmware_loading_timeout();
-	if (nowait) {
-		timeout = usermodehelper_read_lock_wait(timeout);
-		if (!timeout) {
-			dev_dbg(device, "firmware: %s loading timed out\n",
-				name);
-			ret = -EBUSY;
-			goto out;
-		}
-	} else {
-		ret = usermodehelper_read_trylock();
-		if (WARN_ON(ret)) {
-			dev_err(device, "firmware: %s will not be loaded\n",
-				name);
-			goto out;
+	if (!fw_get_filesystem_firmware(device, fw->priv)) {
+		long timeout = firmware_loading_timeout();
+		if (nowait) {
+			timeout = usermodehelper_read_lock_wait(timeout);
+			if (!timeout) {
+				dev_dbg(device, "firmware: %s loading timed out\n",
+					name);
+				ret = -EBUSY;
+				goto out;
+			}
+		} else {
+			ret = usermodehelper_read_trylock();
+			if (WARN_ON(ret)) {
+				dev_err(device, "firmware: %s will not be loaded\n",
+					name);
+				goto out;
+			}
 		}
-	}
 
-	if (!fw_get_filesystem_firmware(device, fw->priv))
+		usermode_locked = true;
 		ret = fw_load_from_user_helper(fw, name, device,
 					       uevent, nowait, timeout);
+	}
+
 	if (!ret)
 		ret = assign_firmware_buf(fw, device);
 
-	usermodehelper_read_unlock();
+	if (usermode_locked)
+		usermodehelper_read_unlock();
 
  out:
 	if (ret < 0) {
-- 
1.8.2.1


  reply	other threads:[~2013-05-08  6:57 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-08  6:56 [PATCH 0/3] firmware: Fix usermodehelper deadlock at shutdown Takashi Iwai
2013-05-08  6:56 ` Takashi Iwai [this message]
2013-05-08 15:52   ` [PATCH 1/3] firmware: Avoid superfluous usermodehelper lock Ming Lei
2013-05-08 16:21     ` Takashi Iwai
2013-05-08 16:37       ` Takashi Iwai
2013-05-08 17:51         ` Takashi Iwai
2013-05-09  1:25           ` Ming Lei
2013-05-09  7:31             ` Takashi Iwai
2013-05-09  8:43               ` Ming Lei
2013-05-09 17:04                 ` Takashi Iwai
2013-05-10  1:25                   ` Ming Lei
2013-05-10  9:32                     ` Takashi Iwai
2013-05-11 13:01                       ` Ming Lei
2013-05-12  7:20                         ` Takashi Iwai
2013-05-12 13:32                           ` Ming Lei
2013-05-13 14:48                             ` Takashi Iwai
2013-05-12 13:59           ` Ming Lei
2013-05-13 15:04             ` Takashi Iwai
2013-05-08  6:56 ` [PATCH 2/3] firmware: Avoid deadlock of usermodehelper lock at shutdown Takashi Iwai
2013-05-08 15:56   ` Ming Lei
2013-05-08 16:15     ` Takashi Iwai
2013-05-09  1:19       ` Ming Lei
2013-05-09  7:34         ` Takashi Iwai
2013-05-08  6:56 ` [PATCH 3/3] dell_rbu: Select CONFIG_FW_LOADER_USER_HELPER explicitly Takashi Iwai
2013-05-08 15:42 ` [PATCH 0/3] firmware: Fix usermodehelper deadlock at shutdown Greg Kroah-Hartman
2013-05-08 15:48   ` Takashi Iwai
2013-05-08 15:59   ` Ming Lei
2013-05-08 16:07 ` Ming Lei
2013-05-08 16:26   ` Takashi Iwai
2013-05-08 18:46     ` Kay Sievers
2013-05-09  7:26       ` Takashi Iwai
2013-05-21 17:02 ` Greg Kroah-Hartman
2013-05-22  1:21   ` Ming Lei
2013-05-22 16:25     ` Takashi Iwai

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=1367996197-32748-2-git-send-email-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@canonical.com \
    /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

all inboxes | Powered by JetHome®