Skip to content

Commit 6070c74

Browse files
Jakob-Koschelgregkh
authored andcommitted
usb: gadget: dummy_hcd: remove usage of list iterator past the loop body
[ Upstream commit 7975f08 ] To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com> Link: https://lore.kernel.org/r/20220308171818.384491-26-jakobkoschel@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Stable-dep-of: 8d63c83 ("USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8a82e3a commit 6070c74

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

drivers/usb/gadget/udc/dummy_hcd.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req)
748748
struct dummy *dum;
749749
int retval = -EINVAL;
750750
unsigned long flags;
751-
struct dummy_request *req = NULL;
751+
struct dummy_request *req = NULL, *iter;
752752

753753
if (!_ep || !_req)
754754
return retval;
@@ -760,13 +760,14 @@ static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req)
760760

761761
local_irq_save(flags);
762762
spin_lock(&dum->lock);
763-
list_for_each_entry(req, &ep->queue, queue) {
764-
if (&req->req == _req) {
765-
list_del_init(&req->queue);
766-
_req->status = -ECONNRESET;
767-
retval = 0;
768-
break;
769-
}
763+
list_for_each_entry(iter, &ep->queue, queue) {
764+
if (&iter->req != _req)
765+
continue;
766+
list_del_init(&iter->queue);
767+
_req->status = -ECONNRESET;
768+
req = iter;
769+
retval = 0;
770+
break;
770771
}
771772
spin_unlock(&dum->lock);
772773

0 commit comments

Comments
 (0)