[PATCH] irqchip/loongson-pch-msi: Fix off-by-one on allocation error path

Zenghui Yu posted 1 patch 1 year, 10 months ago
There is a newer version of this series
drivers/irqchip/irq-loongson-pch-msi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] irqchip/loongson-pch-msi: Fix off-by-one on allocation error path
Posted by Zenghui Yu 1 year, 10 months ago
When pch_msi_parent_domain_alloc() returns an error, there is an off-by-one
in the number of IRQs to be freed.

Fix it by passing the number of successfully allocated IRQs, instead of the
relative index of the last allocated one.

Fixes: 632dcc2c75ef ("irqchip: Add Loongson PCH MSI controller")
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
---
 drivers/irqchip/irq-loongson-pch-msi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-loongson-pch-msi.c b/drivers/irqchip/irq-loongson-pch-msi.c
index 6e1e1f011bb2..dd4d699170f4 100644
--- a/drivers/irqchip/irq-loongson-pch-msi.c
+++ b/drivers/irqchip/irq-loongson-pch-msi.c
@@ -136,7 +136,7 @@ static int pch_msi_middle_domain_alloc(struct irq_domain *domain,
 
 err_hwirq:
 	pch_msi_free_hwirq(priv, hwirq, nr_irqs);
-	irq_domain_free_irqs_parent(domain, virq, i - 1);
+	irq_domain_free_irqs_parent(domain, virq, i);
 
 	return err;
 }
-- 
2.33.0
Re: [PATCH] irqchip/loongson-pch-msi: Fix off-by-one on allocation error path
Posted by Jiaxun Yang 1 year, 10 months ago

在 2024/3/27 14:23, Zenghui Yu 写道:
> When pch_msi_parent_domain_alloc() returns an error, there is an off-by-one
> in the number of IRQs to be freed.
>
> Fix it by passing the number of successfully allocated IRQs, instead of the
> relative index of the last allocated one.
>
> Fixes: 632dcc2c75ef ("irqchip: Add Loongson PCH MSI controller")
> Cc: Huacai Chen <chenhuacai@kernel.org>
> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
> Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>

Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>


I copied that piece of code from another driver without thinking.

Good catch!
> ---
>   drivers/irqchip/irq-loongson-pch-msi.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/irqchip/irq-loongson-pch-msi.c b/drivers/irqchip/irq-loongson-pch-msi.c
> index 6e1e1f011bb2..dd4d699170f4 100644
> --- a/drivers/irqchip/irq-loongson-pch-msi.c
> +++ b/drivers/irqchip/irq-loongson-pch-msi.c
> @@ -136,7 +136,7 @@ static int pch_msi_middle_domain_alloc(struct irq_domain *domain,
>   
>   err_hwirq:
>   	pch_msi_free_hwirq(priv, hwirq, nr_irqs);
> -	irq_domain_free_irqs_parent(domain, virq, i - 1);
> +	irq_domain_free_irqs_parent(domain, virq, i);
>   
>   	return err;
>   }

[tip: irq/core] irqchip/loongson-pch-msi: Fix off-by-one on allocation error path
Posted by tip-bot2 for Zenghui Yu 1 year, 10 months ago
The following commit has been merged into the irq/core branch of tip:

Commit-ID:     b327708798809328f21da8dc14cc8883d1e8a4b3
Gitweb:        https://git.kernel.org/tip/b327708798809328f21da8dc14cc8883d1e8a4b3
Author:        Zenghui Yu <yuzenghui@huawei.com>
AuthorDate:    Wed, 27 Mar 2024 22:23:34 +08:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Tue, 09 Apr 2024 11:03:16 +02:00

irqchip/loongson-pch-msi: Fix off-by-one on allocation error path

When pch_msi_parent_domain_alloc() returns an error, there is an off-by-one
in the number of interrupts to be freed.

Fix it by passing the number of successfully allocated interrupts, instead of the
relative index of the last allocated one.

Fixes: 632dcc2c75ef ("irqchip: Add Loongson PCH MSI controller")
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Link: https://lore.kernel.org/r/20240327142334.1098-1-yuzenghui@huawei.com

---
 drivers/irqchip/irq-loongson-pch-msi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-loongson-pch-msi.c b/drivers/irqchip/irq-loongson-pch-msi.c
index 6e1e1f0..dd4d699 100644
--- a/drivers/irqchip/irq-loongson-pch-msi.c
+++ b/drivers/irqchip/irq-loongson-pch-msi.c
@@ -136,7 +136,7 @@ static int pch_msi_middle_domain_alloc(struct irq_domain *domain,
 
 err_hwirq:
 	pch_msi_free_hwirq(priv, hwirq, nr_irqs);
-	irq_domain_free_irqs_parent(domain, virq, i - 1);
+	irq_domain_free_irqs_parent(domain, virq, i);
 
 	return err;
 }