diff options
author | Florian Fainelli <florian@openwrt.org> | 2013-03-25 01:03:39 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-03-25 12:23:41 -0400 |
commit | 21168245031062212c0b805d0bd466ee6dd4a16f (patch) | |
tree | c962fb3124dbb8fb4f69f5a0a71e9f39d80e02cb /net/dsa | |
parent | 4c64f1f70cf3e7860bae12d62a31c137a6a4f4a7 (diff) |
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: Florian Fainelli <florian@openwrt.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa')
-rw-r--r-- | net/dsa/dsa.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 908bc11082db..aa2ff583b7ed 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c | |||
@@ -343,6 +343,21 @@ out: | |||
343 | return ret; | 343 | return ret; |
344 | } | 344 | } |
345 | 345 | ||
346 | static void dsa_of_free_platform_data(struct dsa_platform_data *pd) | ||
347 | { | ||
348 | int i; | ||
349 | int port_index; | ||
350 | |||
351 | for (i = 0; i < pd->nr_chips; i++) { | ||
352 | port_index = 0; | ||
353 | while (pd->chip[i].port_names && | ||
354 | pd->chip[i].port_names[++port_index]) | ||
355 | kfree(pd->chip[i].port_names[port_index]); | ||
356 | kfree(pd->chip[i].rtable); | ||
357 | } | ||
358 | kfree(pd->chip); | ||
359 | } | ||
360 | |||
346 | static int dsa_of_probe(struct platform_device *pdev) | 361 | static int dsa_of_probe(struct platform_device *pdev) |
347 | { | 362 | { |
348 | struct device_node *np = pdev->dev.of_node; | 363 | struct device_node *np = pdev->dev.of_node; |
@@ -354,7 +369,7 @@ static int dsa_of_probe(struct platform_device *pdev) | |||
354 | const char *port_name; | 369 | const char *port_name; |
355 | int chip_index, port_index; | 370 | int chip_index, port_index; |
356 | const unsigned int *sw_addr, *port_reg; | 371 | const unsigned int *sw_addr, *port_reg; |
357 | int ret, i; | 372 | int ret; |
358 | 373 | ||
359 | mdio = of_parse_phandle(np, "dsa,mii-bus", 0); | 374 | mdio = of_parse_phandle(np, "dsa,mii-bus", 0); |
360 | if (!mdio) | 375 | if (!mdio) |
@@ -439,14 +454,7 @@ static int dsa_of_probe(struct platform_device *pdev) | |||
439 | return 0; | 454 | return 0; |
440 | 455 | ||
441 | out_free_chip: | 456 | out_free_chip: |
442 | for (i = 0; i < pd->nr_chips; i++) { | 457 | dsa_of_free_platform_data(pd); |
443 | port_index = 0; | ||
444 | while (pd->chip[i].port_names && | ||
445 | pd->chip[i].port_names[++port_index]) | ||
446 | kfree(pd->chip[i].port_names[port_index]); | ||
447 | kfree(pd->chip[i].rtable); | ||
448 | } | ||
449 | kfree(pd->chip); | ||
450 | out_free: | 458 | out_free: |
451 | kfree(pd); | 459 | kfree(pd); |
452 | pdev->dev.platform_data = NULL; | 460 | pdev->dev.platform_data = NULL; |
@@ -456,21 +464,11 @@ out_free: | |||
456 | static void dsa_of_remove(struct platform_device *pdev) | 464 | static void dsa_of_remove(struct platform_device *pdev) |
457 | { | 465 | { |
458 | struct dsa_platform_data *pd = pdev->dev.platform_data; | 466 | struct dsa_platform_data *pd = pdev->dev.platform_data; |
459 | int i; | ||
460 | int port_index; | ||
461 | 467 | ||
462 | if (!pdev->dev.of_node) | 468 | if (!pdev->dev.of_node) |
463 | return; | 469 | return; |
464 | 470 | ||
465 | for (i = 0; i < pd->nr_chips; i++) { | 471 | dsa_of_free_platform_data(pd); |
466 | port_index = 0; | ||
467 | while (pd->chip[i].port_names && | ||
468 | pd->chip[i].port_names[++port_index]) | ||
469 | kfree(pd->chip[i].port_names[port_index]); | ||
470 | kfree(pd->chip[i].rtable); | ||
471 | } | ||
472 | |||
473 | kfree(pd->chip); | ||
474 | kfree(pd); | 472 | kfree(pd); |
475 | } | 473 | } |
476 | #else | 474 | #else |