[V2] raw/ioat: Check for the NULL pointer after calling malloc
Checks
Commit Message
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(+)
Comments
On Wed, Jul 06, 2022 at 02:55:48PM +0800, 835703180@qq.com wrote:
> 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>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
06/07/2022 11:07, Bruce Richardson:
> On Wed, Jul 06, 2022 at 02:55:48PM +0800, 835703180@qq.com wrote:
> > 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>
> > ---
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Applied, thanks.
@@ -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);