Skip to content

Commit

Permalink
net/ena/base: limit exponential backoff
Browse files Browse the repository at this point in the history
[ upstream commit 4b378679c88ff231b97b71aaedc2d424e82f1aba ]

Limit the value of the exponent used for this backoff
at (1<<16) to prevent it from reaching to an excessive
value (1<<32) or potentially even overflowing.
In addition, for uniformity and readability purposes,
the min/max parameter in the calls of ENA_MIN32 and
ENA_MAX32 macros was changed to be first.

Fixes: 0c84e04 ("net/ena/base: make delay exponential in polling functions")

Signed-off-by: Shai Brandes <shaibran@amazon.com>
Reviewed-by: Amit Bernstein <amitbern@amazon.com>
  • Loading branch information
shaibran authored and kevintraynor committed Apr 3, 2024
1 parent b063b49 commit cb98b1b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/net/ena/base/ena_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#define ENA_REGS_ADMIN_INTR_MASK 1

#define ENA_MAX_BACKOFF_DELAY_EXP 16U

#define ENA_MIN_ADMIN_POLL_US 100

#define ENA_MAX_ADMIN_POLL_US 5000
Expand Down Expand Up @@ -539,8 +541,9 @@ static int ena_com_comp_status_to_errno(struct ena_com_admin_queue *admin_queue,

static void ena_delay_exponential_backoff_us(u32 exp, u32 delay_us)
{
exp = ENA_MIN32(ENA_MAX_BACKOFF_DELAY_EXP, exp);
delay_us = ENA_MAX32(ENA_MIN_ADMIN_POLL_US, delay_us);
delay_us = ENA_MIN32(delay_us * (1U << exp), ENA_MAX_ADMIN_POLL_US);
delay_us = ENA_MIN32(ENA_MAX_ADMIN_POLL_US, delay_us * (1U << exp));
ENA_USLEEP(delay_us);
}

Expand Down

0 comments on commit cb98b1b

Please sign in to comment.