Search Linux Wireless

[PATCH 5/7] firmware_class: extract start loading logic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Extract the logic performed when starting a new firmware load.

Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
---
 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-wireless" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Wireless Personal Area Network]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]

  Powered by Linux