From patchwork Wed Apr 27 16:13:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoltan Kiss X-Patchwork-Id: 66802 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2282854qge; Wed, 27 Apr 2016 09:21:15 -0700 (PDT) X-Received: by 10.50.246.14 with SMTP id xs14mr27779414igc.47.1461774075859; Wed, 27 Apr 2016 09:21:15 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id n88si10712602ioo.185.2016.04.27.09.21.15; Wed, 27 Apr 2016 09:21:15 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 42BD961563; Wed, 27 Apr 2016 16:21:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 4DC586157C; Wed, 27 Apr 2016 16:16:59 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 2D396611F3; Wed, 27 Apr 2016 16:15:48 +0000 (UTC) Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by lists.linaro.org (Postfix) with ESMTPS id 26B97611FB for ; Wed, 27 Apr 2016 16:14:21 +0000 (UTC) Received: by mail-wm0-f42.google.com with SMTP id u206so56932444wme.1 for ; Wed, 27 Apr 2016 09:14:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=E1e8EFDvPKsNOO3WXm+fDXojCzylEecIEqaS3iatKAo=; b=Z+BBqyL1TUe4McPNI89P4oOv+gQbFvwh7TJ5/CYzJam1Guz02DM16SjD+Q7TWiMLXk GDnQK8KJflEaKeicfDSh0/82Au1hJpFxuOOO43/Z1EPlb3iWaqzuXmytVm5Ee2pMTYrI I/5wstlgyhMyXoiqClTB2QloDBK3DStR9qYjuR8xgsi1EsE+2Gyav2ZnGbF4Okrm/v/3 mRqyO5x7JJagLGXn9cgLZrIPmCEFapRb7vU8W79t0VgQ+nY6CngeOXVik+lNjMjy1nqp KRsNUQx67VT2tJ+mq9njS3DG2OWvMF5a9ZpnZntMBgtfDiQxPgKu8eoG5SdRtyOxu55m qMQQ== X-Gm-Message-State: AOPr4FUr8w/v4dNRC7SJr/R4Oad7cJwra1w2pn/pEQWbU+S+87jtpTanjcpqpllIAwwUZm18nj4= X-Received: by 10.194.57.168 with SMTP id j8mr10139982wjq.43.1461773659912; Wed, 27 Apr 2016 09:14:19 -0700 (PDT) Received: from localhost.localdomain ([195.11.233.227]) by smtp.googlemail.com with ESMTPSA id f135sm9246636wmf.22.2016.04.27.09.14.19 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 27 Apr 2016 09:14:19 -0700 (PDT) From: Zoltan Kiss To: lng-odp@lists.linaro.org Date: Wed, 27 Apr 2016 17:13:40 +0100 Message-Id: <1461773622-26062-2-git-send-email-zoltan.kiss@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461773622-26062-1-git-send-email-zoltan.kiss@linaro.org> References: <1461773622-26062-1-git-send-email-zoltan.kiss@linaro.org> X-Topics: Classification patch Cc: petri.savolainen@nokia.com Subject: [lng-odp] [PATCH 1/3] linux-generic: classification: release the packet as soon as an error happens X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Move release to _odp_packet_classifier(), because caller has no way to know if new_pkt were allocated. In that case there would be a double free on pkt, and new_pkt would be leaked. Signed-off-by: Zoltan Kiss --- platform/linux-generic/odp_classification.c | 21 ++++++++++++--------- platform/linux-generic/pktio/loop.c | 1 - 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c index 3a18a78..a1466fd 100644 --- a/platform/linux-generic/odp_classification.c +++ b/platform/linux-generic/odp_classification.c @@ -734,22 +734,20 @@ int _odp_packet_classifier(pktio_entry_t *entry, odp_packet_t pkt) odp_packet_t new_pkt; uint8_t *pkt_addr; - if (entry == NULL) + if (entry == NULL) { + odp_packet_free(pkt); return -1; + } pkt_hdr = odp_packet_hdr(pkt); pkt_addr = odp_packet_data(pkt); /* Matching PMR and selecting the CoS for the packet*/ cos = pktio_select_cos(entry, pkt_addr, pkt_hdr); - if (cos == NULL) - return -1; - - if (cos->s.pool == NULL) - return -1; - - if (cos->s.queue == NULL) + if (cos == NULL || cos->s.queue == NULL || cos->s.pool == NULL) { + odp_packet_free(pkt); return -1; + } if (odp_packet_pool(pkt) != cos->s.pool->s.pool_hdl) { new_pkt = odp_packet_copy(pkt, cos->s.pool->s.pool_hdl); @@ -762,7 +760,12 @@ int _odp_packet_classifier(pktio_entry_t *entry, odp_packet_t pkt) /* Enqueuing the Packet based on the CoS */ queue = cos->s.queue; - return queue_enq(queue, odp_buf_to_hdr((odp_buffer_t)new_pkt), 0); + if (queue_enq(queue, odp_buf_to_hdr((odp_buffer_t)new_pkt), 0)) { + odp_packet_free(new_pkt); + return -1; + } else { + return 0; + } } cos_t *pktio_select_cos(pktio_entry_t *entry, const uint8_t *pkt_addr, diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c index f6a8c1d..676e98b 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loop.c @@ -76,7 +76,6 @@ static int loopback_recv(pktio_entry_t *pktio_entry, odp_packet_t pkts[], } else { pktio_entry->s.stats.in_errors += odp_packet_len(pkt); - odp_packet_free(pkt); } } nbr = j;