nfc: Fix hangup of RC-S380* in port100_send_ack()
authorOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Sat, 4 Feb 2017 01:16:56 +0000 (10:16 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 7 Aug 2017 01:59:41 +0000 (18:59 -0700)
commit35bdf9a61dc9bd8e47f988b729e038a1ac8b7c9d
treecbbcb15ddd7fe333ba6b77916990d5843a3ea93b
parent6b3d13fe67da15aca3186c11c016b6abd00f0469
nfc: Fix hangup of RC-S380* in port100_send_ack()

commit 2497128133f8169b24b928852ba6eae34fc495e5 upstream.

If port100_send_ack() was called twice or more, it has race to hangup.

  port100_send_ack()          port100_send_ack()
    init_completion()
    [...]
    dev->cmd_cancel = true
                                /* this removes previous from completion */
                                init_completion()
[...]
                                dev->cmd_cancel = true
                                wait_for_completion()
    /* never be waked up */
    wait_for_completion()

Like above race, this code is not assuming port100_send_ack() is
called twice or more.

To fix, this checks dev->cmd_cancel to know if prior cancel is
in-flight or not. And never be remove prior task from completion by
using reinit_completion(), so this guarantees to be waked up properly
soon or later.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nfc/port100.c