OSDN Git Service

usb: isp1760: check for null return from kzalloc
authorColin Ian King <colin.king@canonical.com>
Tue, 2 Jun 2015 18:05:13 +0000 (19:05 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 8 Jun 2015 21:25:04 +0000 (14:25 -0700)
isp1760_ep_alloc_request allocates a structure with kzalloc without checking
for NULL and then returns a pointer to one of the structure fields. As the
field happens to be the first in the structure the caller can properly check
for NULL, but this is risky if the structure layout is changed later. Add an
explicit NULL check for the kzalloc return value

Detected with smatch static analysis:

drivers/usb/isp1760/isp1760-udc.c:816 isp1760_ep_alloc_request()
  error: potential null dereference 'req'.  (kzalloc returns null)

[ thanks to Laurent Pinchart for improved commit message ]

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/isp1760/isp1760-udc.c

index 3fc4fe7..18ebf5b 100644 (file)
@@ -812,6 +812,8 @@ static struct usb_request *isp1760_ep_alloc_request(struct usb_ep *ep,
        struct isp1760_request *req;
 
        req = kzalloc(sizeof(*req), gfp_flags);
+       if (!req)
+               return NULL;
 
        return &req->req;
 }