From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) by dpdk.org (Postfix) with ESMTP id DD3281B3F0 for ; Thu, 7 Jun 2018 11:44:17 +0200 (CEST) Received: by mail-lf0-f50.google.com with SMTP id i83-v6so13657396lfh.5 for ; Thu, 07 Jun 2018 02:44:17 -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; bh=SAtXlHMV0FBsEo0Xi1UinCpHnc+YFrmUOsBuiGZuUnk=; b=yrb5W1cvmt2ABxEC7hgN76KSqofkncY8NNqpo+ZI60YRXHLhQn2ZZVeBCedfpDLIUY 0gCgsTUfPcneGblrKfj0SUT3BESRlF0PQnGATRzdARmJJ1hnJ3Lz7J6HRG+ocfngNgiT Gk1Y9mPkFkYVv3ZPZXGJNrKAe+Aa/Ti1lHZU92sBwxFCBTfS3v47MBMNfczqTw5kBAja pc7cUAxGkOR/TNCAARvDV36xrg04x8HFt98mLOpmGQfmgddRTz6v6hHeXXjBYMfiUIlt ocynAbG0kz6g73j/jq2PUCNZSfP5qazfzbnJYnCIExO7hXy2tnSniHrmJr8ct72mnOMo Kjww== 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; bh=SAtXlHMV0FBsEo0Xi1UinCpHnc+YFrmUOsBuiGZuUnk=; b=TqncqVdbeYVUWqhyrNwylv9iotV51UWEItkxgu3/4DUPwRoH0yJPTbjMPi9FYB6qDk 0MK109wD+AaAw4rF5W5ft1SJt+1Q/XTVs+pQgvjoJhrRKLsChBUTba2MQRLIxLwfv38D 1FQIfqrhwXrMaID7QvoW8RyPk7lP6gVJoEC1QmrR6uuk1Tc5GlLSaJLNJong1xSqevUh 69iZ+mwq+03R0wepACjJVlyZJEV5I3EQZXaSgoS0ffN7Bvr15Hj6VdnV86tZoRe3FHaI uKrFwsQiYwhFG9MF5MFMSgMEimfy/8rCvAvizlQLW2vt6fc2lKOmQwKeLO54fD9YjoEz XWcg== X-Gm-Message-State: APt69E17vP7rWEspWQQ9mbVN7TUfDP+8OLo5P8DNY4ie2Mt+jN290hP5 rig9gGFjoHb26KyYQYxSKgeFtQ== X-Google-Smtp-Source: ADUXVKJXpsBLszHnd5HZgBQJnTkT37Jz4bscldVBGZQ1oDuJaGaSj0kU4U3KkcrebibtKcrd4gFHYQ== X-Received: by 2002:a19:c1c1:: with SMTP id r184-v6mr875168lff.51.1528364657566; Thu, 07 Jun 2018 02:44:17 -0700 (PDT) Received: from mkPC.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id p28-v6sm3612368lfh.24.2018.06.07.02.44.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 02:44:15 -0700 (PDT) From: Michal Krawczyk To: Marcin Wojtas , Michal Krawczyk , Guy Tzalik , Evgeny Schemeilin Cc: dev@dpdk.org, matua@amazon.com, Rafal Kozik Date: Thu, 7 Jun 2018 11:43:18 +0200 Message-Id: <20180607094322.14312-23-mk@semihalf.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180607094322.14312-1-mk@semihalf.com> References: <20180607094322.14312-1-mk@semihalf.com> Subject: [dpdk-dev] [PATCH v3 23/27] net/ena: check pointer before memset 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: , X-List-Received-Date: Thu, 07 Jun 2018 09:44:18 -0000 From: Rafal Kozik Need to check if memory allocation succeed before using it. Using memset on NULL pointer cause segfault. Fixes: 9ba7981ec992 ("ena: add communication layer for DPDK") Signed-off-by: Rafal Kozik Acked-by: Michal Krawczyk --- drivers/net/ena/base/ena_plat_dpdk.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h index e2af4ee2c..d30153e92 100644 --- a/drivers/net/ena/base/ena_plat_dpdk.h +++ b/drivers/net/ena/base/ena_plat_dpdk.h @@ -210,10 +210,15 @@ extern uint32_t ena_alloc_cnt; "ena_alloc_%d", ena_alloc_cnt++); \ mz = rte_memzone_reserve(z_name, size, SOCKET_ID_ANY, \ RTE_MEMZONE_IOVA_CONTIG); \ - memset(mz->addr, 0, size); \ - virt = mz->addr; \ - phys = mz->iova; \ handle = mz; \ + if (mz == NULL) { \ + virt = NULL; \ + phys = 0; \ + } else { \ + memset(mz->addr, 0, size); \ + virt = mz->addr; \ + phys = mz->iova; \ + } \ } while (0) #define ENA_MEM_FREE_COHERENT(dmadev, size, virt, phys, handle) \ ({ ENA_TOUCH(size); ENA_TOUCH(phys); \ @@ -230,9 +235,14 @@ extern uint32_t ena_alloc_cnt; "ena_alloc_%d", ena_alloc_cnt++); \ mz = rte_memzone_reserve(z_name, size, node, \ RTE_MEMZONE_IOVA_CONTIG); \ - memset(mz->addr, 0, size); \ - virt = mz->addr; \ - phys = mz->iova; \ + if (mz == NULL) { \ + virt = NULL; \ + phys = 0; \ + } else { \ + memset(mz->addr, 0, size); \ + virt = mz->addr; \ + phys = mz->iova; \ + } \ (void)mem_handle; \ } while (0) -- 2.14.1