DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] raw/ioat: Check for the NULL pointer after calling malloc
@ 2022-06-27 17:52 835703180
  2022-07-05 10:14 ` Bruce Richardson
  2022-07-05 19:43 ` Thomas Monjalon
  0 siblings, 2 replies; 4+ messages in thread
From: 835703180 @ 2022-06-27 17:52 UTC (permalink / raw)
  To: bruce.richardson; +Cc: dev, Shiqi Liu

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..8ab4ed5885 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] raw/ioat: Check for the NULL pointer after calling malloc
  2022-06-27 17:52 [PATCH] raw/ioat: Check for the NULL pointer after calling malloc 835703180
@ 2022-07-05 10:14 ` Bruce Richardson
  2022-07-05 19:43 ` Thomas Monjalon
  1 sibling, 0 replies; 4+ messages in thread
From: Bruce Richardson @ 2022-07-05 10:14 UTC (permalink / raw)
  To: 835703180; +Cc: dev

On Tue, Jun 28, 2022 at 01:52:26AM +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>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] raw/ioat: Check for the NULL pointer after calling malloc
  2022-06-27 17:52 [PATCH] raw/ioat: Check for the NULL pointer after calling malloc 835703180
  2022-07-05 10:14 ` Bruce Richardson
@ 2022-07-05 19:43 ` Thomas Monjalon
  2022-07-06  9:05   ` Bruce Richardson
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Monjalon @ 2022-07-05 19:43 UTC (permalink / raw)
  To: Shiqi Liu; +Cc: bruce.richardson, dev

27/06/2022 19:52, 835703180@qq.com:
> 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>
> ---
> --- 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?




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] raw/ioat: Check for the NULL pointer after calling malloc
  2022-07-05 19:43 ` Thomas Monjalon
@ 2022-07-06  9:05   ` Bruce Richardson
  0 siblings, 0 replies; 4+ messages in thread
From: Bruce Richardson @ 2022-07-06  9:05 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: Shiqi Liu, dev

On Tue, Jul 05, 2022 at 09:43:34PM +0200, Thomas Monjalon wrote:
> 27/06/2022 19:52, 835703180@qq.com:
> > 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>
> > ---
> > --- 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-06  9:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27 17:52 [PATCH] raw/ioat: Check for the NULL pointer after calling malloc 835703180
2022-07-05 10:14 ` Bruce Richardson
2022-07-05 19:43 ` Thomas Monjalon
2022-07-06  9:05   ` Bruce Richardson

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).