Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usb: cdc: Do not duplicate USB transfer slots for OUT transfers #27025

Merged

Conversation

eobalski
Copy link
Collaborator

@eobalski eobalski commented Jul 21, 2020

This commit fixes an issue when more than one USB transfer is
reserved for same OUT endpoint.

There are 2 scenarios when this could happen:

  • The Host sends SET_CONFIGURATION(1) request twice.
  • The Host triggers Suspend->Resume->Configured
    event sequence for the device.

USB tranfers are not canceled on SUSPEND event
when the device was not configred previously.

Because of that USB transfer slot is reserved twice
for the same OUT endpoint and lead to shortage of USB
transfer slots quickly.

Without this patch CDC ACM class reserves duplicated USB
transfer slots for one transfer. The sequence of
Suspend->Resume events is genereted alongside with
Configured and the stack will shortly run out of transfer
slots.

If the Host, for some reason, decides to send
SET_CONFIGURATION request twice the same issue is seen.
This patch prevents from reserving additional USB transfer
slots twice.

Fixes #26970

@eobalski eobalski added bug The issue is a bug, or the PR is fixing a bug area: USB Universal Serial Bus labels Jul 21, 2020
@eobalski eobalski requested review from jfischer-no and anangl July 21, 2020 15:04
@eobalski eobalski requested a review from finikorg as a code owner July 21, 2020 15:04
@eobalski
Copy link
Collaborator Author

I can drop e77a1b8 if needed.

@eobalski
Copy link
Collaborator Author

@stephanosio Could You please have a look as well?

@eobalski eobalski requested a review from stephanosio July 21, 2020 15:05
subsys/usb/class/cdc_acm.c Outdated Show resolved Hide resolved
subsys/usb/class/cdc_acm.c Outdated Show resolved Hide resolved
@pabigot
Copy link
Collaborator

pabigot commented Jul 26, 2020

#26970 explains why I can't combine the CDC ACM composite sample with a USB console and get anything useful. The fix here seems to solve that.

subsys/usb/class/cdc_acm.c Outdated Show resolved Hide resolved
@eobalski eobalski force-pushed the usb_duplicate_transfers_fix branch from e77a1b8 to 2c72565 Compare July 27, 2020 11:24
@eobalski eobalski force-pushed the usb_duplicate_transfers_fix branch from 2c72565 to 7faef15 Compare August 10, 2020 14:37
@eobalski
Copy link
Collaborator Author

@stephanosio @jfischer-phytec-iot Could You please have a look? This PR is fixing an issue.

@eobalski eobalski added priority: medium Medium impact/importance bug and removed priority: medium Medium impact/importance bug labels Aug 10, 2020
@eobalski eobalski force-pushed the usb_duplicate_transfers_fix branch 4 times, most recently from 9b8e41c to eacf3c0 Compare August 11, 2020 10:11
subsys/usb/class/cdc_acm.c Outdated Show resolved Hide resolved
subsys/usb/class/cdc_acm.c Show resolved Hide resolved
subsys/usb/usb_transfer.c Outdated Show resolved Hide resolved
@eobalski eobalski force-pushed the usb_duplicate_transfers_fix branch from eacf3c0 to c2a8af8 Compare August 11, 2020 13:27
Copy link
Collaborator

@pabigot pabigot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes hid-cdc now, fixed the problem I had three weeks ago then.

@ioannisg
Copy link
Member

@emob-nordic #26725 seems already closed. Is this PR description accurate?

@eobalski
Copy link
Collaborator Author

@ioannisg Yes, #26725 is already closed but by the PR that introduced bug with duplicate transfers. I will remove it from the description if You insist.

This commit fixes an issue when more than one USB transfer is
reserved for same OUT endpoint.

There are 2 scenarios when this could happen:
- The Host sends SET_CONFIGURATION(1) request twice.
- The Host triggers Suspend->Resume->Configured
  event sequence for the device.

USB tranfers are not canceled on SUSPEND event
when the device was not configred previously.

Because of that USB transfer slot is reserved twice
for the same OUT endpoint and lead to shortage of USB
transfer slots quickly.

Without this patch CDC ACM class reserves duplicated USB
transfer slots for one transfer. The sequence of
Suspend->Resume events is genereted alongside with
Configured and the stack will shortly run out of transfer
slots.

If the Host, for some reason, decides to send
SET_CONFIGURATION request twice the same issue is seen.
This patch prevents from reserving additional USB transfer
slots twice.

Signed-off-by: Emil Obalski <[email protected]>
@eobalski eobalski force-pushed the usb_duplicate_transfers_fix branch from c2a8af8 to abf7007 Compare August 19, 2020 08:22
@ioannisg ioannisg merged commit 1b353d5 into zephyrproject-rtos:master Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: USB Universal Serial Bus bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

usb: overflow of USB transfers leads to clogging
5 participants