mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 14:25:26 +00:00
dpif-netdev: Don't check if xcalloc() failed when creating meter.
xcalloc() can't return null. Signed-off-by: Justin Pettit <jpettit@ovn.org> Acked-by: Flavio Leitner <fbl@sysclose.org> Acked-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
@@ -5199,44 +5199,42 @@ dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id meter_id,
|
|||||||
/* Allocate meter */
|
/* Allocate meter */
|
||||||
meter = xzalloc(sizeof *meter
|
meter = xzalloc(sizeof *meter
|
||||||
+ config->n_bands * sizeof(struct dp_meter_band));
|
+ 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 */
|
meter->flags = config->flags;
|
||||||
for (i = 0; i < config->n_bands; ++i) {
|
meter->n_bands = config->n_bands;
|
||||||
uint32_t band_max_delta_t;
|
meter->max_delta_t = 0;
|
||||||
|
meter->used = time_usec();
|
||||||
|
|
||||||
/* Set burst size to a workable value if none specified. */
|
/* set up bands */
|
||||||
if (config->bands[i].burst_size == 0) {
|
for (i = 0; i < config->n_bands; ++i) {
|
||||||
config->bands[i].burst_size = config->bands[i].rate;
|
uint32_t band_max_delta_t;
|
||||||
}
|
|
||||||
|
|
||||||
meter->bands[i].up = config->bands[i];
|
/* Set burst size to a workable value if none specified. */
|
||||||
/* Convert burst size to the bucket units: */
|
if (config->bands[i].burst_size == 0) {
|
||||||
/* pkts => 1/1000 packets, kilobits => bits. */
|
config->bands[i].burst_size = config->bands[i].rate;
|
||||||
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_lock(dp, mid);
|
meter->bands[i].up = config->bands[i];
|
||||||
dp_delete_meter(dp, mid); /* Free existing meter, if any */
|
/* Convert burst size to the bucket units: */
|
||||||
dp->meters[mid] = meter;
|
/* pkts => 1/1000 packets, kilobits => bits. */
|
||||||
meter_unlock(dp, mid);
|
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
|
static int
|
||||||
|
Reference in New Issue
Block a user