浏览代码

usb: core: buffer: avoid NULL pointer dereferrence

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

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Chunfeng Yun 9 年之前
父节点
当前提交
f5e6253fe6
共有 1 个文件被更改,包括 3 次插入0 次删除
  1. 3 0
      drivers/usb/core/buffer.c

+ 3 - 0
drivers/usb/core/buffer.c

@@ -122,6 +122,9 @@ void *hcd_buffer_alloc(
 	struct usb_hcd		*hcd = bus_to_hcd(bus);
 	struct usb_hcd		*hcd = bus_to_hcd(bus);
 	int			i;
 	int			i;
 
 
+	if (size == 0)
+		return NULL;
+
 	/* some USB hosts just use PIO */
 	/* some USB hosts just use PIO */
 	if (!IS_ENABLED(CONFIG_HAS_DMA) ||
 	if (!IS_ENABLED(CONFIG_HAS_DMA) ||
 	    (!bus->controller->dma_mask &&
 	    (!bus->controller->dma_mask &&