diff mbox series

[4/4] libceph: introudce a variable to avoid calling refcount_read() twice

Message ID 20180731150747.27745-4-cgxu519@gmx.com (mailing list archive)
State New, archived
Headers show
Series [1/4] ceph: use type refcount_t for refcount of snap realm | expand

Commit Message

Chengguang Xu July 31, 2018, 3:07 p.m. UTC
Calling refcount_read() twice may return different value each time,
so introduce a variable to avoid it.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 net/ceph/osd_client.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 8002b8e9ce24..ee8eb99a06ae 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -1155,8 +1155,8 @@  static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum)
 static struct ceph_osd *get_osd(struct ceph_osd *osd)
 {
 	if (refcount_inc_not_zero(&osd->o_ref)) {
-		dout("get_osd %p %d -> %d\n", osd, refcount_read(&osd->o_ref)-1,
-		     refcount_read(&osd->o_ref));
+		unsigned int refcnt = refcount_read(&osd->o_ref);
+		dout("get_osd %p %d -> %d\n", osd, refcnt - 1, refcnt);
 		return osd;
 	} else {
 		dout("get_osd %p FAIL\n", osd);
@@ -1166,8 +1166,8 @@  static struct ceph_osd *get_osd(struct ceph_osd *osd)
 
 static void put_osd(struct ceph_osd *osd)
 {
-	dout("put_osd %p %d -> %d\n", osd, refcount_read(&osd->o_ref),
-	     refcount_read(&osd->o_ref) - 1);
+	unsigned int refcnt = refcount_read(&osd->o_ref);
+	dout("put_osd %p %d -> %d\n", osd, refcnt, refcnt - 1);
 	if (refcount_dec_and_test(&osd->o_ref)) {
 		osd_cleanup(osd);
 		kfree(osd);