From: Chunfeng Yun Date: Thu, 28 Apr 2016 03:42:20 +0000 (+0800) Subject: usb: core: buffer: avoid NULL pointer dereferrence X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=f5e6253fe6de35fc2fa059974dbd9d61f32e4cd0;p=deliverable%2Flinux.git 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c index 2741566ee4f2..98e39f91723a 100644 --- a/drivers/usb/core/buffer.c +++ b/drivers/usb/core/buffer.c @@ -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 &&