usb: cdns3: Don't use priv_dev uninitialized in cdns3_gadget_ep_enable()
Subsystems (2)
PATCH 1/1 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;
^
= NULL1 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().
--- drivers/usb/cdns3/cdns3-gadget.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/usb/cdns3/cdns3-gadget.c +8 -4
@@ -2284,16 +2284,20 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep,int ret =0 ;int val; +if (!ep) { +pr_debug ("usbss: ep not configured?\n" ); +return -EINVAL ; + } + priv_ep =ep_to_cdns3_ep (ep); + priv_dev = priv_ep->cdns3_dev; + comp_desc = priv_ep->endpoint.comp_desc; -if (!ep || !desc || desc->bDescriptorType !=USB_DT_ENDPOINT ) { +if (!desc || desc->bDescriptorType !=USB_DT_ENDPOINT ) {dev_dbg (priv_dev->dev,"usbss: invalid parameters\n" );return -EINVAL ; } - comp_desc = priv_ep->endpoint.comp_desc; - priv_dev = priv_ep->cdns3_dev; -if (!desc->wMaxPacketSize) {dev_err (priv_dev->dev,"usbss: missing wMaxPacketSize\n" );return -EINVAL ;
base-commit: 8288c99fc263bcafc5df5fa8c278b2eb8106364e
Signature · 1 line
2.37.1
Quoted 27 lines · Nathan Chancellor
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; ^ = NULL1 error generated.
The
priv_devassignment was moved below the if statement to avoid potentially dereferencing ep before it was checked butpriv_devis used in thedev_dbg()call.
Quoted 7 lines
To fix this, move the
priv_devandcomp_descassignments back to their original spot and hoist the ep check above those assignments with a call topr_debug()instead ofdev_dbg().Fixes c3ffc9c4ca44 ("usb: cdns3: change place of 'priv_ep' assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable()")Signed-off-by Nathan Chancellor <[email protected]>
Quoted 38 lines
--- drivers/usb/cdns3/cdns3-gadget.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/usb/cdns3/cdns3-gadget.c +8
-4@@ -2284,16 +2284,20 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep,int ret =0 ;int val; +if (!ep) { +pr_debug ("usbss: ep not configured?\n" ); +return -EINVAL ; + } + priv_ep =ep_to_cdns3_ep (ep); + priv_dev = priv_ep->cdns3_dev; + comp_desc = priv_ep->endpoint.comp_desc; -if (!ep || !desc || desc->bDescriptorType !=USB_DT_ENDPOINT ) { +if (!desc || desc->bDescriptorType !=USB_DT_ENDPOINT ) {dev_dbg (priv_dev->dev,"usbss: invalid parameters\n" );return -EINVAL ; } - comp_desc = priv_ep->endpoint.comp_desc; - priv_dev = priv_ep->cdns3_dev; -if (!desc->wMaxPacketSize) {dev_err (priv_dev->dev,"usbss: missing wMaxPacketSize\n" );return -EINVAL ;base-commit:
8288c99fc263bcafc5df5fa8c278b2eb8106364eSignature · 1 line
2.37.1
Signature · 2 lines
Thanks, Peter Chen