Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: composite: Fix NULL pointer dereference

commit f563d230903210acc ("usb: gadget: composite: add req_match method
to usb_function") accesses cdev->config even before set config
is invoked causing a NULL pointer dereferencing error while running
Lecroy Mass Storage Compliance test.

Fix it here by accessing cdev->config only if it is non NULL.

Fixes: commit f563d230903210acc ("usb: gadget: composite: add req_match
method to usb_function").

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>

authored by

Kishon Vijay Abraham I and committed by
Felipe Balbi
b4c21f0b 4088acf1

+7 -4
+7 -4
drivers/usb/gadget/composite.c
··· 1758 1758 * take such requests too, if that's ever needed: to work 1759 1759 * in config 0, etc. 1760 1760 */ 1761 - list_for_each_entry(f, &cdev->config->functions, list) 1762 - if (f->req_match && f->req_match(f, ctrl)) 1763 - goto try_fun_setup; 1764 - f = NULL; 1761 + if (cdev->config) { 1762 + list_for_each_entry(f, &cdev->config->functions, list) 1763 + if (f->req_match && f->req_match(f, ctrl)) 1764 + goto try_fun_setup; 1765 + f = NULL; 1766 + } 1767 + 1765 1768 switch (ctrl->bRequestType & USB_RECIP_MASK) { 1766 1769 case USB_RECIP_INTERFACE: 1767 1770 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)