Skip to contentSkip to conversation

usb: gadget: Potential NULL dereference on allocation error

PATCH New Dan Carpenter 1 participant 1 message Dec 21, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: Potential NULL dereference on allocation error

The source_sink_alloc_func() function is supposed to return error pointers on error. The function is called from usb_get_function() which doesn't check for NULL returns so it would result in an Oops.

Of course, in the current kernel, small allocations always succeed so this doesn't affect runtime.

---
 drivers/usb/gadget/function/f_sourcesink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/function/f_sourcesink.c +1 -1
index 9cdef108fb1b..ed68a4860b7d 100644
@@ -838,7 +838,7 @@ static struct usb_function *source_sink_alloc_func(
 
 	ss = kzalloc(sizeof(*ss), GFP_KERNEL);
 	if (!ss)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	ss_opts =  container_of(fi, struct f_ss_opts, func_inst);
 
Signature · 1 line
2.17.1