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 */
|
||||
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;
|
||||
meter->flags = config->flags;
|
||||
meter->n_bands = config->n_bands;
|
||||
meter->max_delta_t = 0;
|
||||
meter->used = time_usec();
|
||||
|
||||
/* 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;
|
||||
}
|
||||
/* set up bands */
|
||||
for (i = 0; i < config->n_bands; ++i) {
|
||||
uint32_t band_max_delta_t;
|
||||
|
||||
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;
|
||||
}
|
||||
/* 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
|
||||
|
Reference in New Issue
Block a user