[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAAeHK+x1wbSOt=EA-T1C3RjNhjYPa_uB0=vMmMS2-LECQFcj-g@mail.gmail.com>
Date: Tue, 7 Apr 2020 16:48:49 +0200
From: Andrey Konovalov <andreyknvl@...gle.com>
To: Dan Carpenter <dan.carpenter@...cle.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
USB list <linux-usb@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>,
Felipe Balbi <balbi@...nel.org>,
Jonathan Corbet <corbet@....net>,
Alan Stern <stern@...land.harvard.edu>
Subject: Re: [PATCH v2] usb: raw-gadget: fix raw_event_queue_fetch locking
On Tue, Apr 7, 2020 at 4:29 PM Dan Carpenter <dan.carpenter@...cle.com> wrote:
>
> On Tue, Apr 07, 2020 at 04:14:50PM +0200, Andrey Konovalov wrote:
> > @@ -89,11 +90,18 @@ static struct usb_raw_event *raw_event_queue_fetch(
> > * there's at least one event queued by decrementing the semaphore,
> > * and then take the lock to protect queue struct fields.
> > */
> > - if (down_interruptible(&queue->sema))
> > - return NULL;
> > + ret = down_interruptible(&queue->sema);
> > + if (ret)
> > + return ERR_PTR(ret);
> > spin_lock_irqsave(&queue->lock, flags);
> > - if (WARN_ON(!queue->size))
> > + /*
> > + * queue->size must have the same value as queue->sema counter (before
> > + * the down_interruptible() call above), so this check is a fail-safe.
> > + */
> > + if (WARN_ON(!queue->size)) {
> > + spin_unlock_irqrestore(&queue->lock, flags);
> > return NULL;
>
> I'm sorry for not noticing this earlier. When a function returns both
> error pointers and NULL then NULL is supposed to a special case of
> success. For example:
>
> my_struct_pointer = get_optional_feature();
>
> If there is a memory allocation failure then my_struct_pointer is
> -ENOMEM and we fail. But say the optional feature is disabled, then
> we can't return a valid pointer, but it's also working as designed so
> it's not an error. In that case we return NULL. The surrounding code
> should be written to allow NULL pointers.
>
> So I don't think returning NULL here is correct.
No problem, sent v3, thanks!
Powered by blists - more mailing lists