Skip to content

Commit ec15dd4

Browse files
viviendavem330
authored andcommitted
net: dsa: setup and teardown tree
This commit provides better scope for the DSA tree setup and teardown functions. It renames the "applied" bool to "setup" and print a message when the tree is setup, as it is done during teardown. At the same time, check dst->setup in dsa_tree_setup, where it is set to true. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 17a22fc commit ec15dd4

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

include/net/dsa.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct dsa_switch_tree {
122122
struct kref refcount;
123123

124124
/* Has this tree been applied to the hardware? */
125-
bool applied;
125+
bool setup;
126126

127127
/*
128128
* Configuration data for the platform device that owns

net/dsa/dsa2.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,18 @@ static void dsa_tree_teardown_master(struct dsa_switch_tree *dst)
486486
return dsa_master_teardown(master);
487487
}
488488

489-
static int dsa_dst_apply(struct dsa_switch_tree *dst)
489+
static int dsa_tree_setup(struct dsa_switch_tree *dst)
490490
{
491491
struct dsa_switch *ds;
492492
u32 index;
493493
int err;
494494

495+
if (dst->setup) {
496+
pr_err("DSA: tree %d already setup! Disjoint trees?\n",
497+
dst->index);
498+
return -EEXIST;
499+
}
500+
495501
err = dsa_tree_setup_default_cpu(dst);
496502
if (err)
497503
return err;
@@ -510,17 +516,19 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
510516
if (err)
511517
return err;
512518

513-
dst->applied = true;
519+
dst->setup = true;
520+
521+
pr_info("DSA: tree %d setup\n", dst->index);
514522

515523
return 0;
516524
}
517525

518-
static void dsa_dst_unapply(struct dsa_switch_tree *dst)
526+
static void dsa_tree_teardown(struct dsa_switch_tree *dst)
519527
{
520528
struct dsa_switch *ds;
521529
u32 index;
522530

523-
if (!dst->applied)
531+
if (!dst->setup)
524532
return;
525533

526534
dsa_tree_teardown_master(dst);
@@ -535,8 +543,9 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
535543

536544
dsa_tree_teardown_default_cpu(dst);
537545

538-
pr_info("DSA: tree %d unapplied\n", dst->index);
539-
dst->applied = false;
546+
pr_info("DSA: tree %d torn down\n", dst->index);
547+
548+
dst->setup = false;
540549
}
541550

542551
static void dsa_tree_remove_switch(struct dsa_switch_tree *dst,
@@ -794,14 +803,9 @@ static int _dsa_register_switch(struct dsa_switch *ds)
794803
if (err == 1)
795804
return 0;
796805

797-
if (dst->applied) {
798-
pr_info("DSA: Disjoint trees?\n");
799-
return -EINVAL;
800-
}
801-
802-
err = dsa_dst_apply(dst);
806+
err = dsa_tree_setup(dst);
803807
if (err) {
804-
dsa_dst_unapply(dst);
808+
dsa_tree_teardown(dst);
805809
goto out_del_dst;
806810
}
807811

@@ -852,7 +856,7 @@ static void _dsa_unregister_switch(struct dsa_switch *ds)
852856
struct dsa_switch_tree *dst = ds->dst;
853857
unsigned int index = ds->index;
854858

855-
dsa_dst_unapply(dst);
859+
dsa_tree_teardown(dst);
856860

857861
dsa_tree_remove_switch(dst, index);
858862
}

0 commit comments

Comments
 (0)