function mana_hwc_create_wq leaks memory
PATCH 1/1 function mana_hwc_create_wq leaks memory
memory space allocated for the queue in function mana_gd_create_hwc_queue is not freed during error condition.
--- drivers/net/ethernet/microsoft/mana/hw_channel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/microsoft/mana/hw_channel.c +3 -1
@@ -501,8 +501,10 @@ static int mana_hwc_create_wq(struct hw_channel_context *hwc, *hwc_wq_ptr = hwc_wq;return 0 ; out: -if (err) +if (err) { +kfree (queue);mana_hwc_destroy_wq (hwc, hwc_wq); + }return err; }
Signature · 1 line
2.30.1 (Apple Git-130)
Quoted 17 lines
From: Dhiraj Shah <[email protected]>
Sent: Thursday, June 10, 2021 8:29 AM
...
memory space allocated for the queue in functionmana_gd_create_hwc_queueis not freed during error condition.Signed-off-by Dhiraj Shah <[email protected]>--- drivers/net/ethernet/microsoft/mana/hw_channel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0
drivers/net/ethernet/microsoft/mana/hw_channel.c static int mana_hwc_create_wq(struct · line 505
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +1
-1@@ -501,8 +501,10 @@ static int mana_hwc_create_wq(structhw_channel_context *hwc, *hwc_wq_ptr = hwc_wq;return 0 ; out: -if (err) +if (err) {
Here the 'err' must be non-zero. Can you please remove this 'if'?
drivers/net/ethernet/microsoft/mana/hw_channel.c static int mana_hwc_create_wq(struct hw_channel_context *hwc, · line 509
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +2
-0+kfree (queue);mana_hwc_destroy_wq (hwc, hwc_wq); + }return err; }
Dexuan Cui
maintainerQuoted 18 lines
From: Dexuan Cui <[email protected]>
Sent: Thursday, June 10, 2021 10:18 AM
...drivers/net/ethernet/microsoft/mana/hw_channel.c static int mana_hwc_create_wq(struct · line 505
Quoted 12 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +1
-1@@ -501,8 +501,10 @@ static int mana_hwc_create_wq(structhw_channel_context *hwc, *hwc_wq_ptr = hwc_wq;return 0 ; out: -if (err) +if (err) {Here the 'err' must be non-zero. Can you please remove this 'if'?
Quoted 7 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c static int mana_hwc_create_wq(struct hw_channel_context *hwc, · line 509
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +2
-0+kfree (queue);mana_hwc_destroy_wq (hwc, hwc_wq); + }return err; }Reviewed-by Dexuan Cui <[email protected]>
Hi Dhiraj,
I checked the code again and it looks like your patch is actually unnecessary as IMO there is no memory leak here: the 'queue' pointer is passed to mana_hwc_destroy_wq() as hwc_wq->gdma_wq, and is later freed in mana_gd_destroy_queue() -> mana_gd_destroy_queue().
The 'if' test can be removed as the 'err's is always non-zero there.
Thanks,
Dexuan
Hi Dexuan,
Thanks for the feedback.
You are right saying ‘mana_hwc_destroy_wq' free’s up the queue.
However for example if function 'mana_hwc_alloc_dma_buf' fails it will goto ‘out' and call ‘mana_hwc_destroy_wq', the value 'hwc_wq->gdma_wq' is still not assigned at this point. In the ‘mana_hwc_destroy_wq' function i see it checks for 'hwc_wq->gdma_wq' before calling, ‘mana_gd_destroy_queue', which makes me think queue is still not freed.
Please let me know if i am missing something.
Regards,
/Dhiraj
Quoted 39 lines · Dexuan Cui
Quoted 19 lines
From: Dexuan Cui <[email protected]>
Sent: Thursday, June 10, 2021 10:18 AM
...drivers/net/ethernet/microsoft/mana/hw_channel.c static int mana_hwc_create_wq(struct hw_channel_context *hwc, · line 504
Quoted 12 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0@@ -501,8 +501,10 @@ static int mana_hwc_create_wq(structhw_channel_context *hwc, *hwc_wq_ptr = hwc_wq;return 0 ;out:
drivers/net/ethernet/microsoft/mana/hw_channel.c +1
-1-if (err) +if (err) {Here the 'err' must be non-zero. Can you please remove this 'if'?
Quoted 7 lines
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +1
-0+kfree (queue);mana_hwc_destroy_wq(hwc, hwc_wq);drivers/net/ethernet/microsoft/mana/hw_channel.c +1
-0+ }return err; }Reviewed-by Dexuan Cui <[email protected]>Hi Dhiraj,
I checked the code again and it looks like your patch is actually unnecessary as IMO there is no memory leak here: the 'queue' pointer is passed tomana_hwc_destroy_wq()ashwc_wq->gdma_wq, and is later freed inmana_gd_destroy_queue()->mana_gd_destroy_queue().The 'if' test can be removed as the 'err's is always non-zero there.
Thanks,
Dexuan
Dexuan Cui
maintainerQuoted 5 lines
From: Dhiraj Shah <[email protected]>
Sent: Thursday, June 10, 2021 12:53 PM
...
Hi Dexuan,
Quoted 7 lines
Thanks for the feedback.
You are right saying ‘mana_hwc_destroy_wq' free’s up the queue.
However for example if function '
mana_hwc_alloc_dma_buf' fails it will goto ‘out' and call ‘mana_hwc_destroy_wq', the value 'hwc_wq->gdma_wq' is still not assigned at this point. In the ‘mana_hwc_destroy_wq' function i see
At this point, hwc_wq->gdma_wq stays with its default value NULL.
Quoted 2 lines
it checks for '
hwc_wq->gdma_wq' before calling, ‘mana_gd_destroy_queue', which makes me think queue is still not freed.
IMO the current code is not buggy, though I admit it's not very readable. :-)
If you're interested, you're welcome to help make it more readable. I'll also try to make some time on this.
Thanks,
Dexuan