diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/buflib.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/firmware/buflib.c b/firmware/buflib.c index c6ec011653..4551fd8dca 100644 --- a/firmware/buflib.c +++ b/firmware/buflib.c | |||
@@ -664,23 +664,22 @@ find_block_before(struct buflib_context *ctx, union buflib_data* block, | |||
664 | union buflib_data *ret = ctx->buf_start, | 664 | union buflib_data *ret = ctx->buf_start, |
665 | *next_block = ret; | 665 | *next_block = ret; |
666 | 666 | ||
667 | /* no previous block */ | ||
668 | if (next_block == block) | ||
669 | return NULL; | ||
670 | |||
667 | /* find the block that's before the current one */ | 671 | /* find the block that's before the current one */ |
668 | while (next_block < block) | 672 | while (next_block != block) |
669 | { | 673 | { |
670 | ret = next_block; | 674 | ret = next_block; |
671 | next_block += abs(ret->val); | 675 | next_block += abs(ret->val); |
672 | } | 676 | } |
673 | 677 | ||
674 | /* If next_block == block, the above loop didn't go anywhere. If it did, | 678 | /* don't return it if the found block isn't free */ |
675 | * and the block before this one is empty, that is the wanted one | 679 | if (is_free && ret->val >= 0) |
676 | */ | 680 | return NULL; |
677 | if (next_block == block && ret < block) | 681 | |
678 | { | 682 | return ret; |
679 | if (is_free && ret->val >= 0) /* NULL if found block isn't free */ | ||
680 | return NULL; | ||
681 | return ret; | ||
682 | } | ||
683 | return NULL; | ||
684 | } | 683 | } |
685 | 684 | ||
686 | /* Free the buffer associated with handle_num. */ | 685 | /* Free the buffer associated with handle_num. */ |