[PATCH] raw/ioat: Check for the NULL pointer after calling malloc

Bruce Richardson bruce.richardson at intel.com
Wed Jul 6 11:05:47 CEST 2022


On Tue, Jul 05, 2022 at 09:43:34PM +0200, Thomas Monjalon wrote:
> 27/06/2022 19:52, 835703180 at qq.com:
> > 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>
> > ---
> > --- 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;
> 
> Isn't it supposed to be a negative value?
> 
Yes, I missed that on my review. Reading the definition of what the bus
"scan" method is to return it indicates <0 on error.

/Bruce


More information about the dev mailing list