[PATCH 15/21] tcm_fc: Fix ft_sess_get()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use kref_get_unless_zero() instead of kref_get(). This patch
avoids that the following kernel warning gets reported:

WARNING: CPU: 1 PID: 1423 at include/linux/kref.h:47 ft_recv+0x2f0/0x340 [tcm_fc]()

Signed-off-by: Bart Van Assche <bart.vanassche@xxxxxxxxxxx>
Cc: Vasu Dev <vasu.dev@xxxxxxxxx>
Cc: stable <stable@xxxxxxxxxxxxxxx>
---
 drivers/target/tcm_fc/tfc_sess.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/target/tcm_fc/tfc_sess.c b/drivers/target/tcm_fc/tfc_sess.c
index 00a22d6..97220e5 100644
--- a/drivers/target/tcm_fc/tfc_sess.c
+++ b/drivers/target/tcm_fc/tfc_sess.c
@@ -171,7 +171,7 @@ static struct ft_sess *ft_sess_get(struct fc_lport *lport, u32 port_id)
 {
 	struct ft_tport *tport;
 	struct hlist_head *head;
-	struct ft_sess *sess;
+	struct ft_sess *sess, *ret = NULL;
 
 	rcu_read_lock();
 	tport = rcu_dereference(lport->prov[FC_TYPE_FCP]);
@@ -181,16 +181,21 @@ static struct ft_sess *ft_sess_get(struct fc_lport *lport, u32 port_id)
 	head = &tport->hash[ft_sess_hash(port_id)];
 	hlist_for_each_entry_rcu(sess, head, hash) {
 		if (sess->port_id == port_id) {
-			kref_get(&sess->kref);
-			rcu_read_unlock();
-			pr_debug("port_id %x found %p\n", port_id, sess);
-			return sess;
+			if (kref_get_unless_zero(&sess->kref))
+				ret = sess;
+			break;
 		}
 	}
+
 out:
 	rcu_read_unlock();
-	pr_debug("port_id %x not found\n", port_id);
-	return NULL;
+
+	if (ret)
+		pr_debug("port_id %x found %p\n", port_id, ret);
+	else
+		pr_debug("port_id %x not found\n", port_id);
+
+	return ret;
 }
 
 /*
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux