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 947FDA0589; Fri, 27 Mar 2020 11:29:42 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D2CA11C0B9; Fri, 27 Mar 2020 11:29:18 +0100 (CET) Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by dpdk.org (Postfix) with ESMTP id 4E1841C0AB for ; Fri, 27 Mar 2020 11:29:14 +0100 (CET) Received: by mail-lf1-f68.google.com with SMTP id j11so7403719lfg.4 for ; Fri, 27 Mar 2020 03:29:14 -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=TXAQoH2S2mfVVP4wiPJ9u0Pb0qqA66VEkckL/wFdoDg12O/P3PTIhgzthctrZIYaOR KdU9lbvuCpyC5J4XMjiCyfhbMP1ZEa/VJiMl7Afd6lItI5XthDQBrfIzdhH6oLpzOSbQ v/zcq+U1AUD8syYCfIO1ne7zmPb1naqXrALOrl2MenS/k7aAu+o++JhrY0jjaFaDZxq/ ILwp/DRTeMQiGD8xuptzJcWb+LJ8iSu8pGFsbRKGo2RrzIxp+urH/ja2cqzFGerUHbNs fkMI9PqwK0rDFGY6gmc8eAQdan3BhsIHDpQewcz0afX6hX/r+dVtjeNirmVnjJyMz14y dzDg== 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=uWec20EWua4W+qOJsj2BJSVBBmQg3siORZla3qh6gDuPhQq9XCIIjYr9NYjHdlVThx nNuASYsM+uAmgOCDyF1NJY9H9eIV5OL2INHXkCLrD8tPXzJaPQ6oBNOa5VDcwasH5B9b RvOa2Oyg6SiOjg3ORZF5IltmIu/iy11yVZuLryq5nxHrhdQ+IPOFcKyDu+a1SbWaKUPm iBWqGYGZd/Q9U4cwjxbAi3iJRean+74f3gA1Xxyy2AqywMQMak6OFO+/pXzzQxJYN8r1 Py/OP5ZXsPlUa3M1o23K1El1Muv94K6EK1LBDGXYxmhLaUv8bwm1r+ZXbB/D4HreQgcy GHKw== X-Gm-Message-State: ANhLgQ25XcQslmPhu1z75dQsjRlOwdWjkFjdcGaScp0/Aq3qxNuzrcAe Iau+jSxVVcxOrJUKK61Fi2BYr6sQIyc= X-Google-Smtp-Source: ADFU+vsUWyceyu2KfAeR8mg13QVGKWALo/pI620VjnmwSCwNyGSfjmPrC+26Qn6e1hKHxFFHjiCf9A== X-Received: by 2002:a05:6512:6d4:: with SMTP id u20mr8936533lff.209.1585304953678; Fri, 27 Mar 2020 03:29:13 -0700 (PDT) Received: from localhost.localdomain (193-106-246-138.noc.fibertech.net.pl. [193.106.246.138]) by smtp.gmail.com with ESMTPSA id i11sm2789587lfo.84.2020.03.27.03.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2020 03:29:12 -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: Fri, 27 Mar 2020 11:17:57 +0100 Message-Id: <20200327101823.12646-4-mk@semihalf.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200327101823.12646-1-mk@semihalf.com> References: <20200327101823.12646-1-mk@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 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