linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] niu: Use refcount_t for refcount
@ 2019-08-02 12:57 Chuhong Yuan
  2019-08-02 16:16 ` Chuhong Yuan
  0 siblings, 1 reply; 2+ messages in thread
From: Chuhong Yuan @ 2019-08-02 12:57 UTC (permalink / raw)
  Cc: David S . Miller, netdev, linux-kernel, Chuhong Yuan

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 <hslester96@gmail.com>
---
 drivers/net/ethernet/sun/niu.c | 6 +++---
 drivers/net/ethernet/sun/niu.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c
index 0bc5863bffeb..5bf096e51db7 100644
--- a/drivers/net/ethernet/sun/niu.c
+++ b/drivers/net/ethernet/sun/niu.c
@@ -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);
 	}
diff --git a/drivers/net/ethernet/sun/niu.h b/drivers/net/ethernet/sun/niu.h
index 04c215f91fc0..755e6dd4c903 100644
--- a/drivers/net/ethernet/sun/niu.h
+++ b/drivers/net/ethernet/sun/niu.h
@@ -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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] niu: Use refcount_t for refcount
  2019-08-02 12:57 [PATCH] niu: Use refcount_t for refcount Chuhong Yuan
@ 2019-08-02 16:16 ` Chuhong Yuan
  0 siblings, 0 replies; 2+ messages in thread
From: Chuhong Yuan @ 2019-08-02 16:16 UTC (permalink / raw)
  Cc: David S . Miller, Netdev, LKML

Chuhong Yuan <hslester96@gmail.com> 于2019年8月2日周五 下午8:57写道:
>
> 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.

It seems that directly converting refcount from 0-based to
1-based is infeasible.
I am sorry for this mistake.

Regards,
Chuhong

>
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
>  drivers/net/ethernet/sun/niu.c | 6 +++---
>  drivers/net/ethernet/sun/niu.h | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c
> index 0bc5863bffeb..5bf096e51db7 100644
> --- a/drivers/net/ethernet/sun/niu.c
> +++ b/drivers/net/ethernet/sun/niu.c
> @@ -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);
>         }
> diff --git a/drivers/net/ethernet/sun/niu.h b/drivers/net/ethernet/sun/niu.h
> index 04c215f91fc0..755e6dd4c903 100644
> --- a/drivers/net/ethernet/sun/niu.h
> +++ b/drivers/net/ethernet/sun/niu.h
> @@ -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
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-02 16:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-02 12:57 [PATCH] niu: Use refcount_t for refcount Chuhong Yuan
2019-08-02 16:16 ` Chuhong Yuan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).