diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-03-30 18:18:55 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-09-19 15:09:51 -0400 |
commit | 59edcc57a28b883b05d6d50b42cccc764191b0f3 (patch) | |
tree | 083e975bf92cb9d22386f66b2b625f1263be4a9b | |
parent | dcc4e54b77b3122e8772d45830a5879f0cd3022b (diff) | |
download | rockbox-59edcc57a2.tar.gz rockbox-59edcc57a2.zip |
buflib: omit CRC field if CRC paranoia is not enabled
If we don't check or generate CRCs then the CRC field can be left
out of the header, which reduces buflib overhead slightly.
Change-Id: I08b4cf77a701d8f6da453e019a0373d858a79ae4
-rw-r--r-- | firmware/buflib.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/firmware/buflib.c b/firmware/buflib.c index 6ddd96e7df..2ed13b49b1 100644 --- a/firmware/buflib.c +++ b/firmware/buflib.c @@ -105,6 +105,10 @@ /* Bitmask of enabled paranoia checks */ #define BUFLIB_PARANOIA 0 +#if BUFLIB_PARANOIA & PARANOIA_CHECK_CRC +# define BUFLIB_HAS_CRC +#endif + /* Forward indices, used to index a block start pointer as block[fidx_XXX] */ enum { fidx_LEN, /* length of the block, must come first */ @@ -116,14 +120,20 @@ enum { /* Backward indices, used to index a block end pointer as block[-bidx_XXX] */ enum { bidx_USER, /* dummy to get below fields to be 1-based */ +#ifdef BUFLIB_HAS_CRC bidx_CRC, /* CRC, protects all metadata behind it */ +#endif bidx_BSIZE, /* total size of the block header */ }; /* Number of fields in the block header, excluding the name, which is * accounted for using the BSIZE field. Note that bidx_USER is not an * actual field so it is not included in the count. */ -#define BUFLIB_NUM_FIELDS 5 +#ifdef BUFLIB_HAS_CRC +# define BUFLIB_NUM_FIELDS 5 +#else +# define BUFLIB_NUM_FIELDS 4 +#endif struct buflib_callbacks buflib_ops_locked = { .move_callback = NULL, @@ -1211,6 +1221,7 @@ static void check_block_handle(struct buflib_context *ctx, } } +#ifdef BUFLIB_HAS_CRC static uint32_t calc_block_crc(union buflib_data *block, union buflib_data *block_end) { @@ -1247,3 +1258,22 @@ static void check_block_crc(struct buflib_context *ctx, } } } +#else +static void update_block_crc(struct buflib_context *ctx, + union buflib_data *block, + union buflib_data *block_end) +{ + (void)ctx; + (void)block; + (void)block_end; +} + +static void check_block_crc(struct buflib_context *ctx, + union buflib_data *block, + union buflib_data *block_end) +{ + (void)ctx; + (void)block; + (void)block_end; +} +#endif |