mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-03 21:01:50 +00:00
net: dsa: provide a find or new tree helper
Rename dsa_get_dst to dsa_tree_find since it doesn't increment the reference counter, rename dsa_add_dst to dsa_tree_alloc for symmetry with dsa_tree_free, and provide a convenient dsa_tree_touch function to find or allocate a new tree. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
65254108b4
commit
1ca28ec9ab
1 changed files with 21 additions and 11 deletions
|
@ -21,33 +21,35 @@
|
||||||
|
|
||||||
#include "dsa_priv.h"
|
#include "dsa_priv.h"
|
||||||
|
|
||||||
static LIST_HEAD(dsa_switch_trees);
|
static LIST_HEAD(dsa_tree_list);
|
||||||
static DEFINE_MUTEX(dsa2_mutex);
|
static DEFINE_MUTEX(dsa2_mutex);
|
||||||
|
|
||||||
static const struct devlink_ops dsa_devlink_ops = {
|
static const struct devlink_ops dsa_devlink_ops = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct dsa_switch_tree *dsa_get_dst(unsigned int index)
|
static struct dsa_switch_tree *dsa_tree_find(int index)
|
||||||
{
|
{
|
||||||
struct dsa_switch_tree *dst;
|
struct dsa_switch_tree *dst;
|
||||||
|
|
||||||
list_for_each_entry(dst, &dsa_switch_trees, list)
|
list_for_each_entry(dst, &dsa_tree_list, list)
|
||||||
if (dst->index == index)
|
if (dst->index == index)
|
||||||
return dst;
|
return dst;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dsa_switch_tree *dsa_add_dst(unsigned int index)
|
static struct dsa_switch_tree *dsa_tree_alloc(int index)
|
||||||
{
|
{
|
||||||
struct dsa_switch_tree *dst;
|
struct dsa_switch_tree *dst;
|
||||||
|
|
||||||
dst = kzalloc(sizeof(*dst), GFP_KERNEL);
|
dst = kzalloc(sizeof(*dst), GFP_KERNEL);
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
dst->index = index;
|
dst->index = index;
|
||||||
|
|
||||||
INIT_LIST_HEAD(&dst->list);
|
INIT_LIST_HEAD(&dst->list);
|
||||||
list_add_tail(&dsa_switch_trees, &dst->list);
|
list_add_tail(&dsa_tree_list, &dst->list);
|
||||||
|
|
||||||
/* Initialize the reference counter to the number of switches, not 1 */
|
/* Initialize the reference counter to the number of switches, not 1 */
|
||||||
kref_init(&dst->refcount);
|
kref_init(&dst->refcount);
|
||||||
|
@ -62,6 +64,17 @@ static void dsa_tree_free(struct dsa_switch_tree *dst)
|
||||||
kfree(dst);
|
kfree(dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct dsa_switch_tree *dsa_tree_touch(int index)
|
||||||
|
{
|
||||||
|
struct dsa_switch_tree *dst;
|
||||||
|
|
||||||
|
dst = dsa_tree_find(index);
|
||||||
|
if (!dst)
|
||||||
|
dst = dsa_tree_alloc(index);
|
||||||
|
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
static void dsa_tree_get(struct dsa_switch_tree *dst)
|
static void dsa_tree_get(struct dsa_switch_tree *dst)
|
||||||
{
|
{
|
||||||
kref_get(&dst->refcount);
|
kref_get(&dst->refcount);
|
||||||
|
@ -745,12 +758,9 @@ static int _dsa_register_switch(struct dsa_switch *ds)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
dst = dsa_get_dst(tree);
|
dst = dsa_tree_touch(tree);
|
||||||
if (!dst) {
|
|
||||||
dst = dsa_add_dst(tree);
|
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
|
||||||
|
|
||||||
if (dst->ds[index])
|
if (dst->ds[index])
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue