Skip to content

Commit

Permalink
dsa: factor freeing of dsa_platform_data
Browse files Browse the repository at this point in the history
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: Florian Fainelli <florian@openwrt.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Florian Fainelli authored and David S. Miller committed Mar 25, 2013
1 parent 4c64f1f commit 2116824
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions net/dsa/dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,21 @@ static int dsa_of_setup_routing_table(struct dsa_platform_data *pd,
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)
{
struct device_node *np = pdev->dev.of_node;
Expand All @@ -354,7 +369,7 @@ static int dsa_of_probe(struct platform_device *pdev)
const char *port_name;
int chip_index, port_index;
const unsigned int *sw_addr, *port_reg;
int ret, i;
int ret;

mdio = of_parse_phandle(np, "dsa,mii-bus", 0);
if (!mdio)
Expand Down Expand Up @@ -439,14 +454,7 @@ static int dsa_of_probe(struct platform_device *pdev)
return 0;

out_free_chip:
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);
dsa_of_free_platform_data(pd);
out_free:
kfree(pd);
pdev->dev.platform_data = NULL;
Expand All @@ -456,21 +464,11 @@ static int dsa_of_probe(struct platform_device *pdev)
static void dsa_of_remove(struct platform_device *pdev)
{
struct dsa_platform_data *pd = pdev->dev.platform_data;
int i;
int port_index;

if (!pdev->dev.of_node)
return;

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);
dsa_of_free_platform_data(pd);
kfree(pd);
}
#else
Expand Down

0 comments on commit 2116824

Please sign in to comment.