From: Chuhong Yuan <hslester96@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: "David S . Miller" <davem@davemloft.net>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Chuhong Yuan <hslester96@gmail.com>
Subject: [PATCH] niu: Use refcount_t for refcount
Date: Fri, 2 Aug 2019 20:57:20 +0800 [thread overview]
Message-ID: <20190802125720.22363-1-hslester96@gmail.com> (raw)
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
next reply other threads:[~2019-08-02 12:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-02 12:57 Chuhong Yuan [this message]
2019-08-02 16:16 ` [PATCH] niu: Use refcount_t for refcount Chuhong Yuan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190802125720.22363-1-hslester96@gmail.com \
--to=hslester96@gmail.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).