linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Chen <peter.chen@kernel.org>
To: Nathan Chancellor <nathan@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Pawel Laszczak <pawell@cadence.com>,
	Roger Quadros <rogerq@kernel.org>,
	Aswath Govindraju <a-govindraju@ti.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Tom Rix <trix@redhat.com>, Andrey Strachuk <strochuk@ispras.ru>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH] usb: cdns3: Don't use priv_dev uninitialized in cdns3_gadget_ep_enable()
Date: Fri, 19 Aug 2022 06:51:00 +0800	[thread overview]
Message-ID: <20220818225100.GA237489@Peter> (raw)
In-Reply-To: <20220803162422.2981308-1-nathan@kernel.org>

On 22-08-03 09:24:22, Nathan Chancellor wrote:
> 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>

Acked-by: Peter Chen <peter.chen@kernel.org>

> ---
>  drivers/usb/cdns3/cdns3-gadget.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
> index 9ac7d0a8c5da..d21b69997e75 100644
> --- a/drivers/usb/cdns3/cdns3-gadget.c
> +++ b/drivers/usb/cdns3/cdns3-gadget.c
> @@ -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
> -- 
> 2.37.1
> 

-- 

Thanks,
Peter Chen


      reply	other threads:[~2022-08-18 22:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-03 16:24 [PATCH] usb: cdns3: Don't use priv_dev uninitialized in cdns3_gadget_ep_enable() Nathan Chancellor
2022-08-18 22:51 ` Peter Chen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220818225100.GA237489@Peter \
    --to=peter.chen@kernel.org \
    --cc=a-govindraju@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=pawell@cadence.com \
    --cc=rogerq@kernel.org \
    --cc=strochuk@ispras.ru \
    --cc=torvalds@linux-foundation.org \
    --cc=trix@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).