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


Groups > linux.kernel > #1160963

[PATCH 4/6] Add refcount to fw_event_work struct

From Calvin Owens <calvinowens@fb.com>
Newsgroups linux.kernel
Subject [PATCH 4/6] Add refcount to fw_event_work struct
Date 2015-06-09 06:00 +0200
Message-ID <pziRI-34C-21@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


The fw_event_work struct is concurrently referenced at shutdown, so
add a refcount to protect it.

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

diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
index 9645055..611b34d 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
@@ -176,9 +176,37 @@ struct fw_event_work {
 	u8			VP_ID;
 	u8			ignore;
 	u16			event;
+	struct kref		refcount;
 	char			event_data[0] __aligned(4);
 };
 
+static void fw_event_work_free(struct kref *r)
+{
+	kfree(container_of(r, struct fw_event_work, refcount));
+}
+
+static void fw_event_work_get(struct fw_event_work *fw_work)
+{
+	kref_get(&fw_work->refcount);
+}
+
+static void fw_event_work_put(struct fw_event_work *fw_work)
+{
+	kref_put(&fw_work->refcount, fw_event_work_free);
+}
+
+static struct fw_event_work *alloc_fw_event_work(int len)
+{
+	struct fw_event_work *fw_event;
+
+	fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
+	if (!fw_event)
+		return NULL;
+
+	kref_init(&fw_event->refcount);
+	return fw_event;
+}
+
 /* raid transport support */
 static struct raid_template *mpt2sas_raid_template;
 
-- 
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 | Next 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