OSDN Git Service

usb: core: buffer: avoid NULL pointer dereferrence
authorChunfeng Yun <chunfeng.yun@mediatek.com>
Thu, 28 Apr 2016 03:42:20 +0000 (11:42 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Apr 2016 19:35:36 +0000 (12:35 -0700)
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>
drivers/usb/core/buffer.c

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