DPDK patches and discussions
 help / color / mirror / Atom feed
From: 835703180@qq.com
To: bruce.richardson@intel.com
Cc: dev@dpdk.org, Shiqi Liu <835703180@qq.com>
Subject: [PATCH V2] raw/ioat: Check for the NULL pointer after calling malloc
Date: Wed,  6 Jul 2022 14:55:48 +0800	[thread overview]
Message-ID: <tencent_3233F62A07E91482DCAD2C1AA4D01B241409@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: b7aaf417f93 ("raw/ioat: add bus driver for device scanning automatically")
Signed-off-by: Shiqi Liu <835703180@qq.com>
---
 drivers/raw/ioat/idxd_bus.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/raw/ioat/idxd_bus.c b/drivers/raw/ioat/idxd_bus.c
index 539f51b1b1..ba2bbe0f7e 100644
--- a/drivers/raw/ioat/idxd_bus.c
+++ b/drivers/raw/ioat/idxd_bus.c
@@ -301,6 +301,10 @@ dsa_scan(void)
 		IOAT_PMD_DEBUG("%s(): found %s/%s", __func__, path, wq->d_name);
 
 		dev = malloc(sizeof(*dev));
+		if (dev == NULL) {
+			closedir(dev_dir);
+			return -ENOMEM;
+		}
 		if (dsa_addr_parse(wq->d_name, &dev->addr) < 0) {
 			IOAT_PMD_ERR("Error parsing WQ name: %s", wq->d_name);
 			free(dev);
-- 
2.35.1.windows.2


             reply	other threads:[~2022-07-06  6:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06  6:55 835703180 [this message]
2022-07-06  9:07 ` Bruce Richardson
2022-10-10 15:48   ` 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_3233F62A07E91482DCAD2C1AA4D01B241409@qq.com \
    --to=835703180@qq.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /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).