提交 b2fc059f 编写于 作者: C Colin Ian King 提交者: Felipe Balbi

usb: gadget: don't dereference g until after it has been null checked

Avoid dereferencing pointer g until after g has been sanity null checked;
move the assignment of cdev much later when it is required into a more
local scope.

Detected by CoverityScan, CID#1222135 ("Dereference before null check")

Fixes: b785ea7c ("usb: gadget: composite: fix ep->maxburst initialization")
Signed-off-by: NColin Ian King <colin.king@canonical.com>
Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
上级 593e789f
...@@ -146,7 +146,6 @@ int config_ep_by_speed(struct usb_gadget *g, ...@@ -146,7 +146,6 @@ int config_ep_by_speed(struct usb_gadget *g,
struct usb_function *f, struct usb_function *f,
struct usb_ep *_ep) struct usb_ep *_ep)
{ {
struct usb_composite_dev *cdev = get_gadget_data(g);
struct usb_endpoint_descriptor *chosen_desc = NULL; struct usb_endpoint_descriptor *chosen_desc = NULL;
struct usb_descriptor_header **speed_desc = NULL; struct usb_descriptor_header **speed_desc = NULL;
...@@ -226,8 +225,12 @@ int config_ep_by_speed(struct usb_gadget *g, ...@@ -226,8 +225,12 @@ int config_ep_by_speed(struct usb_gadget *g,
_ep->maxburst = comp_desc->bMaxBurst + 1; _ep->maxburst = comp_desc->bMaxBurst + 1;
break; break;
default: default:
if (comp_desc->bMaxBurst != 0) if (comp_desc->bMaxBurst != 0) {
struct usb_composite_dev *cdev;
cdev = get_gadget_data(g);
ERROR(cdev, "ep0 bMaxBurst must be 0\n"); ERROR(cdev, "ep0 bMaxBurst must be 0\n");
}
_ep->maxburst = 1; _ep->maxburst = 1;
break; break;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册