Skip to content

Commit 35bdf9a

Browse files
OGAWAHirofumigregkh
authored andcommitted
nfc: Fix hangup of RC-S380* in port100_send_ack()
commit 2497128 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 <[email protected]> Signed-off-by: Samuel Ortiz <[email protected]> Signed-off-by: Amit Pundir <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6b3d13f commit 35bdf9a

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

drivers/nfc/port100.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -725,23 +725,33 @@ static int port100_submit_urb_for_ack(struct port100 *dev, gfp_t flags)
725725

726726
static int port100_send_ack(struct port100 *dev)
727727
{
728-
int rc;
728+
int rc = 0;
729729

730730
mutex_lock(&dev->out_urb_lock);
731731

732-
init_completion(&dev->cmd_cancel_done);
732+
/*
733+
* If prior cancel is in-flight (dev->cmd_cancel == true), we
734+
* can skip to send cancel. Then this will wait the prior
735+
* cancel, or merged into the next cancel rarely if next
736+
* cancel was started before waiting done. In any case, this
737+
* will be waked up soon or later.
738+
*/
739+
if (!dev->cmd_cancel) {
740+
reinit_completion(&dev->cmd_cancel_done);
733741

734-
usb_kill_urb(dev->out_urb);
742+
usb_kill_urb(dev->out_urb);
735743

736-
dev->out_urb->transfer_buffer = ack_frame;
737-
dev->out_urb->transfer_buffer_length = sizeof(ack_frame);
738-
rc = usb_submit_urb(dev->out_urb, GFP_KERNEL);
744+
dev->out_urb->transfer_buffer = ack_frame;
745+
dev->out_urb->transfer_buffer_length = sizeof(ack_frame);
746+
rc = usb_submit_urb(dev->out_urb, GFP_KERNEL);
739747

740-
/* Set the cmd_cancel flag only if the URB has been successfully
741-
* submitted. It will be reset by the out URB completion callback
742-
* port100_send_complete().
743-
*/
744-
dev->cmd_cancel = !rc;
748+
/*
749+
* Set the cmd_cancel flag only if the URB has been
750+
* successfully submitted. It will be reset by the out
751+
* URB completion callback port100_send_complete().
752+
*/
753+
dev->cmd_cancel = !rc;
754+
}
745755

746756
mutex_unlock(&dev->out_urb_lock);
747757

@@ -928,8 +938,8 @@ static void port100_send_complete(struct urb *urb)
928938
struct port100 *dev = urb->context;
929939

930940
if (dev->cmd_cancel) {
941+
complete_all(&dev->cmd_cancel_done);
931942
dev->cmd_cancel = false;
932-
complete(&dev->cmd_cancel_done);
933943
}
934944

935945
switch (urb->status) {
@@ -1543,6 +1553,7 @@ static int port100_probe(struct usb_interface *interface,
15431553
PORT100_COMM_RF_HEAD_MAX_LEN;
15441554
dev->skb_tailroom = PORT100_FRAME_TAIL_LEN;
15451555

1556+
init_completion(&dev->cmd_cancel_done);
15461557
INIT_WORK(&dev->cmd_complete_work, port100_wq_cmd_complete);
15471558

15481559
/* The first thing to do with the Port-100 is to set the command type

0 commit comments

Comments
 (0)