summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-02-17 14:07:29 +0700
committerGitHub <[email protected]>2021-02-17 14:07:29 +0700
commit1b849fc70a9dca3603b38828a3c37696efb1ebe0 (patch)
tree2555d6e6e46943f00c26104aca792fa9e3f2a796 /src/common
parent09868434cd9f53394350cce682333ada97f796c3 (diff)
parentb7ec66e33af1e24b763d855545d921ec5957f61a (diff)
Merge pull request #655 from ndinsmore/fifo_fix
Fix to fifo pointer overflow mathmatics
Diffstat (limited to 'src/common')
-rw-r--r--src/common/tusb_fifo.c2
-rw-r--r--src/common/tusb_fifo.h2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c
index 00f2434a7..e3c4d74c7 100644
--- a/src/common/tusb_fifo.c
+++ b/src/common/tusb_fifo.c
@@ -74,7 +74,7 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si
f->overwritable = overwritable;
f->max_pointer_idx = 2*depth - 1; // Limit index space to 2*depth - this allows for a fast "modulo" calculation but limits the maximum depth to 2^16/2 = 2^15 and buffer overflows are detectable only if overflow happens once (important for unsupervised DMA applications)
- f->non_used_index_space = 0xFFFF - f->max_pointer_idx;
+ f->non_used_index_space = UINT16_MAX - f->max_pointer_idx;
f->rd_idx = f->wr_idx = 0;
diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h
index b965386ab..c35b85a49 100644
--- a/src/common/tusb_fifo.h
+++ b/src/common/tusb_fifo.h
@@ -86,7 +86,7 @@ typedef struct
.item_size = sizeof(_type), \
.overwritable = _overwritable, \
.max_pointer_idx = 2*_depth-1, \
- .non_used_index_space = 0xFFFF - 2*_depth-1, \
+ .non_used_index_space = UINT16_MAX - (2*_depth-1), \
}
bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable);