Skip to content

Commit

Permalink
fix potential race condition in boot-cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
purdeaandrei committed Sep 26, 2024
1 parent 0aac428 commit 6070c58
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions firmware/boot-cypress/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,14 @@ void handle_pending_usb_setup(void) {
}
SETUP_EP0_BUF(len);
} else {
SETUP_EP0_BUF(0);
SETUP_EP0_OUT_BUF();
while(EP0CS & _BUSY);
if(!eeprom_write(arg_chip, arg_addr, EP0BUF, len, arg_dbyte, page_size,
/*timeout=*/166)) {
STALL_EP0();
break;
}
ACK_EP0()
}

arg_len -= len;
Expand All @@ -179,9 +180,10 @@ void handle_pending_usb_setup(void) {
xmemcpy(EP0BUF, (__xdata void *)arg_addr, len);
SETUP_EP0_BUF(len);
} else {
SETUP_EP0_BUF(0);
SETUP_EP0_OUT_BUF();
while(EP0CS & _BUSY);
xmemcpy((__xdata void *)arg_addr, EP0BUF, arg_len);
ACK_EP0();
}

arg_len -= len;
Expand Down

0 comments on commit 6070c58

Please sign in to comment.