Linux-mediatek Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: core: buffer: avoid NULL pointer dereferrence
@ 2016-04-08  9:08 Chunfeng Yun
       [not found] ` <1460106483-24793-1-git-send-email-chunfeng.yun-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Chunfeng Yun @ 2016-04-08  9:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Chunfeng Yun, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

NULL pointer dereferrence will happen when class driver
wants to allocate zero length buffer and pool_max[0]
can't be used, so skip reserved pool in this case.

Signed-off-by: Chunfeng Yun <chunfeng.yun-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
---
 drivers/usb/core/buffer.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index 2741566..c8f958b 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -131,7 +131,7 @@ void *hcd_buffer_alloc(
 	}
 
 	for (i = 0; i < HCD_BUFFER_POOLS; i++) {
-		if (size <= pool_max[i])
+		if (pool_max[i] && size <= pool_max[i])
 			return dma_pool_alloc(hcd->pool[i], mem_flags, dma);
 	}
 	return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags);
@@ -158,7 +158,7 @@ void hcd_buffer_free(
 	}
 
 	for (i = 0; i < HCD_BUFFER_POOLS; i++) {
-		if (size <= pool_max[i]) {
+		if (pool_max[i] && size <= pool_max[i]) {
 			dma_pool_free(hcd->pool[i], addr, dma);
 			return;
 		}
-- 
1.7.9.5

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

end of thread, other threads:[~2016-04-27  1:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-08  9:08 [PATCH] usb: core: buffer: avoid NULL pointer dereferrence Chunfeng Yun
     [not found] ` <1460106483-24793-1-git-send-email-chunfeng.yun-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2016-04-08 14:07   ` Greg Kroah-Hartman
     [not found]     ` <20160408140701.GA3547-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2016-04-08 15:21       ` Alan Stern
2016-04-26 23:11         ` Greg Kroah-Hartman
     [not found]           ` <20160426231115.GB23273-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2016-04-27  1:32             ` chunfeng yun
2016-04-11  3:01     ` chunfeng yun
2016-04-11  5:07       ` Felipe Balbi
2016-04-11  7:16         ` chunfeng yun
2016-04-11  8:24           ` Felipe Balbi
2016-04-11 14:44           ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox