Skip to content

Commit 6da2a94

Browse files
viviendavem330
authored andcommitted
net: dsa: rework switch addition and removal
This patch removes the unnecessary index argument from the dsa_dst_add_ds and dsa_dst_del_ds functions and renames them to dsa_tree_add_switch and dsa_tree_remove_switch respectively. In addition to a more explicit scope, we now check the presence of an existing switch with the same index directly within dsa_tree_add_switch. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1ca28ec commit 6da2a94

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

net/dsa/dsa2.c

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,6 @@ static void dsa_tree_put(struct dsa_switch_tree *dst)
9494
kref_put(&dst->refcount, dsa_tree_release);
9595
}
9696

97-
static void dsa_dst_add_ds(struct dsa_switch_tree *dst,
98-
struct dsa_switch *ds, u32 index)
99-
{
100-
dsa_tree_get(dst);
101-
dst->ds[index] = ds;
102-
}
103-
104-
static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
105-
struct dsa_switch *ds, u32 index)
106-
{
107-
dst->ds[index] = NULL;
108-
dsa_tree_put(dst);
109-
}
110-
11197
/* For platform data configurations, we need to have a valid name argument to
11298
* differentiate a disabled port from an enabled one
11399
*/
@@ -484,6 +470,27 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
484470
dst->applied = false;
485471
}
486472

473+
static void dsa_tree_remove_switch(struct dsa_switch_tree *dst,
474+
unsigned int index)
475+
{
476+
dst->ds[index] = NULL;
477+
dsa_tree_put(dst);
478+
}
479+
480+
static int dsa_tree_add_switch(struct dsa_switch_tree *dst,
481+
struct dsa_switch *ds)
482+
{
483+
unsigned int index = ds->index;
484+
485+
if (dst->ds[index])
486+
return -EBUSY;
487+
488+
dsa_tree_get(dst);
489+
dst->ds[index] = ds;
490+
491+
return 0;
492+
}
493+
487494
static int dsa_cpu_parse(struct dsa_port *port, u32 index,
488495
struct dsa_switch_tree *dst,
489496
struct dsa_switch *ds)
@@ -762,9 +769,6 @@ static int _dsa_register_switch(struct dsa_switch *ds)
762769
if (!dst)
763770
return -ENOMEM;
764771

765-
if (dst->ds[index])
766-
return -EBUSY;
767-
768772
ds->dst = dst;
769773
ds->index = index;
770774
ds->cd = pdata;
@@ -773,7 +777,9 @@ static int _dsa_register_switch(struct dsa_switch *ds)
773777
for (i = 0; i < DSA_MAX_SWITCHES; ++i)
774778
ds->rtable[i] = DSA_RTABLE_NONE;
775779

776-
dsa_dst_add_ds(dst, ds, index);
780+
err = dsa_tree_add_switch(dst, ds);
781+
if (err)
782+
return err;
777783

778784
err = dsa_dst_complete(dst);
779785
if (err < 0)
@@ -801,7 +807,7 @@ static int _dsa_register_switch(struct dsa_switch *ds)
801807
return 0;
802808

803809
out_del_dst:
804-
dsa_dst_del_ds(dst, ds, ds->index);
810+
dsa_tree_remove_switch(dst, index);
805811

806812
return err;
807813
}
@@ -843,10 +849,11 @@ EXPORT_SYMBOL_GPL(dsa_register_switch);
843849
static void _dsa_unregister_switch(struct dsa_switch *ds)
844850
{
845851
struct dsa_switch_tree *dst = ds->dst;
852+
unsigned int index = ds->index;
846853

847854
dsa_dst_unapply(dst);
848855

849-
dsa_dst_del_ds(dst, ds, ds->index);
856+
dsa_tree_remove_switch(dst, index);
850857
}
851858

852859
void dsa_unregister_switch(struct dsa_switch *ds)

0 commit comments

Comments
 (0)