Skip to contentSkip to conversation

octeon_ep: Fix the error handling path of octep_request_irqs()

PATCH Superseded Christophe JAILLET 4 participants 8 messages May 15, 2022 – May 17, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover octeon_ep: Fix the error handling path of octep_request_irqs()

I send a small serie to ease review and because I'm sighly less confident with the 2nd patch.

They are related to the same Fixes: tag, so they obviously could be merged if it is preferred.

Christophe JAILLET (2):
octeon_ep: Fix a memory leak in the error handling path of
octep_request_irqs()
octeon_ep: Fix irq releasing in the error handling path of
octep_request_irqs()

 drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 octeon_ep: Fix a memory leak in the error handling path of octep_request_irqs()

'oct->non_ioq_irq_names' is not freed in the error handling path of octep_request_irqs().

Add the missing kfree().

Fixes 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt support")
---
 drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +2 -0
index e020c81f3455..6b60a03574a0 100644
@@ -267,6 +267,8 @@ static int octep_request_irqs(struct octep_device *oct)
 		--i;
 		free_irq(oct->msix_entries[i].vector, oct);
 	}
+	kfree(oct->non_ioq_irq_names);
+	oct->non_ioq_irq_names = NULL;
 alloc_err:
 	return -1;
 }
Signature · 1 line
2.34.1
#2 lore raw

RE: [EXT] [PATCH 1/2] octeon_ep: Fix a memory leak in the error handling path of octep_request_irqs()

Quoted 34 lines

-----Original Message-----
From: Christophe JAILLET <[email protected]>
Sent: Sunday, May 15, 2022 8:57 AM
To: Veerasenareddy Burru <[email protected]>; Abhijit Ayarekar <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Satananda Burla <[email protected]>
Cc: [email protected]; [email protected]; Christophe JAILLET <[email protected]>; [email protected]
Subject: [EXT] [PATCH 1/2] octeon_ep: Fix a memory leak in the error handling path of octep_request_irqs()

External Email

----------------------------------------------------------------------
'oct->non_ioq_irq_names' is not freed in the error handling path of octep_request_irqs().

Add the missing kfree().

Fixes 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt

support")

---
 drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +0 -0
index e020c81f3455..6b60a03574a0 100644

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_request_irqs(struct octep_device · line 272

Quoted 6 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +2 -0
@@ -267,6 +267,8 @@ static int octep_request_irqs(struct octep_device
 *oct)
 		--i;
 		free_irq(oct->msix_entries[i].vector, oct);
 	}
+	kfree(oct->non_ioq_irq_names);
+	oct->non_ioq_irq_names = NULL;

Ack
Thanks for the change.

Regards,
Veerasenareddy

Quoted 5 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +0 -0
 alloc_err:
 	return -1;

}
--
2.34.1

#3 lore raw

PATCH 2/2 octeon_ep: Fix irq releasing in the error handling path of octep_request_irqs()

In reply to Christophe JAILLET

For the error handling to work as expected, the index in the 'oct->msix_entries' array must be tweaked because, when the irq are requested there is:

	msix_entry = &oct->msix_entries[i + num_non_ioq_msix];

So in the error handling path, 'i + num_non_ioq_msix' should be used instead of 'i'.

The 2nd argument of free_irq() also needs to be adjusted.

Fixes 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt support")

---
I think that the wording above is awful, but I'm sure you get it. Feel free to rephrase everything to have it more readable.

---
 drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +3 -1
index 6b60a03574a0..4dcae805422b 100644
@@ -257,10 +257,12 @@ static int octep_request_irqs(struct octep_device *oct)
 
 	return 0;
 ioq_irq_err:
+	i += num_non_ioq_msix;
 	while (i > num_non_ioq_msix) {
 		--i;
 		irq_set_affinity_hint(oct->msix_entries[i].vector, NULL);
-		free_irq(oct->msix_entries[i].vector, oct->ioq_vector[i]);
+		free_irq(oct->msix_entries[i].vector,
+			 oct->ioq_vector[i - num_non_ioq_msix]);
 	}
 non_ioq_irq_err:
 	while (i) {
Signature · 1 line
2.34.1
#4 lore raw

RE: [EXT] [PATCH 2/2] octeon_ep: Fix irq releasing in the error handling path of octep_request_irqs()

Quoted 43 lines

-----Original Message-----
From: Christophe JAILLET <[email protected]>
Sent: Sunday, May 15, 2022 8:57 AM
To: Veerasenareddy Burru <[email protected]>; Abhijit Ayarekar <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Satananda Burla <[email protected]>
Cc: [email protected]; [email protected]; Christophe JAILLET <[email protected]>; [email protected]
Subject: [EXT] [PATCH 2/2] octeon_ep: Fix irq releasing in the error handling path of octep_request_irqs()

External Email

----------------------------------------------------------------------
For the error handling to work as expected, the index in the 'oct-

Quoted 1 line

msix_entries' array must be tweaked because, when the irq are requested

there is:

	msix_entry = &oct->msix_entries[i + num_non_ioq_msix];

So in the error handling path, 'i + num_non_ioq_msix' should be used instead of 'i'.

The 2nd argument of free_irq() also needs to be adjusted.

Fixes 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt

support")

---
I think that the wording above is awful, but I'm sure you get it. Feel free to rephrase everything to have it more readable.

---
 drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +0 -0
index 6b60a03574a0..4dcae805422b 100644
@@ -257,10 +257,12 @@ static int octep_request_irqs(struct octep_device
 *oct)

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_request_irqs(struct octep_device · line 266

Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +3 -1
 
 	return 0;
 ioq_irq_err:
+	i += num_non_ioq_msix;
 	while (i > num_non_ioq_msix) {
 		--i;
 		irq_set_affinity_hint(oct->msix_entries[i].vector, NULL);
-		free_irq(oct->msix_entries[i].vector, oct->ioq_vector[i]);
+		free_irq(oct->msix_entries[i].vector,
+			 oct->ioq_vector[i - num_non_ioq_msix]);

Ack.
Thanks for the fix.

Regards,
Veerasenareddy.

Quoted 5 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +0 -0
 	}
 non_ioq_irq_err:

while (i) {
--
2.34.1

#5 lore raw

Re: [PATCH 2/2] octeon_ep: Fix irq releasing in the error handling path of octep_request_irqs()

In reply to Christophe JAILLET
Quoted 24 lines · Christophe JAILLET

For the error handling to work as expected, the index in the 'oct->msix_entries' array must be tweaked because, when the irq are requested there is:

	msix_entry = &oct->msix_entries[i + num_non_ioq_msix];

So in the error handling path, 'i + num_non_ioq_msix' should be used instead of 'i'.

The 2nd argument of free_irq() also needs to be adjusted.

Fixes 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt support")

---
I think that the wording above is awful, but I'm sure you get it. Feel free to rephrase everything to have it more readable.

---
 drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +0 -0
index 6b60a03574a0..4dcae805422b 100644

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_request_irqs(struct octep_device *oct) · line 261

Quoted 5 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +1 -0
@@ -257,10 +257,12 @@ static int octep_request_irqs(struct octep_device *oct)
 
 	return 0;
 ioq_irq_err:
+	i += num_non_ioq_msix;
 	while (i > num_non_ioq_msix) {

This makes my mind hurt so badly. Can we not just have two variables for the two different loops instead of re-using i?

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_request_irqs(struct octep_device *oct) · line 266

Quoted 6 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +2 -1
 		--i;
 		irq_set_affinity_hint(oct->msix_entries[i].vector, NULL);
-		free_irq(oct->msix_entries[i].vector, oct->ioq_vector[i]);
+		free_irq(oct->msix_entries[i].vector,
+			 oct->ioq_vector[i - num_non_ioq_msix]);
 	}

ioq_irq_err:

        while (--j >= 0) {
                ioq_vector = oct->ioq_vector[j];
                msix_entry = &oct->msix_entries[j + num_non_ioq_msix];

                irq_set_affinity_hint(msix_entry->vector, NULL);
                free_irq(msix_entry->vector, ioq_vector);
        }

regards,
dan carpenter

maintainer
#6 lore raw

Re: [PATCH 2/2] octeon_ep: Fix irq releasing in the error handling path of octep_request_irqs()

Quoted 50 lines · Dan Carpenter
Quoted 24 lines · Christophe JAILLET

For the error handling to work as expected, the index in the 'oct->msix_entries' array must be tweaked because, when the irq are requested there is:

	msix_entry = &oct->msix_entries[i + num_non_ioq_msix];

So in the error handling path, 'i + num_non_ioq_msix' should be used instead of 'i'.

The 2nd argument of free_irq() also needs to be adjusted.

Fixes 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt support")

---
I think that the wording above is awful, but I'm sure you get it. Feel free to rephrase everything to have it more readable.

---
 drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +0 -0
index 6b60a03574a0..4dcae805422b 100644

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_request_irqs(struct octep_device *oct) · line 261

Quoted 5 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +1 -0
@@ -257,10 +257,12 @@ static int octep_request_irqs(struct octep_device *oct)
 
 	return 0;
 ioq_irq_err:
+	i += num_non_ioq_msix;
 	while (i > num_non_ioq_msix) {

This makes my mind hurt so badly. Can we not just have two variables for the two different loops instead of re-using i?

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_request_irqs(struct octep_device *oct) · line 266

Quoted 6 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +2 -1
 		--i;
 		irq_set_affinity_hint(oct->msix_entries[i].vector, NULL);
-		free_irq(oct->msix_entries[i].vector, oct->ioq_vector[i]);
+		free_irq(oct->msix_entries[i].vector,
+			 oct->ioq_vector[i - num_non_ioq_msix]);
 	}

ioq_irq_err:

        while (--j >= 0) {
                ioq_vector = oct->ioq_vector[j];
                msix_entry = &oct->msix_entries[j + num_non_ioq_msix];

                irq_set_affinity_hint(msix_entry->vector, NULL);
                free_irq(msix_entry->vector, ioq_vector);
        }
Quoted 2 lines

regards,
dan carpenter

I agree the above would be more readable. @Christophe: could you please refactor the code as per Dan's suggestion?

Thanks!

Paolo

#7 lore raw

Re: [PATCH 2/2] octeon_ep: Fix irq releasing in the error handling path of octep_request_irqs()

Le 17/05/2022 à 10:35, Paolo Abeni a écrit :

Quoted 51 lines · Dan Carpenter
Quoted 50 lines · Christophe JAILLET
Quoted 24 lines

For the error handling to work as expected, the index in the 'oct->msix_entries' array must be tweaked because, when the irq are requested there is:

	msix_entry = &oct->msix_entries[i + num_non_ioq_msix];

So in the error handling path, 'i + num_non_ioq_msix' should be used instead of 'i'.

The 2nd argument of free_irq() also needs to be adjusted.

Fixes 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt support")

---
I think that the wording above is awful, but I'm sure you get it. Feel free to rephrase everything to have it more readable.

---
  drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +0 -0
index 6b60a03574a0..4dcae805422b 100644

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_request_irqs(struct octep_device *oct) · line 261

Quoted 5 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +1 -0
@@ -257,10 +257,12 @@ static int octep_request_irqs(struct octep_device *oct)
 
  	return 0;
  ioq_irq_err:
+	i += num_non_ioq_msix;
  	while (i > num_non_ioq_msix) {

This makes my mind hurt so badly. Can we not just have two variables for the two different loops instead of re-using i?

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_request_irqs(struct octep_device *oct) · line 266

Quoted 6 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +2 -1
  		--i;
  		irq_set_affinity_hint(oct->msix_entries[i].vector, NULL);
-		free_irq(oct->msix_entries[i].vector, oct->ioq_vector[i]);
+		free_irq(oct->msix_entries[i].vector,
+			 oct->ioq_vector[i - num_non_ioq_msix]);
  	}

ioq_irq_err:

         while (--j >= 0) {
                 ioq_vector = oct->ioq_vector[j];
                 msix_entry = &oct->msix_entries[j + num_non_ioq_msix];

                 irq_set_affinity_hint(msix_entry->vector, NULL);
                 free_irq(msix_entry->vector, ioq_vector);
         }
Quoted 5 lines
Quoted 2 lines

regards,
dan carpenter

I agree the above would be more readable. @Christophe: could you please refactor the code as per Dan's suggestion?

Will do.

I was sure that Dan would comment on this unusual pattern :)

CJ

Quoted 6 lines

Thanks!

Paolo