aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/firmware_class.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 985da11174e7..4c70b9148b28 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -130,6 +130,17 @@ static ssize_t firmware_loading_show(struct device *dev,
130 return sprintf(buf, "%d\n", loading); 130 return sprintf(buf, "%d\n", loading);
131} 131}
132 132
133static void firmware_free_data(const struct firmware *fw)
134{
135 int i;
136 vunmap(fw->data);
137 if (fw->pages) {
138 for (i = 0; i < PFN_UP(fw->size); i++)
139 __free_page(fw->pages[i]);
140 kfree(fw->pages);
141 }
142}
143
133/* Some architectures don't have PAGE_KERNEL_RO */ 144/* Some architectures don't have PAGE_KERNEL_RO */
134#ifndef PAGE_KERNEL_RO 145#ifndef PAGE_KERNEL_RO
135#define PAGE_KERNEL_RO PAGE_KERNEL 146#define PAGE_KERNEL_RO PAGE_KERNEL
@@ -162,21 +173,21 @@ static ssize_t firmware_loading_store(struct device *dev,
162 mutex_unlock(&fw_lock); 173 mutex_unlock(&fw_lock);
163 break; 174 break;
164 } 175 }
165 vfree(fw_priv->fw->data); 176 firmware_free_data(fw_priv->fw);
166 fw_priv->fw->data = NULL; 177 memset(fw_priv->fw, 0, sizeof(struct firmware));
178 /* If the pages are not owned by 'struct firmware' */
167 for (i = 0; i < fw_priv->nr_pages; i++) 179 for (i = 0; i < fw_priv->nr_pages; i++)
168 __free_page(fw_priv->pages[i]); 180 __free_page(fw_priv->pages[i]);
169 kfree(fw_priv->pages); 181 kfree(fw_priv->pages);
170 fw_priv->pages = NULL; 182 fw_priv->pages = NULL;
171 fw_priv->page_array_size = 0; 183 fw_priv->page_array_size = 0;
172 fw_priv->nr_pages = 0; 184 fw_priv->nr_pages = 0;
173 fw_priv->fw->size = 0;
174 set_bit(FW_STATUS_LOADING, &fw_priv->status); 185 set_bit(FW_STATUS_LOADING, &fw_priv->status);
175 mutex_unlock(&fw_lock); 186 mutex_unlock(&fw_lock);
176 break; 187 break;
177 case 0: 188 case 0:
178 if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) { 189 if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) {
179 vfree(fw_priv->fw->data); 190 vunmap(fw_priv->fw->data);
180 fw_priv->fw->data = vmap(fw_priv->pages, 191 fw_priv->fw->data = vmap(fw_priv->pages,
181 fw_priv->nr_pages, 192 fw_priv->nr_pages,
182 0, PAGE_KERNEL_RO); 193 0, PAGE_KERNEL_RO);
@@ -184,7 +195,10 @@ static ssize_t firmware_loading_store(struct device *dev,
184 dev_err(dev, "%s: vmap() failed\n", __func__); 195 dev_err(dev, "%s: vmap() failed\n", __func__);
185 goto err; 196 goto err;
186 } 197 }
187 /* Pages will be freed by vfree() */ 198 /* Pages are now owned by 'struct firmware' */
199 fw_priv->fw->pages = fw_priv->pages;
200 fw_priv->pages = NULL;
201
188 fw_priv->page_array_size = 0; 202 fw_priv->page_array_size = 0;
189 fw_priv->nr_pages = 0; 203 fw_priv->nr_pages = 0;
190 complete(&fw_priv->completion); 204 complete(&fw_priv->completion);
@@ -578,7 +592,7 @@ release_firmware(const struct firmware *fw)
578 if (fw->data == builtin->data) 592 if (fw->data == builtin->data)
579 goto free_fw; 593 goto free_fw;
580 } 594 }
581 vfree(fw->data); 595 firmware_free_data(fw);
582 free_fw: 596 free_fw:
583 kfree(fw); 597 kfree(fw);
584 } 598 }