Skip to content

Commit

Permalink
hsr: fix a memory leak in hsr_del_port()
Browse files Browse the repository at this point in the history
hsr_del_port() should release all the resources allocated
in hsr_add_port().

As a consequence of this change, hsr_for_each_port() is no
longer safe to work with hsr_del_port(), switch to
list_for_each_entry_safe() as we always hold RTNL lock.

Cc: Arvid Brodin <arvid.brodin@alten.se>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Cong Wang authored and David S. Miller committed Jul 5, 2019
1 parent 114b5b3 commit 619afef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions net/hsr/hsr_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,14 @@ static void hsr_dev_destroy(struct net_device *hsr_dev)
{
struct hsr_priv *hsr;
struct hsr_port *port;
struct hsr_port *tmp;

hsr = netdev_priv(hsr_dev);

hsr_debugfs_term(hsr);

rtnl_lock();
hsr_for_each_port(hsr, port)
list_for_each_entry_safe(port, tmp, &hsr->ports, port_list)
hsr_del_port(port);
rtnl_unlock();

Expand Down Expand Up @@ -428,6 +429,7 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
{
struct hsr_priv *hsr;
struct hsr_port *port;
struct hsr_port *tmp;
int res;

hsr = netdev_priv(hsr_dev);
Expand Down Expand Up @@ -492,7 +494,7 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
return 0;

fail:
hsr_for_each_port(hsr, port)
list_for_each_entry_safe(port, tmp, &hsr->ports, port_list)
hsr_del_port(port);
err_add_port:
hsr_del_node(&hsr->self_node_db);
Expand Down
1 change: 1 addition & 0 deletions net/hsr/hsr_slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,5 @@ void hsr_del_port(struct hsr_port *port)

if (port != master)
dev_put(port->dev);
kfree(port);
}

0 comments on commit 619afef

Please sign in to comment.