Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1160964

[PATCH 1/6] Add refcount to sas_device struct

From Calvin Owens <calvinowens@fb.com>
Newsgroups linux.kernel
Subject [PATCH 1/6] Add refcount to sas_device struct
Date 2015-06-09 06:00 +0200
Message-ID <pziRJ-34C-29@gated-at.bofh.it> (permalink)
References <pqeNj-4f4-3@gated-at.bofh.it> <pziRH-34C-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


These objects can be referenced concurrently throughout the driver, we
need a way to make sure threads can't delete them out from under each
other.

Signed-off-by: Calvin Owens <calvinowens@fb.com>
---
 drivers/scsi/mpt2sas/mpt2sas_base.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.h b/drivers/scsi/mpt2sas/mpt2sas_base.h
index caff8d1..2e7dc33 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.h
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.h
@@ -376,8 +376,24 @@ struct _sas_device {
 	u8	phy;
 	u8	responding;
 	u8	pfa_led_on;
+	struct kref refcount;
 };
 
+static inline void sas_device_get(struct _sas_device *s)
+{
+	kref_get(&s->refcount);
+}
+
+static inline void sas_device_free(struct kref *r)
+{
+	kfree(container_of(r, struct _sas_device, refcount));
+}
+
+static inline void sas_device_put(struct _sas_device *s)
+{
+	kref_put(&s->refcount, sas_device_free);
+}
+
 /**
  * struct _raid_device - raid volume link list
  * @list: sas device list
-- 
1.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[RESEND][PATCH 0/6] Fixes for memory corruption in mpt2sas Calvin Owens <calvinowens@fb.com> - 2015-06-09 06:00 +0200
  [PATCH 6/6] Fix unsafe fw_event_list usage Calvin Owens <calvinowens@fb.com> - 2015-06-09 06:00 +0200
  [PATCH 4/6] Add refcount to fw_event_work struct Calvin Owens <calvinowens@fb.com> - 2015-06-09 06:00 +0200
  [PATCH 1/6] Add refcount to sas_device struct Calvin Owens <calvinowens@fb.com> - 2015-06-09 06:00 +0200

csiph-web