netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: pch_gbe: Fix memory leaks
@ 2019-08-14  1:33 Wenwen Wang
  2019-08-15 19:34 ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Wenwen Wang @ 2019-08-14  1:33 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: David S. Miller, Richard Fontana, Allison Randal, Alexios Zavras,
	Greg Kroah-Hartman, Thomas Gleixner,
	open list:NETWORKING DRIVERS, open list

In pch_gbe_set_ringparam(), if netif_running() returns false, 'tx_old' and
'rx_old' are not deallocated, leading to memory leaks. To fix this issue,
move the free statements after the if branch.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
 drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_ethtool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_ethtool.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_ethtool.c
index 1a3008e..ef6311cd 100644
--- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_ethtool.c
+++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_ethtool.c
@@ -340,12 +340,12 @@ static int pch_gbe_set_ringparam(struct net_device *netdev,
 			goto err_setup_tx;
 		pch_gbe_free_rx_resources(adapter, rx_old);
 		pch_gbe_free_tx_resources(adapter, tx_old);
-		kfree(tx_old);
-		kfree(rx_old);
 		adapter->rx_ring = rxdr;
 		adapter->tx_ring = txdr;
 		err = pch_gbe_up(adapter);
 	}
+	kfree(tx_old);
+	kfree(rx_old);
 	return err;
 
 err_setup_tx:
-- 
2.7.4


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

* Re: [PATCH] net: pch_gbe: Fix memory leaks
  2019-08-14  1:33 [PATCH] net: pch_gbe: Fix memory leaks Wenwen Wang
@ 2019-08-15 19:34 ` David Miller
  2019-08-15 20:03   ` Wenwen Wang
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2019-08-15 19:34 UTC (permalink / raw)
  To: wenwen
  Cc: rfontana, allison, alexios.zavras, gregkh, tglx, netdev, linux-kernel

From: Wenwen Wang <wenwen@cs.uga.edu>
Date: Tue, 13 Aug 2019 20:33:45 -0500

> In pch_gbe_set_ringparam(), if netif_running() returns false, 'tx_old' and
> 'rx_old' are not deallocated, leading to memory leaks. To fix this issue,
> move the free statements after the if branch.
> 
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>

Why would they be "deallocated"?  They are still assigned to
adapter->tx_ring and adapter->rx_ring.

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

* Re: [PATCH] net: pch_gbe: Fix memory leaks
  2019-08-15 19:34 ` David Miller
@ 2019-08-15 20:03   ` Wenwen Wang
  2019-08-15 20:42     ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Wenwen Wang @ 2019-08-15 20:03 UTC (permalink / raw)
  To: David Miller
  Cc: Richard Fontana, Allison Randal, Alexios Zavras,
	Greg Kroah-Hartman, Thomas Gleixner,
	open list:NETWORKING [GENERAL],
	open list, Wenwen Wang

On Thu, Aug 15, 2019 at 3:34 PM David Miller <davem@davemloft.net> wrote:
>
> From: Wenwen Wang <wenwen@cs.uga.edu>
> Date: Tue, 13 Aug 2019 20:33:45 -0500
>
> > In pch_gbe_set_ringparam(), if netif_running() returns false, 'tx_old' and
> > 'rx_old' are not deallocated, leading to memory leaks. To fix this issue,
> > move the free statements after the if branch.
> >
> > Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
>
> Why would they be "deallocated"?  They are still assigned to
> adapter->tx_ring and adapter->rx_ring.

'adapter->tx_ring' and 'adapter->rx_ring' has been covered by newly
allocated 'txdr' and 'rxdr' respectively before this if statement.

Wenwen

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

* Re: [PATCH] net: pch_gbe: Fix memory leaks
  2019-08-15 20:03   ` Wenwen Wang
@ 2019-08-15 20:42     ` David Miller
  2019-08-15 20:46       ` Wenwen Wang
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2019-08-15 20:42 UTC (permalink / raw)
  To: wenwen
  Cc: rfontana, allison, alexios.zavras, gregkh, tglx, netdev, linux-kernel

From: Wenwen Wang <wenwen@cs.uga.edu>
Date: Thu, 15 Aug 2019 16:03:39 -0400

> On Thu, Aug 15, 2019 at 3:34 PM David Miller <davem@davemloft.net> wrote:
>>
>> From: Wenwen Wang <wenwen@cs.uga.edu>
>> Date: Tue, 13 Aug 2019 20:33:45 -0500
>>
>> > In pch_gbe_set_ringparam(), if netif_running() returns false, 'tx_old' and
>> > 'rx_old' are not deallocated, leading to memory leaks. To fix this issue,
>> > move the free statements after the if branch.
>> >
>> > Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
>>
>> Why would they be "deallocated"?  They are still assigned to
>> adapter->tx_ring and adapter->rx_ring.
> 
> 'adapter->tx_ring' and 'adapter->rx_ring' has been covered by newly
> allocated 'txdr' and 'rxdr' respectively before this if statement.

That only happens inside of the if() statement, that's why rx_old and
tx_old are only freed in that code path.

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

* Re: [PATCH] net: pch_gbe: Fix memory leaks
  2019-08-15 20:42     ` David Miller
@ 2019-08-15 20:46       ` Wenwen Wang
  2019-08-15 20:51         ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Wenwen Wang @ 2019-08-15 20:46 UTC (permalink / raw)
  To: David Miller
  Cc: Richard Fontana, Allison Randal, Alexios Zavras,
	Greg Kroah-Hartman, Thomas Gleixner,
	open list:NETWORKING [GENERAL],
	open list, Wenwen Wang

On Thu, Aug 15, 2019 at 4:42 PM David Miller <davem@davemloft.net> wrote:
>
> From: Wenwen Wang <wenwen@cs.uga.edu>
> Date: Thu, 15 Aug 2019 16:03:39 -0400
>
> > On Thu, Aug 15, 2019 at 3:34 PM David Miller <davem@davemloft.net> wrote:
> >>
> >> From: Wenwen Wang <wenwen@cs.uga.edu>
> >> Date: Tue, 13 Aug 2019 20:33:45 -0500
> >>
> >> > In pch_gbe_set_ringparam(), if netif_running() returns false, 'tx_old' and
> >> > 'rx_old' are not deallocated, leading to memory leaks. To fix this issue,
> >> > move the free statements after the if branch.
> >> >
> >> > Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> >>
> >> Why would they be "deallocated"?  They are still assigned to
> >> adapter->tx_ring and adapter->rx_ring.
> >
> > 'adapter->tx_ring' and 'adapter->rx_ring' has been covered by newly
> > allocated 'txdr' and 'rxdr' respectively before this if statement.
>
> That only happens inside of the if() statement, that's why rx_old and
> tx_old are only freed in that code path.

That happens not only inside of the if statement, but also before the
if statement, just after 'txdr' and 'rxdr' are allocated.

Wenwen

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

* Re: [PATCH] net: pch_gbe: Fix memory leaks
  2019-08-15 20:46       ` Wenwen Wang
@ 2019-08-15 20:51         ` David Miller
  2019-08-21  4:10           ` Wenwen Wang
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2019-08-15 20:51 UTC (permalink / raw)
  To: wenwen
  Cc: rfontana, allison, alexios.zavras, gregkh, tglx, netdev, linux-kernel

From: Wenwen Wang <wenwen@cs.uga.edu>
Date: Thu, 15 Aug 2019 16:46:05 -0400

> On Thu, Aug 15, 2019 at 4:42 PM David Miller <davem@davemloft.net> wrote:
>>
>> From: Wenwen Wang <wenwen@cs.uga.edu>
>> Date: Thu, 15 Aug 2019 16:03:39 -0400
>>
>> > On Thu, Aug 15, 2019 at 3:34 PM David Miller <davem@davemloft.net> wrote:
>> >>
>> >> From: Wenwen Wang <wenwen@cs.uga.edu>
>> >> Date: Tue, 13 Aug 2019 20:33:45 -0500
>> >>
>> >> > In pch_gbe_set_ringparam(), if netif_running() returns false, 'tx_old' and
>> >> > 'rx_old' are not deallocated, leading to memory leaks. To fix this issue,
>> >> > move the free statements after the if branch.
>> >> >
>> >> > Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
>> >>
>> >> Why would they be "deallocated"?  They are still assigned to
>> >> adapter->tx_ring and adapter->rx_ring.
>> >
>> > 'adapter->tx_ring' and 'adapter->rx_ring' has been covered by newly
>> > allocated 'txdr' and 'rxdr' respectively before this if statement.
>>
>> That only happens inside of the if() statement, that's why rx_old and
>> tx_old are only freed in that code path.
> 
> That happens not only inside of the if statement, but also before the
> if statement, just after 'txdr' and 'rxdr' are allocated.

Then the assignments inside of the if() statement are redundant.

Something doesn't add up here, please make the code consistent.

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

* Re: [PATCH] net: pch_gbe: Fix memory leaks
  2019-08-15 20:51         ` David Miller
@ 2019-08-21  4:10           ` Wenwen Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Wenwen Wang @ 2019-08-21  4:10 UTC (permalink / raw)
  To: David Miller
  Cc: Richard Fontana, Allison Randal, Alexios Zavras,
	Greg Kroah-Hartman, Thomas Gleixner,
	open list:NETWORKING [GENERAL],
	open list, Wenwen Wang

On Thu, Aug 15, 2019 at 4:51 PM David Miller <davem@davemloft.net> wrote:
>
> From: Wenwen Wang <wenwen@cs.uga.edu>
> Date: Thu, 15 Aug 2019 16:46:05 -0400
>
> > On Thu, Aug 15, 2019 at 4:42 PM David Miller <davem@davemloft.net> wrote:
> >>
> >> From: Wenwen Wang <wenwen@cs.uga.edu>
> >> Date: Thu, 15 Aug 2019 16:03:39 -0400
> >>
> >> > On Thu, Aug 15, 2019 at 3:34 PM David Miller <davem@davemloft.net> wrote:
> >> >>
> >> >> From: Wenwen Wang <wenwen@cs.uga.edu>
> >> >> Date: Tue, 13 Aug 2019 20:33:45 -0500
> >> >>
> >> >> > In pch_gbe_set_ringparam(), if netif_running() returns false, 'tx_old' and
> >> >> > 'rx_old' are not deallocated, leading to memory leaks. To fix this issue,
> >> >> > move the free statements after the if branch.
> >> >> >
> >> >> > Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> >> >>
> >> >> Why would they be "deallocated"?  They are still assigned to
> >> >> adapter->tx_ring and adapter->rx_ring.
> >> >
> >> > 'adapter->tx_ring' and 'adapter->rx_ring' has been covered by newly
> >> > allocated 'txdr' and 'rxdr' respectively before this if statement.
> >>
> >> That only happens inside of the if() statement, that's why rx_old and
> >> tx_old are only freed in that code path.
> >
> > That happens not only inside of the if statement, but also before the
> > if statement, just after 'txdr' and 'rxdr' are allocated.
>
> Then the assignments inside of the if() statement are redundant.
>
> Something doesn't add up here, please make the code consistent.

Thanks for your suggestion! I will remove the assignments inside of
the if() statement.

Wenwen

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

end of thread, other threads:[~2019-08-21  4:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-14  1:33 [PATCH] net: pch_gbe: Fix memory leaks Wenwen Wang
2019-08-15 19:34 ` David Miller
2019-08-15 20:03   ` Wenwen Wang
2019-08-15 20:42     ` David Miller
2019-08-15 20:46       ` Wenwen Wang
2019-08-15 20:51         ` David Miller
2019-08-21  4:10           ` Wenwen Wang

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