niu: Use refcount_t for refcount
Subsystems (2)
PATCH 1/1 niu: Use refcount_t for refcount
refcount_t is better for reference counters since its implementation can prevent overflows.
So convert atomic_t ref counters to refcount_t.
Also convert refcount from 0-based to 1-based.
Signed-off-by Chuhong Yuan <[email protected]>
--- drivers/net/ethernet/sun/niu.c | 6 +++--- drivers/net/ethernet/sun/niu.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/sun/niu.c +3 -3
@@ -9464,7 +9464,7 @@ static struct niu_parent *niu_new_parent(struct niu *np,memcpy (&p->id, id,sizeof (*id)); p->plat_type = ptype;INIT_LIST_HEAD (&p->list); -atomic_set (&p->refcnt,0 ); +refcount_set (&p->refcnt,1 );list_add (&p->list, &niu_parent_list);spin_lock_init (&p->lock);
@@ -9524,7 +9524,7 @@ static struct niu_parent *niu_get_parent(struct niu *np, port_name);if (!err) { p->ports[port] = np; -atomic_inc (&p->refcnt); +refcount_inc (&p->refcnt); } }mutex_unlock (&niu_parent_lock);
@@ -9552,7 +9552,7 @@ static void niu_put_parent(struct niu *np) p->ports[port] =NULL ; np->parent =NULL ; -if (atomic_dec_and_test (&p->refcnt)) { +if (refcount_dec_and_test (&p->refcnt)) {list_del (&p->list);platform_device_unregister (p->plat_dev); }
drivers/net/ethernet/sun/niu.h +1 -1
@@ -3071,7 +3071,7 @@ struct niu_parent {struct niu *ports[NIU_MAX_PORTS ]; -atomic_t refcnt; +refcount_t refcnt;struct list_head list;spinlock_t lock;
Signature · 1 line
2.20.1
Quoted 6 lines · Chuhong Yuan <[email protected]> 于2019年8月2日周五 下午8:57写道:
refcount_tis better for reference counters since its implementation can prevent overflows.
So convertatomic_tref counters torefcount_t.Also convert refcount from 0-based to 1-based.
It seems that directly converting refcount from 0-based to 1-based is infeasible.
I am sorry for this mistake.
Regards,
Chuhong
Quoted 54 lines
Signed-off-by Chuhong Yuan <[email protected]>--- drivers/net/ethernet/sun/niu.c | 6 +++--- drivers/net/ethernet/sun/niu.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)drivers/net/ethernet/sun/niu.c +3
-3@@ -9464,7 +9464,7 @@ static struct niu_parent *niu_new_parent(struct niu *np,memcpy (&p->id, id,sizeof (*id)); p->plat_type = ptype;INIT_LIST_HEAD (&p->list); -atomic_set (&p->refcnt,0 ); +refcount_set (&p->refcnt,1 );list_add (&p->list, &niu_parent_list);spin_lock_init (&p->lock);@@ -9524,7 +9524,7 @@ static struct niu_parent *niu_get_parent(struct niu *np, port_name);if (!err) { p->ports[port] = np; -atomic_inc (&p->refcnt); +refcount_inc (&p->refcnt); } }mutex_unlock (&niu_parent_lock);@@ -9552,7 +9552,7 @@ static void niu_put_parent(struct niu *np) p->ports[port] =NULL ; np->parent =NULL ; -if (atomic_dec_and_test (&p->refcnt)) { +if (refcount_dec_and_test (&p->refcnt)) {list_del (&p->list);platform_device_unregister (p->plat_dev); }drivers/net/ethernet/sun/niu.h +1
-2@@ -3071,7 +3071,7 @@ struct niu_parent {struct niu *ports[NIU_MAX_PORTS ]; -atomic_t refcnt; +refcount_t refcnt;struct list_head list;spinlock_t lock; --2.20.1