From: Rafal Kozik <rk@semihalf.com>
To: stable@dpdk.org
Cc: mw@semihalf.com, mk@semihalf.com, gtzalik@amazon.com,
evgenys@amazon.com, matua@amazon.com, igorch@amazon.com,
yskoh@mellanox.com, Rafal Kozik <rk@semihalf.com>
Subject: [dpdk-stable] [17.11 2/3] net/ena: check pointer before memset
Date: Fri, 27 Jul 2018 12:39:05 +0200 [thread overview]
Message-ID: <1532687946-14276-3-git-send-email-rk@semihalf.com> (raw)
In-Reply-To: <1532687946-14276-1-git-send-email-rk@semihalf.com>
[ backported from upstream commit 46916aa17d4b2007df8c0454f99ba0ca8b8cb93b ]
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 <rk@semihalf.com>
Acked-by: Michal Krawczyk <mk@semihalf.com>
---
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 accecf5..362741a 100644
--- a/drivers/net/ena/base/ena_plat_dpdk.h
+++ b/drivers/net/ena/base/ena_plat_dpdk.h
@@ -189,10 +189,15 @@ typedef uint64_t dma_addr_t;
snprintf(z_name, sizeof(z_name), \
"ena_alloc_%d", ena_alloc_cnt++); \
mz = rte_memzone_reserve(z_name, size, SOCKET_ID_ANY, 0); \
- 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); \
@@ -207,9 +212,14 @@ typedef uint64_t dma_addr_t;
snprintf(z_name, sizeof(z_name), \
"ena_alloc_%d", ena_alloc_cnt++); \
mz = rte_memzone_reserve(z_name, size, node, 0); \
- 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; \
+ } \
} while (0)
#define ENA_MEM_ALLOC_NODE(dmadev, size, virt, node, dev_node) \
--
2.7.4
next prev parent reply other threads:[~2018-07-27 10:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-27 10:39 [dpdk-stable] [17.11 0/3] Fixes backported to 17.11 Rafal Kozik
2018-07-27 10:39 ` [dpdk-stable] [17.11 1/3] net/ena: set link speed as none Rafal Kozik
2018-07-27 10:39 ` Rafal Kozik [this message]
2018-07-27 10:39 ` [dpdk-stable] [17.11 3/3] net/ena: change memory type Rafal Kozik
2018-07-27 17:15 ` [dpdk-stable] [17.11 0/3] Fixes backported to 17.11 Yongseok Koh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1532687946-14276-3-git-send-email-rk@semihalf.com \
--to=rk@semihalf.com \
--cc=evgenys@amazon.com \
--cc=gtzalik@amazon.com \
--cc=igorch@amazon.com \
--cc=matua@amazon.com \
--cc=mk@semihalf.com \
--cc=mw@semihalf.com \
--cc=stable@dpdk.org \
--cc=yskoh@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).