Linux USB
 help / color / mirror / Atom feed
From: John Keeping <john@metanate.com>
To: Udipto Goswami <quic_ugoswami@quicinc.com>
Cc: Dan Carpenter <error27@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org,
	Pratham Pratap <quic_ppratap@quicinc.com>
Subject: Re: [PATCH] usb: gadget: f_fs: Fix unbalanced spinlock in __ffs_ep0_queue_wait
Date: Tue, 24 Jan 2023 10:53:28 +0000	[thread overview]
Message-ID: <Y8+4qAqyKp64iqzQ@donbot> (raw)
In-Reply-To: <20230124091149.18647-1-quic_ugoswami@quicinc.com>

On Tue, Jan 24, 2023 at 02:41:49PM +0530, Udipto Goswami wrote:
> __ffs_ep0_queue_wait executes holding the spinlock of &ffs->ev.waitq.lock
> and unlocks it after the assignments to usb_request are done.
> However in the code if the request is already NULL we bail out returning
> -EINVAL but never unlocked the spinlock.
> 
> Fix this by adding spin_unlock_irq &ffs->ev.waitq.lock before returning.
> 
> Fixes: 6a19da111057("usb: gadget: f_fs: Prevent race during ffs_ep0_queue_wait")
> Signed-off-by: Udipto Goswami <quic_ugoswami@quicinc.com>

Reviewed-by: John Keeping <john@metanate.com>

> ---
>  drivers/usb/gadget/function/f_fs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 523a961b910b..8ad354741380 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -279,8 +279,10 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
>  	struct usb_request *req = ffs->ep0req;
>  	int ret;
>  
> -	if (!req)
> +	if (!req) {
> +		spin_unlock_irq(&ffs->ev.waitq.lock);
>  		return -EINVAL;
> +	}
>  
>  	req->zero     = len < le16_to_cpu(ffs->ev.setup.wLength);
>  
> -- 
> 2.17.1
> 

      reply	other threads:[~2023-01-24 10:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24  9:11 [PATCH] usb: gadget: f_fs: Fix unbalanced spinlock in __ffs_ep0_queue_wait Udipto Goswami
2023-01-24 10:53 ` John Keeping [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=Y8+4qAqyKp64iqzQ@donbot \
    --to=john@metanate.com \
    --cc=error27@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=quic_ppratap@quicinc.com \
    --cc=quic_ugoswami@quicinc.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