# HG changeset patch # User Michael Pavone # Date 1697091496 25200 # Node ID 2025ba21026a8ccfb2cfa3ced1afb1a7f9350474 # Parent 047253715fd86b3c3bd83b7083e0940321636ef1 Fix backwards seek calculation diff -r 047253715fd8 -r 2025ba21026a cdd_mcu.c --- a/cdd_mcu.c Wed Oct 11 11:36:18 2023 -0700 +++ b/cdd_mcu.c Wed Oct 11 23:18:16 2023 -0700 @@ -125,13 +125,15 @@ } } else { uint32_t seek_amount; - for (seek_amount = max_seek; seek_amount >= min_seek; seek_amount >>= 1) + for (seek_amount = max_seek; seek_amount >= min_seek;) { - if (context->head_pba - context->seek_pba >= seek_amount) { + uint32_t next_seek = seek_amount >> 1; + if (context->head_pba - context->seek_pba > next_seek) { break; } + seek_amount = next_seek; } - if (seek_amount >= min_seek) { + if (seek_amount >= min_seek && context->head_pba >= seek_amount) { context->head_pba -= seek_amount; } else if (context->head_pba >= min_seek){ context->head_pba -= min_seek;