Commit 21168245 authored by Florian Fainelli's avatar Florian Fainelli Committed by David S. Miller

dsa: factor freeing of dsa_platform_data

This patch factors the freeing of the struct dsa_platform_data
manipulated by the driver identically in two places to a single
function.
Signed-off-by: default avatarFlorian Fainelli <florian@openwrt.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4c64f1f7
...@@ -343,6 +343,21 @@ static int dsa_of_setup_routing_table(struct dsa_platform_data *pd, ...@@ -343,6 +343,21 @@ static int dsa_of_setup_routing_table(struct dsa_platform_data *pd,
return ret; return ret;
} }
static void dsa_of_free_platform_data(struct dsa_platform_data *pd)
{
int i;
int port_index;
for (i = 0; i < pd->nr_chips; i++) {
port_index = 0;
while (pd->chip[i].port_names &&
pd->chip[i].port_names[++port_index])
kfree(pd->chip[i].port_names[port_index]);
kfree(pd->chip[i].rtable);
}
kfree(pd->chip);
}
static int dsa_of_probe(struct platform_device *pdev) static int dsa_of_probe(struct platform_device *pdev)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
...@@ -354,7 +369,7 @@ static int dsa_of_probe(struct platform_device *pdev) ...@@ -354,7 +369,7 @@ static int dsa_of_probe(struct platform_device *pdev)
const char *port_name; const char *port_name;
int chip_index, port_index; int chip_index, port_index;
const unsigned int *sw_addr, *port_reg; const unsigned int *sw_addr, *port_reg;
int ret, i; int ret;
mdio = of_parse_phandle(np, "dsa,mii-bus", 0); mdio = of_parse_phandle(np, "dsa,mii-bus", 0);
if (!mdio) if (!mdio)
...@@ -439,14 +454,7 @@ static int dsa_of_probe(struct platform_device *pdev) ...@@ -439,14 +454,7 @@ static int dsa_of_probe(struct platform_device *pdev)
return 0; return 0;
out_free_chip: out_free_chip:
for (i = 0; i < pd->nr_chips; i++) { dsa_of_free_platform_data(pd);
port_index = 0;
while (pd->chip[i].port_names &&
pd->chip[i].port_names[++port_index])
kfree(pd->chip[i].port_names[port_index]);
kfree(pd->chip[i].rtable);
}
kfree(pd->chip);
out_free: out_free:
kfree(pd); kfree(pd);
pdev->dev.platform_data = NULL; pdev->dev.platform_data = NULL;
...@@ -456,21 +464,11 @@ static int dsa_of_probe(struct platform_device *pdev) ...@@ -456,21 +464,11 @@ static int dsa_of_probe(struct platform_device *pdev)
static void dsa_of_remove(struct platform_device *pdev) static void dsa_of_remove(struct platform_device *pdev)
{ {
struct dsa_platform_data *pd = pdev->dev.platform_data; struct dsa_platform_data *pd = pdev->dev.platform_data;
int i;
int port_index;
if (!pdev->dev.of_node) if (!pdev->dev.of_node)
return; return;
for (i = 0; i < pd->nr_chips; i++) { dsa_of_free_platform_data(pd);
port_index = 0;
while (pd->chip[i].port_names &&
pd->chip[i].port_names[++port_index])
kfree(pd->chip[i].port_names[port_index]);
kfree(pd->chip[i].rtable);
}
kfree(pd->chip);
kfree(pd); kfree(pd);
} }
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment