There's no reason to allocate the bals[] array on the stack here, since
this is not on any fast-path.
As an alternative, we could limit the number of interfaces on a single
bond to some reasonable maximum, such as 8 or 32, but this commit's change
is simpler.
static void
bond_rebalance_port(struct port *port)
{
- struct slave_balance bals[DP_MAX_PORTS];
+ struct slave_balance *bals;
size_t n_bals;
struct bond_entry *hashes[BOND_MASK + 1];
struct slave_balance *b, *from, *to;
* become contiguous in memory, and then we point each 'hashes' members of
* a slave_balance structure to the start of a contiguous group. */
n_bals = port->n_ifaces;
+ bals = xmalloc(n_bals * sizeof *bals);
for (b = bals; b < &bals[n_bals]; b++) {
b->iface = port->ifaces[b - bals];
b->tx_bytes = 0;
while (!bals[n_bals - 1].iface->enabled) {
n_bals--;
if (!n_bals) {
- return;
+ goto exit;
}
}
for (e = &port->bond_hash[0]; e <= &port->bond_hash[BOND_MASK]; e++) {
e->tx_bytes /= 2;
}
+
+exit:
+ free(bals);
}
static void