usb: isp1760: fix null dereference if kzalloc returns null
Subsystems (2)
PATCH v2 1/1 usb: isp1760: fix null dereference if kzalloc returns null
From: Colin Ian King <[email protected]>
If kzalloc returns null then isp1760_ep_alloc_request performs a null pointer dereference on req. Check for null to avoid this.
Detected with smatch static analysis:
drivers/usb/isp1760/isp1760-udc.c:816 isp1760_ep_alloc_request()
error: potential null dereference 'req'. (kzalloc returns null)
--- drivers/usb/isp1760/isp1760-udc.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/isp1760/isp1760-udc.c +2 -0
@@ -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; }
Signature · 1 line
2.1.4
Hello.
Quoted 4 lines · Colin King
From: Colin Ian King <[email protected]>
If kzalloc returns null then
isp1760_ep_alloc_requestperforms a null pointer dereference on req. Check for null to avoid this.
I told you there's no dereference and yet you're repeating it again. :-(
Quoted 6 lines
Detected with smatch static analysis:
drivers/usb/isp1760/isp1760-udc.c:816isp1760_ep_alloc_request()
error: potential null dereference 'req'. (kzalloc returns null)Signed-off-by Colin Ian King <[email protected]>
WBR, Sergei
Quoted 9 lines · On Monday 01 June 2015 16:51:30 Sergei Shtylyov wrote:
Hello.
Quoted 4 lines · Colin King
From: Colin Ian King <[email protected]>
If kzalloc returns null then
isp1760_ep_alloc_requestperforms a null pointer dereference on req. Check for null to avoid this.I told you there's no dereference and yet you're repeating it again. :-(
How about
"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."
Quoted 9 lines
Quoted 9 lines
a null pointer dereference on req. Check for null to avoid this.
Detected with smatch static analysis:
drivers/usb/isp1760/isp1760-udc.c:816isp1760_ep_alloc_request()error: potential null dereference 'req'. (kzalloc returns null)
Signed-off-by Colin Ian King <[email protected]>
Signature · 3 lines
Regards, Laurent Pinchart
Hello.
Quoted 7 lines · Laurent Pinchart
Quoted 6 lines
Quoted 4 lines
From: Colin Ian King <[email protected]>
If kzalloc returns null then
isp1760_ep_alloc_requestperforms a null pointer dereference on req. Check for null to avoid this.I told you there's no dereference and yet you're repeating it again. :-(
Quoted 7 lines
How about
"
isp1760_ep_alloc_requestallocates 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."
Fine with me! Thanks, Laurent. :-)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
a null pointer dereference on req. Check for null to avoid this.
Detected with smatch static analysis:
drivers/usb/isp1760/isp1760-udc.c:816isp1760_ep_alloc_request()error: potential null dereference 'req'. (kzalloc returns null)
Signed-off-by Colin Ian King <[email protected]>
WBR, Sergei