]> git.hungrycats.org Git - linux/commit
firmware loader: Fix the race FW_STATUS_DONE is followed by class_timeout
authorChuansheng Liu <chuansheng.liu@intel.com>
Thu, 8 Nov 2012 11:14:40 +0000 (19:14 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Jan 2013 17:18:16 +0000 (09:18 -0800)
commit42b5489a2b5163c01e2fe23a609d397facfd0509
tree21352aa6ead5120e31d8fe5fc49354990b65f88a
parente66e367bf75bb2e153f286a76592c2e23afc660d
firmware loader: Fix the race FW_STATUS_DONE is followed by class_timeout

commit ce2fcbd99cef580623116bb33531dbc3e6f690b0 upstream.

There is a race as below when calling request_firmware():
CPU1                                   CPU2
write 0 > loading
mutex_lock(&fw_lock)
...
set_bit FW_STATUS_DONE                 class_timeout is coming
                                       set_bit FW_STATUS_ABORT
complete_all &completion
...
mutex_unlock(&fw_lock)

In this time, the bit FW_STATUS_DONE and FW_STATUS_ABORT are set,
and request_firmware() will return failure due to condition in
_request_firmware_load():
if (!buf->size || test_bit(FW_STATUS_ABORT, &buf->status))
retval = -ENOENT;

But from the above scenerio, it should be a successful requesting.
So we need judge if the bit FW_STATUS_DONE is already set before
calling fw_load_abort() in timeout function.

As Ming's proposal, we need change the timer into sched_work to
benefit from using &fw_lock mutex also.

Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>
Acked-by: Ming Lei <ming.lei@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/firmware_class.c