I have no idea why, but the test and branch in odp_actions_add() has always
bugged me. This commit eliminates it.
odp_actions_add(struct odp_actions *actions, uint16_t type)
{
union odp_action *a;
- if (actions->n_actions < MAX_ODP_ACTIONS) {
- a = &actions->actions[actions->n_actions++];
- } else {
- COVERAGE_INC(odp_overflow);
- actions->n_actions = MAX_ODP_ACTIONS + 1;
- a = &actions->actions[MAX_ODP_ACTIONS - 1];
- }
+ size_t idx;
+
+ idx = actions->n_actions++ & (MAX_ODP_ACTIONS - 1);
+ a = &actions->actions[idx];
memset(a, 0, sizeof *a);
a->type = type;
return a;
#include <stdint.h>
#include "openflow/openflow.h"
#include "openvswitch/datapath-protocol.h"
+#include "util.h"
struct ds;
* memory, so there is no point in allocating more than that. */
enum { MAX_ODP_ACTIONS = 4096 / sizeof(union odp_action) };
+/* odp_actions_add() assumes that MAX_ODP_ACTIONS is a power of 2. */
+BUILD_ASSERT_DECL(IS_POW2(MAX_ODP_ACTIONS));
+
struct odp_actions {
size_t n_actions;
union odp_action actions[MAX_ODP_ACTIONS];
*nf_output_iface = ctx.nf_output_iface;
}
if (odp_actions_overflow(out)) {
+ COVERAGE_INC(odp_overflow);
odp_actions_init(out);
return ofp_mkerr(OFPET_BAD_ACTION, OFPBAC_TOO_MANY);
}