Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] thunderbolt: Add the missed ida_simple_remove() in ring_request_msix()
@ 2020-10-14  1:46 Jing Xiangfeng
  2020-10-14  8:48 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Jing Xiangfeng @ 2020-10-14  1:46 UTC (permalink / raw)
  To: andreas.noever, michael.jamet, mika.westerberg, YehezkelShB,
	andriy.shevchenko
  Cc: linux-usb, linux-kernel, jingxiangfeng

ring_request_msix() misses to call ida_simple_remove() in an error path.
Add a label 'err_ida_remove' and jump to it.

Fixes: 046bee1f9ab8 ("thunderbolt: Add MSI-X support")
Signed-off-by: Jing Xiangfeng <jingxiangfeng@huawei.com>
---
 drivers/thunderbolt/nhi.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index 5f7489fa1327..e066888c4b41 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -406,11 +406,22 @@ static int ring_request_msix(struct tb_ring *ring, bool no_suspend)
 	ring->vector = ret;
 
 	ring->irq = pci_irq_vector(ring->nhi->pdev, ring->vector);
-	if (ring->irq < 0)
-		return ring->irq;
+	if (ring->irq < 0) {
+		ret = ring->irq;
+		goto err_ida_remove;
+	}
 
 	irqflags = no_suspend ? IRQF_NO_SUSPEND : 0;
-	return request_irq(ring->irq, ring_msix, irqflags, "thunderbolt", ring);
+	ret = request_irq(ring->irq, ring_msix, irqflags, "thunderbolt", ring);
+	if (ret)
+		goto err_ida_remove;
+
+	return 0;
+
+err_ida_remove:
+	ida_simple_remove(&nhi->msix_ida, ring->vector);
+
+	return ret;
 }
 
 static void ring_release_msix(struct tb_ring *ring)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] thunderbolt: Add the missed ida_simple_remove() in ring_request_msix()
  2020-10-14  1:46 [PATCH v2] thunderbolt: Add the missed ida_simple_remove() in ring_request_msix() Jing Xiangfeng
@ 2020-10-14  8:48 ` Andy Shevchenko
  2020-10-15  1:54   ` Jing Xiangfeng
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2020-10-14  8:48 UTC (permalink / raw)
  To: Jing Xiangfeng
  Cc: andreas.noever, michael.jamet, mika.westerberg, YehezkelShB,
	linux-usb, linux-kernel

On Wed, Oct 14, 2020 at 09:46:04AM +0800, Jing Xiangfeng wrote:
> ring_request_msix() misses to call ida_simple_remove() in an error path.
> Add a label 'err_ida_remove' and jump to it.

...

> @@ -406,11 +406,22 @@ static int ring_request_msix(struct tb_ring *ring, bool no_suspend)
>  	ring->vector = ret;

^^^

>  	ring->irq = pci_irq_vector(ring->nhi->pdev, ring->vector);
> -	if (ring->irq < 0)
> -		return ring->irq;
> +	if (ring->irq < 0) {
> +		ret = ring->irq;
> +		goto err_ida_remove;
> +	}

What about
	ret = pci_irq_vector(ring->nhi->pdev, ring->vector);
	if (ret < 0)
		goto err_ida_remove;

	ring->irq = ret;

?

(See also context above)

>  	irqflags = no_suspend ? IRQF_NO_SUSPEND : 0;
> -	return request_irq(ring->irq, ring_msix, irqflags, "thunderbolt", ring);
> +	ret = request_irq(ring->irq, ring_msix, irqflags, "thunderbolt", ring);
> +	if (ret)
> +		goto err_ida_remove;
> +
> +	return 0;
> +
> +err_ida_remove:
> +	ida_simple_remove(&nhi->msix_ida, ring->vector);
> +
> +	return ret;
>  }
>  
>  static void ring_release_msix(struct tb_ring *ring)
> -- 
> 2.17.1
> 

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] thunderbolt: Add the missed ida_simple_remove() in ring_request_msix()
  2020-10-14  8:48 ` Andy Shevchenko
@ 2020-10-15  1:54   ` Jing Xiangfeng
  0 siblings, 0 replies; 3+ messages in thread
From: Jing Xiangfeng @ 2020-10-15  1:54 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: andreas.noever, michael.jamet, mika.westerberg, YehezkelShB,
	linux-usb, linux-kernel



On 2020/10/14 16:48, Andy Shevchenko wrote:
> On Wed, Oct 14, 2020 at 09:46:04AM +0800, Jing Xiangfeng wrote:
>> ring_request_msix() misses to call ida_simple_remove() in an error path.
>> Add a label 'err_ida_remove' and jump to it.
> ...
>
>> @@ -406,11 +406,22 @@ static int ring_request_msix(struct tb_ring *ring, bool no_suspend)
>>   	ring->vector = ret;
> ^^^
>
>>   	ring->irq = pci_irq_vector(ring->nhi->pdev, ring->vector);
>> -	if (ring->irq < 0)
>> -		return ring->irq;
>> +	if (ring->irq < 0) {
>> +		ret = ring->irq;
>> +		goto err_ida_remove;
>> +	}
> What about
> 	ret = pci_irq_vector(ring->nhi->pdev, ring->vector);
> 	if (ret < 0)
> 		goto err_ida_remove;
>
> 	ring->irq = ret;
>
> ?
Yeah, I agree. Thanks for your suggestions.

>
> (See also context above)
>
>>   	irqflags = no_suspend ? IRQF_NO_SUSPEND : 0;
>> -	return request_irq(ring->irq, ring_msix, irqflags, "thunderbolt", ring);
>> +	ret = request_irq(ring->irq, ring_msix, irqflags, "thunderbolt", ring);
>> +	if (ret)
>> +		goto err_ida_remove;
>> +
>> +	return 0;
>> +
>> +err_ida_remove:
>> +	ida_simple_remove(&nhi->msix_ida, ring->vector);
>> +
>> +	return ret;
>>   }
>>   
>>   static void ring_release_msix(struct tb_ring *ring)
>> -- 
>> 2.17.1
>>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14  1:46 [PATCH v2] thunderbolt: Add the missed ida_simple_remove() in ring_request_msix() Jing Xiangfeng
2020-10-14  8:48 ` Andy Shevchenko
2020-10-15  1:54   ` Jing Xiangfeng

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git