[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1405373897-31671-6-git-send-email-keescook@chromium.org>
Date: Mon, 14 Jul 2014 14:38:15 -0700
From: Kees Cook <keescook@...omium.org>
To: linux-kernel@...r.kernel.org
Cc: Kees Cook <keescook@...omium.org>,
Ming Lei <ming.lei@...onical.com>,
"Luis R. Rodriguez" <mcgrof@...e.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
James Morris <james.l.morris@...cle.com>,
David Howells <dhowells@...hat.com>, linux-doc@...r.kernel.org,
linux-security-module@...r.kernel.org, linux-firmware@...nel.org,
linux-wireless <linux-wireless@...r.kernel.org>
Subject: [PATCH 5/7] firmware_class: extract start loading logic
Extract the logic performed when starting a new firmware load.
Signed-off-by: Kees Cook <keescook@...omium.org>
---
drivers/base/firmware_class.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 7399bab71ced..b38cbcd6ebb1 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -604,6 +604,23 @@ static int fw_map_pages_buf(struct firmware_buf *buf)
return 0;
}
+/* fw_lock must be held */
+static void fw_load_start(struct firmware_buf *fw_buf)
+{
+ /* discarding any previous partial load */
+ if (!test_bit(FW_STATUS_DONE, &fw_buf->status)) {
+ int i;
+
+ for (i = 0; i < fw_buf->nr_pages; i++)
+ __free_page(fw_buf->pages[i]);
+ kfree(fw_buf->pages);
+ fw_buf->pages = NULL;
+ fw_buf->page_array_size = 0;
+ fw_buf->nr_pages = 0;
+ set_bit(FW_STATUS_LOADING, &fw_buf->status);
+ }
+}
+
/**
* firmware_loading_store - set value in the 'loading' control file
* @dev: device pointer
@@ -624,7 +641,6 @@ static ssize_t firmware_loading_store(struct device *dev,
struct firmware_priv *fw_priv = to_firmware_priv(dev);
struct firmware_buf *fw_buf;
int loading = simple_strtol(buf, NULL, 10);
- int i;
mutex_lock(&fw_lock);
fw_buf = fw_priv->buf;
@@ -633,16 +649,7 @@ static ssize_t firmware_loading_store(struct device *dev,
switch (loading) {
case 1:
- /* discarding any previous partial load */
- if (!test_bit(FW_STATUS_DONE, &fw_buf->status)) {
- for (i = 0; i < fw_buf->nr_pages; i++)
- __free_page(fw_buf->pages[i]);
- kfree(fw_buf->pages);
- fw_buf->pages = NULL;
- fw_buf->page_array_size = 0;
- fw_buf->nr_pages = 0;
- set_bit(FW_STATUS_LOADING, &fw_buf->status);
- }
+ fw_load_start(fw_buf);
break;
case 0:
if (test_bit(FW_STATUS_LOADING, &fw_buf->status)) {
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists