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

usb: cdns3: Don't use priv_dev uninitialized in cdns3_gadget_ep_enable()

Clang warns:

drivers/usb/cdns3/cdns3-gadget.c:2290:11: error: variable 'priv_dev' is uninitialized when used here [-Werror,-Wuninitialized]
dev_dbg(priv_dev->dev, "usbss: invalid parameters\n");
^~~~~~~~
include/linux/dev_printk.h:155:18: note: expanded from macro 'dev_dbg'
dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
^~~
include/linux/dynamic_debug.h:167:7: note: expanded from macro 'dynamic_dev_dbg'
dev, fmt, ##__VA_ARGS__)
^~~
include/linux/dynamic_debug.h:152:56: note: expanded from macro '_dynamic_func_call'
__dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
^~~~~~~~~~~
include/linux/dynamic_debug.h:134:15: note: expanded from macro '__dynamic_func_call'
func(&id, ##__VA_ARGS__); \
^~~~~~~~~~~
drivers/usb/cdns3/cdns3-gadget.c:2278:31: note: initialize the variable 'priv_dev' to silence this warning
struct cdns3_device *priv_dev;
^
= NULL
1 error generated.

The priv_dev assignment was moved below the if statement to avoid
potentially dereferencing ep before it was checked but priv_dev is used
in the dev_dbg() call.

To fix this, move the priv_dev and comp_desc assignments back to their
original spot and hoist the ep check above those assignments with a call
to pr_debug() instead of dev_dbg().

Fixes: c3ffc9c4ca44 ("usb: cdns3: change place of 'priv_ep' assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable()")
Link: https://github.com/ClangBuiltLinux/linux/issues/1680
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Nathan Chancellor and committed by
Linus Torvalds
78acd4ca 9e2e5ea3

+9 -5
+9 -5
drivers/usb/cdns3/cdns3-gadget.c
··· 2284 2284 int ret = 0; 2285 2285 int val; 2286 2286 2287 - priv_ep = ep_to_cdns3_ep(ep); 2288 - 2289 - if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { 2290 - dev_dbg(priv_dev->dev, "usbss: invalid parameters\n"); 2287 + if (!ep) { 2288 + pr_debug("usbss: ep not configured?\n"); 2291 2289 return -EINVAL; 2292 2290 } 2293 2291 2294 - comp_desc = priv_ep->endpoint.comp_desc; 2292 + priv_ep = ep_to_cdns3_ep(ep); 2295 2293 priv_dev = priv_ep->cdns3_dev; 2294 + comp_desc = priv_ep->endpoint.comp_desc; 2295 + 2296 + if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT) { 2297 + dev_dbg(priv_dev->dev, "usbss: invalid parameters\n"); 2298 + return -EINVAL; 2299 + } 2296 2300 2297 2301 if (!desc->wMaxPacketSize) { 2298 2302 dev_err(priv_dev->dev, "usbss: missing wMaxPacketSize\n");