diff options
author | Ming Lei <ming.lei@canonical.com> | 2012-08-04 00:01:17 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-16 16:13:18 -0400 |
commit | 28eefa750b5e16b13bb869c2c4f7d624a43eb48b (patch) | |
tree | 1bf6575f9884bdb49f9b8340d159b5ced97383e2 /drivers/base/firmware_class.c | |
parent | 65710cb6ea315b3ef76a8a3da7be99afcf58d2bb (diff) |
firmware loader: fix races during loading firmware
This patch fixes two races in loading firmware:
1, FW_STATUS_DONE should be set before waking up the task waitting
on _request_firmware_load, otherwise FW_STATUS_ABORT may be
thought as DONE mistakenly.
2, Inside _request_firmware_load(), there is a small window between
wait_for_completion() and mutex_lock(&fw_lock), and 'echo 1 > loading'
still may happen during the period, so this patch checks FW_STATUS_DONE
to prevent pages' buffer completed from being freed in firmware_loading_store.
Signed-off-by: Ming Lei <ming.lei@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base/firmware_class.c')
-rw-r--r-- | drivers/base/firmware_class.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 1cbefcfd15f7..1915ad821688 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c | |||
@@ -243,18 +243,21 @@ static ssize_t firmware_loading_store(struct device *dev, | |||
243 | switch (loading) { | 243 | switch (loading) { |
244 | case 1: | 244 | case 1: |
245 | /* discarding any previous partial load */ | 245 | /* discarding any previous partial load */ |
246 | for (i = 0; i < fw_priv->nr_pages; i++) | 246 | if (!test_bit(FW_STATUS_DONE, &fw_priv->status)) { |
247 | __free_page(fw_priv->pages[i]); | 247 | for (i = 0; i < fw_priv->nr_pages; i++) |
248 | kfree(fw_priv->pages); | 248 | __free_page(fw_priv->pages[i]); |
249 | fw_priv->pages = NULL; | 249 | kfree(fw_priv->pages); |
250 | fw_priv->page_array_size = 0; | 250 | fw_priv->pages = NULL; |
251 | fw_priv->nr_pages = 0; | 251 | fw_priv->page_array_size = 0; |
252 | set_bit(FW_STATUS_LOADING, &fw_priv->status); | 252 | fw_priv->nr_pages = 0; |
253 | set_bit(FW_STATUS_LOADING, &fw_priv->status); | ||
254 | } | ||
253 | break; | 255 | break; |
254 | case 0: | 256 | case 0: |
255 | if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) { | 257 | if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) { |
256 | complete(&fw_priv->completion); | 258 | set_bit(FW_STATUS_DONE, &fw_priv->status); |
257 | clear_bit(FW_STATUS_LOADING, &fw_priv->status); | 259 | clear_bit(FW_STATUS_LOADING, &fw_priv->status); |
260 | complete(&fw_priv->completion); | ||
258 | break; | 261 | break; |
259 | } | 262 | } |
260 | /* fallthrough */ | 263 | /* fallthrough */ |
@@ -557,7 +560,6 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent, | |||
557 | 560 | ||
558 | wait_for_completion(&fw_priv->completion); | 561 | wait_for_completion(&fw_priv->completion); |
559 | 562 | ||
560 | set_bit(FW_STATUS_DONE, &fw_priv->status); | ||
561 | del_timer_sync(&fw_priv->timeout); | 563 | del_timer_sync(&fw_priv->timeout); |
562 | 564 | ||
563 | mutex_lock(&fw_lock); | 565 | mutex_lock(&fw_lock); |