All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jussi Kivilinna <jussi.kivilinna@haltian.com>,
	Tim Harvey <tharvey@gateworks.com>,
	Colin Ian King <colin.king@canonical.com>,
	Raz Manor <Raz.Manor@valens.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peter Senna Tschudin <peter.senna@gmail.com>
Subject: Re: [PATCH] usb: gadget: udc: add null check before pointer dereference
Date: Tue, 02 May 2017 10:29:01 -0500	[thread overview]
Message-ID: <20170502102901.Horde.V3lYucW4z0pbiibIoA4m_9v@gator4166.hostgator.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1705021029290.1758-100000@iolanthe.rowland.org>

Hi Alan,

Quoting Alan Stern <stern@rowland.harvard.edu>:

> On Mon, 1 May 2017, Gustavo A. R. Silva wrote:
>
>> Add null check before dereferencing dev->regs pointer inside
>> net2280_led_shutdown() function.
>>
>> Addresses-Coverity-ID: 101783
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> ---
>>  drivers/usb/gadget/udc/net2280.c | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/gadget/udc/net2280.c  
>> b/drivers/usb/gadget/udc/net2280.c
>> index 3828c2e..1898a4b 100644
>> --- a/drivers/usb/gadget/udc/net2280.c
>> +++ b/drivers/usb/gadget/udc/net2280.c
>> @@ -3573,7 +3573,11 @@ static void net2280_remove(struct pci_dev *pdev)
>>  	BUG_ON(dev->driver);
>>
>>  	/* then clean up the resources we allocated during probe() */
>> -	net2280_led_shutdown(dev);
>> +
>> +	if (dev->regs) {
>> +		net2280_led_shutdown(dev);
>> +		iounmap(dev->regs);
>> +	}
>>  	if (dev->requests) {
>>  		int		i;
>>  		for (i = 1; i < 5; i++) {
>> @@ -3588,8 +3592,6 @@ static void net2280_remove(struct pci_dev *pdev)
>>  		free_irq(pdev->irq, dev);
>>  	if (dev->quirks & PLX_PCIE)
>>  		pci_disable_msi(pdev);
>> -	if (dev->regs)
>> -		iounmap(dev->regs);
>>  	if (dev->region)
>>  		release_mem_region(pci_resource_start(pdev, 0),
>>  				pci_resource_len(pdev, 0));
>
> No, you must not move the iounmap() call, because an interrupt could
> theoretically occur at any time.
>

Yeah, I was suspicious about it.

> Either just live with an extra test of dev->regs, or else move the
> net2280_led_shutdown() call later.
>

In this case I think it is safe to move the net2280_led_shutdown()  
call, as the function is only turning off the LEDs.

I'll send a patch shortly.
Thank you
--
Gustavo A. R. Silva

  reply	other threads:[~2017-05-02 15:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-02  3:38 [PATCH] usb: gadget: udc: add null check before pointer dereference Gustavo A. R. Silva
2017-05-02 14:31 ` Alan Stern
2017-05-02 15:29   ` Gustavo A. R. Silva [this message]
2017-05-02 16:37     ` [PATCH v2] " Gustavo A. R. Silva
2017-05-02 18:45       ` Alan Stern

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=20170502102901.Horde.V3lYucW4z0pbiibIoA4m_9v@gator4166.hostgator.com \
    --to=garsilva@embeddedor.com \
    --cc=Raz.Manor@valens.com \
    --cc=balbi@kernel.org \
    --cc=colin.king@canonical.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jussi.kivilinna@haltian.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=peter.senna@gmail.com \
    --cc=stern@rowland.harvard.edu \
    --cc=tharvey@gateworks.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.