Skip to content

Commit

Permalink
usb: device: Fix transfer slot leak without callback
Browse files Browse the repository at this point in the history
Log transfer status and release transfer semaphore regardless if user
provided transfer completion callback or not. This fixes transfer slot
leak when transfer without callback completes.

Signed-off-by: Tomasz Moń <[email protected]>
  • Loading branch information
tmon-nordic authored and fabiobaltieri committed Aug 4, 2023
1 parent 675726f commit 0ab14d9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions subsys/usb/device/usb_transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static void usb_transfer_work(struct k_work *item)
}

done:
if (trans->status != -EBUSY && trans->cb) { /* Transfer complete */
if (trans->status != -EBUSY) { /* Transfer complete */
usb_transfer_callback cb = trans->cb;
int tsize = trans->tsize;
void *priv = trans->priv;
Expand All @@ -149,7 +149,9 @@ static void usb_transfer_work(struct k_work *item)
k_sem_give(&trans->sem);

/* Transfer completion callback */
cb(ep, tsize, priv);
if (cb) {
cb(ep, tsize, priv);
}
}
}

Expand Down

0 comments on commit 0ab14d9

Please sign in to comment.