Skip to content

Commit

Permalink
dpif-netdev: Don't check if xcalloc() failed when creating meter.
Browse files Browse the repository at this point in the history
xcalloc() can't return null.

Signed-off-by: Justin Pettit <[email protected]>
Acked-by: Flavio Leitner <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
justinpettit committed Sep 4, 2018
1 parent e9b33ad commit d0db81e
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -5199,44 +5199,42 @@ dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id meter_id,
/* Allocate meter */
meter = xzalloc(sizeof *meter
+ config->n_bands * sizeof(struct dp_meter_band));
if (meter) {
meter->flags = config->flags;
meter->n_bands = config->n_bands;
meter->max_delta_t = 0;
meter->used = time_usec();

/* set up bands */
for (i = 0; i < config->n_bands; ++i) {
uint32_t band_max_delta_t;

/* Set burst size to a workable value if none specified. */
if (config->bands[i].burst_size == 0) {
config->bands[i].burst_size = config->bands[i].rate;
}

meter->bands[i].up = config->bands[i];
/* Convert burst size to the bucket units: */
/* pkts => 1/1000 packets, kilobits => bits. */
meter->bands[i].up.burst_size *= 1000;
/* Initialize bucket to empty. */
meter->bands[i].bucket = 0;

/* Figure out max delta_t that is enough to fill any bucket. */
band_max_delta_t
= meter->bands[i].up.burst_size / meter->bands[i].up.rate;
if (band_max_delta_t > meter->max_delta_t) {
meter->max_delta_t = band_max_delta_t;
}
meter->flags = config->flags;
meter->n_bands = config->n_bands;
meter->max_delta_t = 0;
meter->used = time_usec();

/* set up bands */
for (i = 0; i < config->n_bands; ++i) {
uint32_t band_max_delta_t;

/* Set burst size to a workable value if none specified. */
if (config->bands[i].burst_size == 0) {
config->bands[i].burst_size = config->bands[i].rate;
}

meter_lock(dp, mid);
dp_delete_meter(dp, mid); /* Free existing meter, if any */
dp->meters[mid] = meter;
meter_unlock(dp, mid);
meter->bands[i].up = config->bands[i];
/* Convert burst size to the bucket units: */
/* pkts => 1/1000 packets, kilobits => bits. */
meter->bands[i].up.burst_size *= 1000;
/* Initialize bucket to empty. */
meter->bands[i].bucket = 0;

return 0;
/* Figure out max delta_t that is enough to fill any bucket. */
band_max_delta_t
= meter->bands[i].up.burst_size / meter->bands[i].up.rate;
if (band_max_delta_t > meter->max_delta_t) {
meter->max_delta_t = band_max_delta_t;
}
}
return ENOMEM;

meter_lock(dp, mid);
dp_delete_meter(dp, mid); /* Free existing meter, if any */
dp->meters[mid] = meter;
meter_unlock(dp, mid);

return 0;
}

static int
Expand Down

0 comments on commit d0db81e

Please sign in to comment.