From 59edcc57a28b883b05d6d50b42cccc764191b0f3 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Wed, 30 Mar 2022 18:18:55 +0100 Subject: 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 --- firmware/buflib.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'firmware') 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 -- cgit v1.2.3