[PATCH V2] raw/ioat: Check for the NULL pointer after calling malloc
835703180 at qq.com
835703180 at qq.com
Wed Jul 6 08:55:48 CEST 2022
From: Shiqi Liu <835703180 at 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 at 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
More information about the dev
mailing list