From: 835703180@qq.com
To: pbhagavatula@marvell.com
Cc: dev@dpdk.org, Shiqi Liu <835703180@qq.com>
Subject: [PATCH] lib: Check for the NULL pointer after calling malloc
Date: Thu, 7 Jul 2022 17:23:45 +0800 [thread overview]
Message-ID: <tencent_7A58A935B4A00F49E866CC56C6D08D05DD0A@qq.com> (raw)
From: Shiqi Liu <835703180@qq.com>
As the possible failure of the malloc(), the not_checked and
checked could be NULL pointer.
Therefore, it should be better to check it in order to avoid
the dereference of the NULL pointer.
Fixes: fa8054c8c88 ("lib/node: add ethdev control")
Signed-off-by: Shiqi Liu <835703180@qq.com>
---
lib/node/ethdev_ctrl.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/node/ethdev_ctrl.c b/lib/node/ethdev_ctrl.c
index 5294607619..eef0785c21 100644
--- a/lib/node/ethdev_ctrl.c
+++ b/lib/node/ethdev_ctrl.c
@@ -75,6 +75,9 @@ rte_node_eth_config(struct rte_node_ethdev_config *conf, uint16_t nb_confs,
/* Add it to list of ethdev rx nodes for lookup */
elem = malloc(sizeof(ethdev_rx_node_elem_t));
+ if (elem == NULL) {
+ return -ENOMEM;
+ }
memset(elem, 0, sizeof(ethdev_rx_node_elem_t));
elem->ctx.port_id = port_id;
elem->ctx.queue_id = j;
--
2.35.1.windows.2
next reply other threads:[~2022-07-07 9:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-07 9:23 835703180 [this message]
2022-10-10 15:46 ` Thomas Monjalon
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=tencent_7A58A935B4A00F49E866CC56C6D08D05DD0A@qq.com \
--to=835703180@qq.com \
--cc=dev@dpdk.org \
--cc=pbhagavatula@marvell.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).