2022-05-15 17:27:46

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH 0/2] 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(-)

--
2.34.1



2022-05-15 21:02:28

by Christophe JAILLET

[permalink] [raw]
Subject: [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")
Signed-off-by: Christophe JAILLET <[email protected]>
---
drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
index e020c81f3455..6b60a03574a0 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
@@ -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;
}
--
2.34.1


2022-05-16 07:32:32

by Christophe JAILLET

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

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(-)

diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
index 6b60a03574a0..4dcae805422b 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
@@ -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) {
--
2.34.1


2022-05-17 00:17:05

by Veerasenareddy Burru

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

> -----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-
> >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(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> index 6b60a03574a0..4dcae805422b 100644
> --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> @@ -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]);
Ack.
Thanks for the fix.

Regards,
Veerasenareddy.
> }
> non_ioq_irq_err:
> while (i) {
> --
> 2.34.1


2022-05-17 01:07:41

by Veerasenareddy Burru

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

> -----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")
> Signed-off-by: Christophe JAILLET <[email protected]>
> ---
> drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> index e020c81f3455..6b60a03574a0 100644
> --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> @@ -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
> alloc_err:
> return -1;
> }
> --
> 2.34.1


2022-05-17 12:53:03

by Paolo Abeni

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

On Tue, 2022-05-17 at 08:28 +0300, Dan Carpenter wrote:
> On Sun, May 15, 2022 at 05:56:45PM +0200, Christophe JAILLET wrote:
> > 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(-)
> >
> > diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> > index 6b60a03574a0..4dcae805422b 100644
> > --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> > +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> > @@ -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?
>
> > --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

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

Thanks!

Paolo


2022-05-17 13:01:06

by Dan Carpenter

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

On Sun, May 15, 2022 at 05:56:45PM +0200, Christophe JAILLET wrote:
> 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(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> index 6b60a03574a0..4dcae805422b 100644
> --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> @@ -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?

> --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


2022-05-18 04:50:21

by Christophe JAILLET

[permalink] [raw]
Subject: 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 :
> On Tue, 2022-05-17 at 08:28 +0300, Dan Carpenter wrote:
>> On Sun, May 15, 2022 at 05:56:45PM +0200, Christophe JAILLET wrote:
>>> 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(-)
>>>
>>> diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
>>> index 6b60a03574a0..4dcae805422b 100644
>>> --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
>>> +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
>>> @@ -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?
>>
>>> --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
>
> 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

>
> Thanks!
>
> Paolo
>
>