diff options
| author | Vivien Didelot <vivien.didelot@savoirfairelinux.com> | 2017-11-06 16:11:52 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2017-11-08 19:26:49 -0500 |
| commit | 308173546ac4342103541e8d4e4ce83d1a5e7eba (patch) | |
| tree | f23ebf7db31d677798c44573133658aae9510c28 /net | |
| parent | 34c09a8916fb52aac948dfc861b33c0b3b37ac29 (diff) | |
net: dsa: setup a tree when adding a switch to it
Now that the tree setup is centralized, we can simplify the code a bit
more by setting up or tearing down the tree directly when adding or
removing a switch to/from it.
Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
| -rw-r--r-- | net/dsa/dsa2.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 44d26b5977cd..3db50e68640e 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c | |||
| @@ -489,6 +489,8 @@ static void dsa_tree_teardown(struct dsa_switch_tree *dst) | |||
| 489 | static void dsa_tree_remove_switch(struct dsa_switch_tree *dst, | 489 | static void dsa_tree_remove_switch(struct dsa_switch_tree *dst, |
| 490 | unsigned int index) | 490 | unsigned int index) |
| 491 | { | 491 | { |
| 492 | dsa_tree_teardown(dst); | ||
| 493 | |||
| 492 | dst->ds[index] = NULL; | 494 | dst->ds[index] = NULL; |
| 493 | dsa_tree_put(dst); | 495 | dsa_tree_put(dst); |
| 494 | } | 496 | } |
| @@ -497,6 +499,7 @@ static int dsa_tree_add_switch(struct dsa_switch_tree *dst, | |||
| 497 | struct dsa_switch *ds) | 499 | struct dsa_switch *ds) |
| 498 | { | 500 | { |
| 499 | unsigned int index = ds->index; | 501 | unsigned int index = ds->index; |
| 502 | int err; | ||
| 500 | 503 | ||
| 501 | if (dst->ds[index]) | 504 | if (dst->ds[index]) |
| 502 | return -EBUSY; | 505 | return -EBUSY; |
| @@ -504,7 +507,11 @@ static int dsa_tree_add_switch(struct dsa_switch_tree *dst, | |||
| 504 | dsa_tree_get(dst); | 507 | dsa_tree_get(dst); |
| 505 | dst->ds[index] = ds; | 508 | dst->ds[index] = ds; |
| 506 | 509 | ||
| 507 | return 0; | 510 | err = dsa_tree_setup(dst); |
| 511 | if (err) | ||
| 512 | dsa_tree_remove_switch(dst, index); | ||
| 513 | |||
| 514 | return err; | ||
| 508 | } | 515 | } |
| 509 | 516 | ||
| 510 | static int dsa_port_parse_user(struct dsa_port *dp, const char *name) | 517 | static int dsa_port_parse_user(struct dsa_port *dp, const char *name) |
| @@ -704,12 +711,17 @@ static int dsa_switch_parse(struct dsa_switch *ds, struct dsa_chip_data *cd) | |||
| 704 | return dsa_switch_parse_ports(ds, cd); | 711 | return dsa_switch_parse_ports(ds, cd); |
| 705 | } | 712 | } |
| 706 | 713 | ||
| 714 | static int dsa_switch_add(struct dsa_switch *ds) | ||
| 715 | { | ||
| 716 | struct dsa_switch_tree *dst = ds->dst; | ||
| 717 | |||
| 718 | return dsa_tree_add_switch(dst, ds); | ||
| 719 | } | ||
| 720 | |||
| 707 | static int _dsa_register_switch(struct dsa_switch *ds) | 721 | static int _dsa_register_switch(struct dsa_switch *ds) |
| 708 | { | 722 | { |
| 709 | struct dsa_chip_data *pdata = ds->dev->platform_data; | 723 | struct dsa_chip_data *pdata = ds->dev->platform_data; |
| 710 | struct device_node *np = ds->dev->of_node; | 724 | struct device_node *np = ds->dev->of_node; |
| 711 | struct dsa_switch_tree *dst; | ||
| 712 | unsigned int index; | ||
| 713 | int err; | 725 | int err; |
| 714 | 726 | ||
| 715 | if (np) | 727 | if (np) |
| @@ -722,20 +734,7 @@ static int _dsa_register_switch(struct dsa_switch *ds) | |||
| 722 | if (err) | 734 | if (err) |
| 723 | return err; | 735 | return err; |
| 724 | 736 | ||
| 725 | index = ds->index; | 737 | return dsa_switch_add(ds); |
| 726 | dst = ds->dst; | ||
| 727 | |||
| 728 | err = dsa_tree_add_switch(dst, ds); | ||
| 729 | if (err) | ||
| 730 | return err; | ||
| 731 | |||
| 732 | err = dsa_tree_setup(dst); | ||
| 733 | if (err) { | ||
| 734 | dsa_tree_teardown(dst); | ||
| 735 | dsa_tree_remove_switch(dst, index); | ||
| 736 | } | ||
| 737 | |||
| 738 | return err; | ||
| 739 | } | 738 | } |
| 740 | 739 | ||
| 741 | struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n) | 740 | struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n) |
| @@ -777,8 +776,6 @@ static void _dsa_unregister_switch(struct dsa_switch *ds) | |||
| 777 | struct dsa_switch_tree *dst = ds->dst; | 776 | struct dsa_switch_tree *dst = ds->dst; |
| 778 | unsigned int index = ds->index; | 777 | unsigned int index = ds->index; |
| 779 | 778 | ||
| 780 | dsa_tree_teardown(dst); | ||
| 781 | |||
| 782 | dsa_tree_remove_switch(dst, index); | 779 | dsa_tree_remove_switch(dst, index); |
| 783 | } | 780 | } |
| 784 | 781 | ||
