From patchwork Wed Aug 29 00:46:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 963182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 420RlC1sFdz9rvt for ; Wed, 29 Aug 2018 10:46:30 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 970A3BE6; Wed, 29 Aug 2018 00:46:27 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id AA9A3BB6 for ; Wed, 29 Aug 2018 00:46:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 0D6B512E for ; Wed, 29 Aug 2018 00:46:25 +0000 (UTC) X-Originating-IP: 76.21.1.228 Received: from localhost.localdomain (unknown [76.21.1.228]) (Authenticated sender: jpettit@ovn.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 43074E0002 for ; Wed, 29 Aug 2018 00:46:22 +0000 (UTC) From: Justin Pettit To: dev@openvswitch.org Date: Tue, 28 Aug 2018 17:46:13 -0700 Message-Id: <20180829004614.129668-1-jpettit@ovn.org> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 1/2] dpif-netdev: Don't check if xcalloc() failed when creating meter. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org xcalloc() can't return null. Signed-off-by: Justin Pettit Acked-by: Flavio Leitner Acked-by: Ben Pfaff --- lib/dpif-netdev.c | 64 +++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 807a462503ee..8b0b3745860b 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -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