[2/4] hash: use alloca instead of vla trivial
Checks
Commit Message
RFC sample illustrating simple conversion of VLA to alloca() where
dimension multiplier removed.
Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
lib/hash/rte_thash.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
> From: Tyler Retzlaff [mailto:roretzla@linux.microsoft.com]
> Sent: Thursday, 4 April 2024 19.15
>
> RFC sample illustrating simple conversion of VLA to alloca() where
> dimension multiplier removed.
>
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
[...]
> {
> - uint32_t tmp_tuple[tuple_len / sizeof(uint32_t)];
> + uint32_t *tmp_tuple = alloca(tuple_len);
This code is in the rte_thash_adjust_tuple() function [1].
I think we could use a constant size array here, making it large enough for what we think would suffice for any realistic purpose.
The function could check the tuple_len parameter at runtime and return an error value if too big for the array.
It could also check the tuple_len parameter, if constant, at build time.
[1]: https://elixir.bootlin.com/dpdk/v24.03/source/lib/hash/rte_thash.c#L768
@@ -771,7 +771,7 @@ struct rte_thash_subtuple_helper *
uint32_t desired_value, unsigned int attempts,
rte_thash_check_tuple_t fn, void *userdata)
{
- uint32_t tmp_tuple[tuple_len / sizeof(uint32_t)];
+ uint32_t *tmp_tuple = alloca(tuple_len);
unsigned int i, j, ret = 0;
uint32_t hash, adj_bits;
const uint8_t *hash_key;