octeon_ep: Fix the error handling path of octep_request_irqs()
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
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().
--- 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
@@ -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
Veerasenareddy Burru
maintainerRE: [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 ofoctep_request_irqs()External Email
----------------------------------------------------------------------
'oct->non_ioq_irq_names' is not freed in the error handling path ofoctep_request_irqs().Add the missing
kfree().Fixes 37d79d059606 ("octeon_ep: add Tx/Rx processing and interruptsupport")
Signed-off-by Christophe JAILLET <[email protected]>--- 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
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
-0alloc_err:return -1 ;}
--
2.34.1
PATCH 2/2 octeon_ep: Fix irq releasing in the error handling path of octep_request_irqs()
In reply to Christophe JAILLETFor 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.
---
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
@@ -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
Veerasenareddy Burru
maintainerRE: [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 ofoctep_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 requestedthere 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 interruptsupport")
Signed-off-by Christophe JAILLET <[email protected]>---
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@@ -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
-1return 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
Re: [PATCH 2/2] octeon_ep: Fix irq releasing in the error handling path of octep_request_irqs()
In reply to Christophe JAILLETQuoted 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")Signed-off-by Christophe JAILLET <[email protected]>---
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
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
Paolo Abeni
maintainerRe: [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")Signed-off-by Christophe JAILLET <[email protected]>---
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
-0drivers/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
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")Signed-off-by Christophe JAILLET <[email protected]>---
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
-0drivers/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 carpenterI 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