linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] irqchip/gic-v5: Delete a stray tab
       [not found] <cover.1752693640.git.dan.carpenter@linaro.org>
@ 2025-07-16 19:37 ` Dan Carpenter
  2025-07-16 19:37 ` [PATCH 2/3] irqchip/gic-v5: Fix forever loop in gicv5_its_create_itt_two_level() error handling Dan Carpenter
  2025-07-16 19:38 ` [PATCH 3/3] irqchip/gic-v5: Fix error handling in gicv5_its_irq_domain_alloc() Dan Carpenter
  2 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2025-07-16 19:37 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: Marc Zyngier, Thomas Gleixner, linux-arm-kernel, linux-kernel

This line is indented one tab too far.  Delete the tab.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/irqchip/irq-gic-v5-irs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-gic-v5-irs.c b/drivers/irqchip/irq-gic-v5-irs.c
index f845415f9143..ad1435a858a4 100644
--- a/drivers/irqchip/irq-gic-v5-irs.c
+++ b/drivers/irqchip/irq-gic-v5-irs.c
@@ -568,7 +568,7 @@ static void __init gicv5_irs_init_bases(struct gicv5_irs_chip_data *irs_data,
 			FIELD_PREP(GICV5_IRS_CR1_IST_RA, GICV5_NO_READ_ALLOC)	|
 			FIELD_PREP(GICV5_IRS_CR1_IC, GICV5_NON_CACHE)		|
 			FIELD_PREP(GICV5_IRS_CR1_OC, GICV5_NON_CACHE);
-			irs_data->flags |= IRS_FLAGS_NON_COHERENT;
+		irs_data->flags |= IRS_FLAGS_NON_COHERENT;
 	} else {
 		cr1 = FIELD_PREP(GICV5_IRS_CR1_VPED_WA, GICV5_WRITE_ALLOC)	|
 			FIELD_PREP(GICV5_IRS_CR1_VPED_RA, GICV5_READ_ALLOC)	|
-- 
2.47.2



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

* [PATCH 2/3] irqchip/gic-v5: Fix forever loop in gicv5_its_create_itt_two_level() error handling
       [not found] <cover.1752693640.git.dan.carpenter@linaro.org>
  2025-07-16 19:37 ` [PATCH 1/3] irqchip/gic-v5: Delete a stray tab Dan Carpenter
@ 2025-07-16 19:37 ` Dan Carpenter
  2025-07-16 19:38 ` [PATCH 3/3] irqchip/gic-v5: Fix error handling in gicv5_its_irq_domain_alloc() Dan Carpenter
  2 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2025-07-16 19:37 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: Marc Zyngier, Thomas Gleixner, Sascha Bischoff, Timothy Hayes,
	linux-arm-kernel, linux-kernel

The "i" variable needs to be signed otherwise there is a forever loop
in the cleanup code.

Fixes: 57d72196dfc8 ("irqchip/gic-v5: Add GICv5 ITS support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/irqchip/irq-gic-v5-its.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v5-its.c b/drivers/irqchip/irq-gic-v5-its.c
index 340640fdbdf6..55360ae9f1f6 100644
--- a/drivers/irqchip/irq-gic-v5-its.c
+++ b/drivers/irqchip/irq-gic-v5-its.c
@@ -191,9 +191,9 @@ static int gicv5_its_create_itt_two_level(struct gicv5_its_chip_data *its,
 					  unsigned int num_events)
 {
 	unsigned int l1_bits, l2_bits, span, events_per_l2_table;
-	unsigned int i, complete_tables, final_span, num_ents;
+	unsigned int complete_tables, final_span, num_ents;
 	__le64 *itt_l1, *itt_l2, **l2ptrs;
-	int ret;
+	int i, ret;
 	u64 val;
 
 	ret = gicv5_its_l2sz_to_l2_bits(itt_l2sz);
-- 
2.47.2



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

* [PATCH 3/3] irqchip/gic-v5: Fix error handling in gicv5_its_irq_domain_alloc()
       [not found] <cover.1752693640.git.dan.carpenter@linaro.org>
  2025-07-16 19:37 ` [PATCH 1/3] irqchip/gic-v5: Delete a stray tab Dan Carpenter
  2025-07-16 19:37 ` [PATCH 2/3] irqchip/gic-v5: Fix forever loop in gicv5_its_create_itt_two_level() error handling Dan Carpenter
@ 2025-07-16 19:38 ` Dan Carpenter
  2025-07-17  9:25   ` Lorenzo Pieralisi
  2 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2025-07-16 19:38 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: Marc Zyngier, Thomas Gleixner, Timothy Hayes, Sascha Bischoff,
	linux-arm-kernel, linux-kernel

There are two issues to fix in this code:
1) If gicv5_alloc_lpi() fails the original code was checking the wrong
variable.  Fix the mixup between "ret" and "lpi".
2) If irq_domain_alloc_irqs_parent() fails, then clean up all the loop
iterations instead of just the current iteration.

Fixes: 57d72196dfc8 ("irqchip/gic-v5: Add GICv5 ITS support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/irqchip/irq-gic-v5-its.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v5-its.c b/drivers/irqchip/irq-gic-v5-its.c
index 55360ae9f1f6..8cc8563e27d5 100644
--- a/drivers/irqchip/irq-gic-v5-its.c
+++ b/drivers/irqchip/irq-gic-v5-its.c
@@ -949,15 +949,18 @@ static int gicv5_its_irq_domain_alloc(struct irq_domain *domain, unsigned int vi
 	device_id = its_dev->device_id;
 
 	for (i = 0; i < nr_irqs; i++) {
-		lpi = gicv5_alloc_lpi();
+		ret = gicv5_alloc_lpi();
 		if (ret < 0) {
 			pr_debug("Failed to find free LPI!\n");
 			goto out_eventid;
 		}
+		lpi = ret;
 
 		ret = irq_domain_alloc_irqs_parent(domain, virq + i, 1, &lpi);
-		if (ret)
+		if (ret) {
+			gicv5_free_lpi(lpi);
 			goto out_free_lpi;
+		}
 
 		/*
 		 * Store eventid and deviceid into the hwirq for later use.
@@ -979,7 +982,12 @@ static int gicv5_its_irq_domain_alloc(struct irq_domain *domain, unsigned int vi
 	return 0;
 
 out_free_lpi:
-	gicv5_free_lpi(lpi);
+	while (--i >= 0) {
+		irqd = irq_domain_get_irq_data(domain, virq + i);
+		gicv5_free_lpi(irqd->parent_data->hwirq);
+		irq_domain_reset_irq_data(irqd);
+		irq_domain_free_irqs_parent(domain, virq + i, 1);
+	}
 out_eventid:
 	gicv5_its_free_eventid(its_dev, event_id_base, nr_irqs);
 	return ret;
-- 
2.47.2



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

* Re: [PATCH 3/3] irqchip/gic-v5: Fix error handling in gicv5_its_irq_domain_alloc()
  2025-07-16 19:38 ` [PATCH 3/3] irqchip/gic-v5: Fix error handling in gicv5_its_irq_domain_alloc() Dan Carpenter
@ 2025-07-17  9:25   ` Lorenzo Pieralisi
  2025-07-17 14:41     ` Dan Carpenter
  0 siblings, 1 reply; 6+ messages in thread
From: Lorenzo Pieralisi @ 2025-07-17  9:25 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Marc Zyngier, Thomas Gleixner, Timothy Hayes, Sascha Bischoff,
	linux-arm-kernel, linux-kernel

On Wed, Jul 16, 2025 at 02:38:22PM -0500, Dan Carpenter wrote:
> There are two issues to fix in this code:
> 1) If gicv5_alloc_lpi() fails the original code was checking the wrong
> variable.  Fix the mixup between "ret" and "lpi".
> 2) If irq_domain_alloc_irqs_parent() fails, then clean up all the loop
> iterations instead of just the current iteration.
> 
> Fixes: 57d72196dfc8 ("irqchip/gic-v5: Add GICv5 ITS support")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/irqchip/irq-gic-v5-its.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/irqchip/irq-gic-v5-its.c b/drivers/irqchip/irq-gic-v5-its.c
> index 55360ae9f1f6..8cc8563e27d5 100644
> --- a/drivers/irqchip/irq-gic-v5-its.c
> +++ b/drivers/irqchip/irq-gic-v5-its.c
> @@ -949,15 +949,18 @@ static int gicv5_its_irq_domain_alloc(struct irq_domain *domain, unsigned int vi
>  	device_id = its_dev->device_id;
>  
>  	for (i = 0; i < nr_irqs; i++) {
> -		lpi = gicv5_alloc_lpi();
> +		ret = gicv5_alloc_lpi();
>  		if (ret < 0) {
>  			pr_debug("Failed to find free LPI!\n");
>  			goto out_eventid;

This should be:

goto out_free_lpi;

otherwise we miss cleaning up for [0, i - 1] on LPI alloc failure.

I can fix it up - not sure it is worth splitting it into two patches,
just let me know please how you want me to handle it.

Thanks,
Lorenzo

>  		}
> +		lpi = ret;
>  
>  		ret = irq_domain_alloc_irqs_parent(domain, virq + i, 1, &lpi);
> -		if (ret)
> +		if (ret) {
> +			gicv5_free_lpi(lpi);
>  			goto out_free_lpi;
> +		}
>  
>  		/*
>  		 * Store eventid and deviceid into the hwirq for later use.
> @@ -979,7 +982,12 @@ static int gicv5_its_irq_domain_alloc(struct irq_domain *domain, unsigned int vi
>  	return 0;
>  
>  out_free_lpi:
> -	gicv5_free_lpi(lpi);
> +	while (--i >= 0) {
> +		irqd = irq_domain_get_irq_data(domain, virq + i);
> +		gicv5_free_lpi(irqd->parent_data->hwirq);
> +		irq_domain_reset_irq_data(irqd);
> +		irq_domain_free_irqs_parent(domain, virq + i, 1);
> +	}
>  out_eventid:
>  	gicv5_its_free_eventid(its_dev, event_id_base, nr_irqs);
>  	return ret;
> -- 
> 2.47.2
> 


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

* Re: [PATCH 3/3] irqchip/gic-v5: Fix error handling in gicv5_its_irq_domain_alloc()
  2025-07-17  9:25   ` Lorenzo Pieralisi
@ 2025-07-17 14:41     ` Dan Carpenter
  2025-07-17 15:18       ` Lorenzo Pieralisi
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2025-07-17 14:41 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: Marc Zyngier, Thomas Gleixner, Timothy Hayes, Sascha Bischoff,
	linux-arm-kernel, linux-kernel

On Thu, Jul 17, 2025 at 11:25:15AM +0200, Lorenzo Pieralisi wrote:
> On Wed, Jul 16, 2025 at 02:38:22PM -0500, Dan Carpenter wrote:
> > There are two issues to fix in this code:
> > 1) If gicv5_alloc_lpi() fails the original code was checking the wrong
> > variable.  Fix the mixup between "ret" and "lpi".
> > 2) If irq_domain_alloc_irqs_parent() fails, then clean up all the loop
> > iterations instead of just the current iteration.
> > 
> > Fixes: 57d72196dfc8 ("irqchip/gic-v5: Add GICv5 ITS support")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> >  drivers/irqchip/irq-gic-v5-its.c | 14 +++++++++++---
> >  1 file changed, 11 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/irqchip/irq-gic-v5-its.c b/drivers/irqchip/irq-gic-v5-its.c
> > index 55360ae9f1f6..8cc8563e27d5 100644
> > --- a/drivers/irqchip/irq-gic-v5-its.c
> > +++ b/drivers/irqchip/irq-gic-v5-its.c
> > @@ -949,15 +949,18 @@ static int gicv5_its_irq_domain_alloc(struct irq_domain *domain, unsigned int vi
> >  	device_id = its_dev->device_id;
> >  
> >  	for (i = 0; i < nr_irqs; i++) {
> > -		lpi = gicv5_alloc_lpi();
> > +		ret = gicv5_alloc_lpi();
> >  		if (ret < 0) {
> >  			pr_debug("Failed to find free LPI!\n");
> >  			goto out_eventid;
> 
> This should be:
> 
> goto out_free_lpi;
> 

Yes, you're right.

> otherwise we miss cleaning up for [0, i - 1] on LPI alloc failure.
> 
> I can fix it up - not sure it is worth splitting it into two patches,
> just let me know please how you want me to handle it.

I don't think it should be split up.  As a reviewer I would be annoyed
by a split up version of this.

I'm a little bit surprised by the offer to fix it up for me...  Is this
going through your tree?  It's probably easiest if I just send a v2...
Let me do that.

regards,
dan carpenter



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

* Re: [PATCH 3/3] irqchip/gic-v5: Fix error handling in gicv5_its_irq_domain_alloc()
  2025-07-17 14:41     ` Dan Carpenter
@ 2025-07-17 15:18       ` Lorenzo Pieralisi
  0 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Pieralisi @ 2025-07-17 15:18 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Marc Zyngier, Thomas Gleixner, Timothy Hayes, Sascha Bischoff,
	linux-arm-kernel, linux-kernel

On Thu, Jul 17, 2025 at 05:41:06PM +0300, Dan Carpenter wrote:
> On Thu, Jul 17, 2025 at 11:25:15AM +0200, Lorenzo Pieralisi wrote:
> > On Wed, Jul 16, 2025 at 02:38:22PM -0500, Dan Carpenter wrote:
> > > There are two issues to fix in this code:
> > > 1) If gicv5_alloc_lpi() fails the original code was checking the wrong
> > > variable.  Fix the mixup between "ret" and "lpi".
> > > 2) If irq_domain_alloc_irqs_parent() fails, then clean up all the loop
> > > iterations instead of just the current iteration.
> > > 
> > > Fixes: 57d72196dfc8 ("irqchip/gic-v5: Add GICv5 ITS support")
> > > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > > ---
> > >  drivers/irqchip/irq-gic-v5-its.c | 14 +++++++++++---
> > >  1 file changed, 11 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/irqchip/irq-gic-v5-its.c b/drivers/irqchip/irq-gic-v5-its.c
> > > index 55360ae9f1f6..8cc8563e27d5 100644
> > > --- a/drivers/irqchip/irq-gic-v5-its.c
> > > +++ b/drivers/irqchip/irq-gic-v5-its.c
> > > @@ -949,15 +949,18 @@ static int gicv5_its_irq_domain_alloc(struct irq_domain *domain, unsigned int vi
> > >  	device_id = its_dev->device_id;
> > >  
> > >  	for (i = 0; i < nr_irqs; i++) {
> > > -		lpi = gicv5_alloc_lpi();
> > > +		ret = gicv5_alloc_lpi();
> > >  		if (ret < 0) {
> > >  			pr_debug("Failed to find free LPI!\n");
> > >  			goto out_eventid;
> > 
> > This should be:
> > 
> > goto out_free_lpi;
> > 
> 
> Yes, you're right.

While at it I'd rename the label, out_free_irqs or something like
that, now we are doing more than freeing an LPI.

> > otherwise we miss cleaning up for [0, i - 1] on LPI alloc failure.
> > 
> > I can fix it up - not sure it is worth splitting it into two patches,
> > just let me know please how you want me to handle it.
> 
> I don't think it should be split up.  As a reviewer I would be annoyed
> by a split up version of this.
> 
> I'm a little bit surprised by the offer to fix it up for me...  Is this
> going through your tree?  It's probably easiest if I just send a v2...
> Let me do that.

I just wanted to help. FYI Marc has sent a PR today mentioning these patches:

https://lore.kernel.org/lkml/20250717122306.4043011-1-maz@kernel.org/

I think that keeping the CC list is good so that Thomas can pick them
up if he pulls the branch.

Thanks again for fixing these issues.

Lorenzo


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

end of thread, other threads:[~2025-07-17 15:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1752693640.git.dan.carpenter@linaro.org>
2025-07-16 19:37 ` [PATCH 1/3] irqchip/gic-v5: Delete a stray tab Dan Carpenter
2025-07-16 19:37 ` [PATCH 2/3] irqchip/gic-v5: Fix forever loop in gicv5_its_create_itt_two_level() error handling Dan Carpenter
2025-07-16 19:38 ` [PATCH 3/3] irqchip/gic-v5: Fix error handling in gicv5_its_irq_domain_alloc() Dan Carpenter
2025-07-17  9:25   ` Lorenzo Pieralisi
2025-07-17 14:41     ` Dan Carpenter
2025-07-17 15:18       ` Lorenzo Pieralisi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).