From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7EBEBA057B; Wed, 1 Apr 2020 16:22:09 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1F12E1BEC0; Wed, 1 Apr 2020 16:21:44 +0200 (CEST) Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) by dpdk.org (Postfix) with ESMTP id D05B51BEB5 for ; Wed, 1 Apr 2020 16:21:42 +0200 (CEST) Received: by mail-lf1-f65.google.com with SMTP id w145so1450284lff.3 for ; Wed, 01 Apr 2020 07:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gTIPi4Ugjdgbn6lIzbN7KYyY2v2TxtQAFwVJtkB2Hh8=; b=lTR6E8iF1FZAAlTCoAF0f5mosGj9qw9GqAjYIhwq7MtHTgta62GTzCCYvPUR2AMfLH zDo9YSzETr81CjDJPZQmRWNY/seBmOE0ujmqParR2BlSEA6jX0NVMALgAhtbgL38tqFe LsTOmDYue3KmeGzyt0zZLj/bmTVBzVBflplKozwdwZBx65GdWEAoCRdEVdzsxv5+19wq //3Bbto6qU22n9xLEeYUupA1n4jJTNt7E24amVH8CrzzUkQlveGqZfG4u7dTSW/ZRtwu aj39UxqfG4TZSgpf3AYh0zUVhlJBojLpx94Ym6xgGIdIVjyKrIJZke0GbQYsTNfXm0vZ AzWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gTIPi4Ugjdgbn6lIzbN7KYyY2v2TxtQAFwVJtkB2Hh8=; b=smNrrJsmnZtwalRFeMQOrRO6JmAc5xbtqCuJn/YKa2N8DpC3Q7g768BK6lI98Ig+o7 BoPauG9Kkzf19I2L3JxfQCHrsSqbO2sCweBpF+lR5RQ+hd7PRfPY0ZB0HuGiAQy9yd7U Osuh+FrvroysTYmN6MDxufBpzV7WmwCkaDd6E4GJCgjdVzsrUFIU0onuY402oCgWn5FM 7GyQ45foVRjh9ChhUoec7kHjnwu64axtVpXWXTj+EI5e3JmF1wScp4Ri5uQvNKgrZCJL wZ+kQf+EV/zVfogqsHCpkDyAyLzTM/B2Wl4bu7KhiVSQ5SMEV3LANzOscIz+MWUFxKY1 Lc6g== X-Gm-Message-State: AGi0PuZOubEAON0sldWKpwl9chn9YvM7eG+hkAoHg9FsXxypgOfYK6t8 slc75z2E67w84tlcUAJrzvq+MVeFbhc= X-Google-Smtp-Source: APiQypKWgDAvmcW0jotpKZZ7/0DdGBI2qCSGnx62w419VhWLM2IylHl52vBc2QJfJ/KlFXXcrrq6bg== X-Received: by 2002:a05:6512:695:: with SMTP id t21mr3511260lfe.158.1585750901113; Wed, 01 Apr 2020 07:21:41 -0700 (PDT) Received: from mkPC.semihalf.local (193-106-246-138.noc.fibertech.net.pl. [193.106.246.138]) by smtp.gmail.com with ESMTPSA id r21sm1435961ljp.29.2020.04.01.07.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 07:21:40 -0700 (PDT) From: Michal Krawczyk To: dev@dpdk.org Cc: mw@semihalf.com, mba@semihalf.com, gtzalik@amazon.com, evgenys@amazon.com, igorch@amazon.com, stable@dpdk.org, Michal Krawczyk Date: Wed, 1 Apr 2020 16:21:01 +0200 Message-Id: <20200401142127.13715-4-mk@semihalf.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401142127.13715-1-mk@semihalf.com> References: <20200401142127.13715-1-mk@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 03/29] net/ena/base: prevent allocation of 0-sized memory X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Igor Chauskin rte_memzone_reserve() will reserve the biggest contiguous memzone available if received 0 as size param. Fixes: 9ba7981ec992 ("ena: add communication layer for DPDK") Cc: stable@dpdk.org Signed-off-by: Igor Chauskin Reviewed-by: Michal Krawczyk Reviewed-by: Guy Tzalik --- drivers/net/ena/base/ena_plat_dpdk.h | 29 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h index 192bbaefcf..793ba8a957 100644 --- a/drivers/net/ena/base/ena_plat_dpdk.h +++ b/drivers/net/ena/base/ena_plat_dpdk.h @@ -184,15 +184,18 @@ extern rte_atomic32_t ena_alloc_cnt; #define ENA_MEM_ALLOC_COHERENT(dmadev, size, virt, phys, handle) \ do { \ - const struct rte_memzone *mz; \ - char z_name[RTE_MEMZONE_NAMESIZE]; \ + const struct rte_memzone *mz = NULL; \ ENA_TOUCH(dmadev); ENA_TOUCH(handle); \ - snprintf(z_name, sizeof(z_name), \ + if (size > 0) { \ + char z_name[RTE_MEMZONE_NAMESIZE]; \ + snprintf(z_name, sizeof(z_name), \ "ena_alloc_%d", \ rte_atomic32_add_return(&ena_alloc_cnt, 1)); \ - mz = rte_memzone_reserve(z_name, size, SOCKET_ID_ANY, \ - RTE_MEMZONE_IOVA_CONTIG); \ - handle = mz; \ + mz = rte_memzone_reserve(z_name, size, \ + SOCKET_ID_ANY, \ + RTE_MEMZONE_IOVA_CONTIG); \ + handle = mz; \ + } \ if (mz == NULL) { \ virt = NULL; \ phys = 0; \ @@ -210,15 +213,17 @@ extern rte_atomic32_t ena_alloc_cnt; #define ENA_MEM_ALLOC_COHERENT_NODE( \ dmadev, size, virt, phys, mem_handle, node, dev_node) \ do { \ - const struct rte_memzone *mz; \ - char z_name[RTE_MEMZONE_NAMESIZE]; \ + const struct rte_memzone *mz = NULL; \ ENA_TOUCH(dmadev); ENA_TOUCH(dev_node); \ - snprintf(z_name, sizeof(z_name), \ + if (size > 0) { \ + char z_name[RTE_MEMZONE_NAMESIZE]; \ + snprintf(z_name, sizeof(z_name), \ "ena_alloc_%d", \ - rte_atomic32_add_return(&ena_alloc_cnt, 1)); \ - mz = rte_memzone_reserve(z_name, size, node, \ + rte_atomic32_add_return(&ena_alloc_cnt, 1)); \ + mz = rte_memzone_reserve(z_name, size, node, \ RTE_MEMZONE_IOVA_CONTIG); \ - mem_handle = mz; \ + mem_handle = mz; \ + } \ if (mz == NULL) { \ virt = NULL; \ phys = 0; \ -- 2.20.1