From 484ad4421a2ed07a94159b0fe92d5135f362c3bf Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 6 May 2022 22:43:44 +0200 Subject: regs: do not assume 16 registers nftnl_regs_alloc() allows for more than 16 registers for future use, replaced hardcoded number of registers. Fixes: b9e00458b9f3 ("src: add dynamic register allocation infrastructure") Signed-off-by: Pablo Neira Ayuso --- src/regs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/regs.c b/src/regs.c index 8dd70b3..daedaba 100644 --- a/src/regs.c +++ b/src/regs.c @@ -84,9 +84,9 @@ static void nft_expr_reg_update(struct nftnl_regs *regs, return expr->ops->reg.update(®s->reg[i], expr); } -static int reg_space(int i) +static int reg_space(const struct nftnl_regs *regs, int i) { - return sizeof(uint32_t) * 16 - sizeof(uint32_t) * i; + return sizeof(uint32_t) * regs->num_regs - sizeof(uint32_t) * i; } struct nftnl_reg_ctx { @@ -98,7 +98,7 @@ struct nftnl_reg_ctx { static void register_track(struct nftnl_reg_ctx *ctx, const struct nftnl_regs *regs, int i, int len) { - if (ctx->reg >= 0 || regs->reg[i].word || reg_space(i) < len) + if (ctx->reg >= 0 || regs->reg[i].word || reg_space(regs, i) < len) return; if (regs->reg[i].type == NFT_EXPR_UNSPEC) { @@ -183,7 +183,7 @@ uint32_t nftnl_reg_get(struct nftnl_regs *regs, const struct nftnl_expr *expr) type = nftnl_expr_type(expr); len = nftnl_expr_reg_len(expr); - for (i = 0; i < 16; i++) { + for (i = 0; i < regs->num_regs; i++) { register_track(&ctx, regs, i, len); if (!nftnl_expr_reg_cmp(regs, expr, i)) @@ -215,7 +215,7 @@ uint32_t nftnl_reg_get_scratch(struct nftnl_regs *regs, uint32_t len) }; int i; - for (i = 0; i < 16; i++) + for (i = 0; i < regs->num_regs; i++) register_track(&ctx, regs, i, len); register_evict(&ctx); -- cgit v1.2.3