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 6A97AA0597; Wed, 8 Apr 2020 10:30:00 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C31151C0B6; Wed, 8 Apr 2020 10:29:32 +0200 (CEST) Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by dpdk.org (Postfix) with ESMTP id AE1FC1C00D for ; Wed, 8 Apr 2020 10:29:28 +0200 (CEST) Received: by mail-lj1-f193.google.com with SMTP id 142so2122184ljj.7 for ; Wed, 08 Apr 2020 01:29:28 -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=/KxbpCL3IXWW8qCiFu9QpdXKCLKmVd0eih2DDTSlqdo=; b=1GiYpVGbfGnqb6rR9Sf09PNpPCW0sDxd0wV3Cn6zNJKbkbGF4EGbfmI8hk1dN9dORQ Whdj8d9xdg6w6G40rNHc5BYn389ERIKNrJCsizzFMZTsrBfCEy5YZgGc58LWRNEfDhpH FiovHGMl9VdtCgO6IIoLgebd2V0iXfs69XWzrix4JKtmgiAeK1TNdrMh+a8154Agml9m eS2GZg7oukqrN5HS+w/iNrICOYEImmOtLz6bOo7NTQDD7F+NCmwl9+p5CGTM5b3Ih+Xj ewXRaxeS5drkLocOPaF7QgxujDND2mRyzQ7xx83kBHK/40FGDTq5vhrt51GfS8oG6hpx C5yA== 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=/KxbpCL3IXWW8qCiFu9QpdXKCLKmVd0eih2DDTSlqdo=; b=PGIMnknBs4YQWjpbjIT7uvfORiNkSuyzHkiZqdOs8l/ErKFv8arHox/hSVra+CG4vn uAQrI/uNX994KAqu8tF+oXhbmp+g3gdrppmSwwO+2LQ1o5T2ThuV+Jge3oryLlNW8iyu j4HtsRC5jC8su8zS3TPceKET0vqYAJDZhYobDSK0NYope1UrP/XNSygahHM1Wz4J1j5L l6YdXKD1Zdk5mdbIWwfPCSGGTh2fB6yfpgOucLVzcPB3SxDhyqOMbBR1sJc45ZUniG/c 0SsgqrivSmy+5hEk3DZOW5E1g52fb6rwsDtNBUUbzTeR+2UCIkuo8w3Twj1BgtZfwJ4N briw== X-Gm-Message-State: AGi0PuZr8qADqCZBaN19F3wHfCOPbd2ieb4WEcW3yRg7BGvxs6v3dRsy xC44IDv8b9VEkcoSyvVHiHeFRAPoygQ= X-Google-Smtp-Source: APiQypJx6K2Y47DxFDaabpvOcRLVUXy3sn4zuw/lOUzpRnGSQF1DkaIM2Fvj3oTHpaMWda3T5efxYA== X-Received: by 2002:a2e:b4f1:: with SMTP id s17mr4135965ljm.283.1586334568109; Wed, 08 Apr 2020 01:29:28 -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 e8sm765685lja.3.2020.04.08.01.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 01:29:27 -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, ferruh.yigit@intel.com, arybchenko@solarflare.com, stable@dpdk.org, Michal Krawczyk Date: Wed, 8 Apr 2020 10:28:54 +0200 Message-Id: <20200408082921.31000-4-mk@semihalf.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200408082921.31000-1-mk@semihalf.com> References: <20200408082921.31000-1-mk@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 03/30] 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 70261bdbc6..4b8fe017dd 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