All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@sandisk.com>
To: Doug Ledford <dledford@redhat.com>
Cc: "Nicholas A. Bellinger" <nab@linux-iscsi.org>,
	Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	target-devel <target-devel@vger.kernel.org>
Subject: [PATCH 3/4] IB/srpt: Introduce two helper functions
Date: Wed, 6 Apr 2016 11:57:20 -0700	[thread overview]
Message-ID: <57055C10.3060108@sandisk.com> (raw)
In-Reply-To: <57055BC6.7070402@sandisk.com>

Move the functionality for initializing and cleaning up I/O
contexts into two new functions. This patch does not change any
functionality.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Nicholas Bellinger <nab@linux-iscsi.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagig@mellanox.com>
---
 drivers/infiniband/ulp/srpt/ib_srpt.c | 64 +++++++++++++++++++++++++++--------
 1 file changed, 49 insertions(+), 15 deletions(-)

diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 07dfc50..cce6c46 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -581,6 +581,31 @@ static void srpt_unregister_mad_agent(struct srpt_device *sdev)
 	}
 }
 
+static int srpt_init_ioctx(struct srpt_device *sdev,
+					  struct srpt_ioctx *ioctx,
+					  int dma_size,
+					  enum dma_data_direction dir)
+{
+	int ret = -ENOMEM;
+
+	ioctx->buf = kmalloc(dma_size, GFP_KERNEL);
+	if (!ioctx->buf)
+		goto out;
+
+	ioctx->dma = ib_dma_map_single(sdev->device, ioctx->buf, dma_size, dir);
+	if (ib_dma_mapping_error(sdev->device, ioctx->dma))
+		goto free_buf;
+
+	ret = 0;
+
+out:
+	return ret;
+
+free_buf:
+	kfree(ioctx->buf);
+	goto out;
+}
+
 /**
  * srpt_alloc_ioctx() - Allocate an SRPT I/O context structure.
  */
@@ -592,24 +617,34 @@ static struct srpt_ioctx *srpt_alloc_ioctx(struct srpt_device *sdev,
 
 	ioctx = kmalloc(ioctx_size, GFP_KERNEL);
 	if (!ioctx)
-		goto err;
-
-	ioctx->buf = kmalloc(dma_size, GFP_KERNEL);
-	if (!ioctx->buf)
-		goto err_free_ioctx;
+		goto out;
 
-	ioctx->dma = ib_dma_map_single(sdev->device, ioctx->buf, dma_size, dir);
-	if (ib_dma_mapping_error(sdev->device, ioctx->dma))
-		goto err_free_buf;
+	if (srpt_init_ioctx(sdev, ioctx, dma_size, dir) < 0)
+		goto free;
 
+out:
 	return ioctx;
 
-err_free_buf:
-	kfree(ioctx->buf);
-err_free_ioctx:
+free:
 	kfree(ioctx);
-err:
-	return NULL;
+	ioctx = NULL;
+	goto out;
+}
+
+/*
+ * Note: it is safe to call this function for a zero-initialized buffer
+ * even if srpt_init_ioctx() has not been called.
+ */
+static void srpt_cleanup_ioctx(struct srpt_device *sdev,
+			       struct srpt_ioctx *ioctx,
+			       int dma_size,
+			       enum dma_data_direction dir)
+{
+	if (!ioctx->buf)
+		return;
+
+	ib_dma_unmap_single(sdev->device, ioctx->dma, dma_size, dir);
+	kfree(ioctx->buf);
 }
 
 /**
@@ -621,8 +656,7 @@ static void srpt_free_ioctx(struct srpt_device *sdev, struct srpt_ioctx *ioctx,
 	if (!ioctx)
 		return;
 
-	ib_dma_unmap_single(sdev->device, ioctx->dma, dma_size, dir);
-	kfree(ioctx->buf);
+	srpt_cleanup_ioctx(sdev, ioctx, dma_size, dir);
 	kfree(ioctx);
 }
 
-- 
2.7.4

  parent reply	other threads:[~2016-04-06 18:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-06 18:56 [PATCH 0/4] IB/srpt and the percpu_ida conversion Bart Van Assche
2016-04-06 18:56 ` [PATCH 1/4] IB/srpt: Revert "Convert to percpu_ida tag allocation" Bart Van Assche
2016-04-06 18:57 ` [PATCH 2/4] IB/srpt: Report login failures only once Bart Van Assche
     [not found]   ` <57055BFF.9060607-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-04-07 13:40     ` Christoph Hellwig
2016-04-06 18:57 ` Bart Van Assche [this message]
2016-04-07 13:40   ` [PATCH 3/4] IB/srpt: Introduce two helper functions Christoph Hellwig
2016-04-07 22:29 ` [PATCH 0/4] IB/srpt and the percpu_ida conversion Nicholas A. Bellinger
     [not found]   ` <1460068181.18732.23.camel-XoQW25Eq2zviZyQQd+hFbcojREIfoBdhmpATvIKMPHk@public.gmane.org>
2016-04-07 22:38     ` Bart Van Assche
2016-04-07 23:01   ` Christoph Hellwig
     [not found]     ` <20160407230110.GA9842-jcswGhMUV9g@public.gmane.org>
2016-04-07 23:24       ` Nicholas A. Bellinger
2016-04-07 23:34         ` Bart Van Assche
2016-04-07 23:47           ` Nicholas A. Bellinger
2016-04-07 23:49             ` Bart Van Assche
2016-04-08  8:16           ` Jack Wang
     [not found]         ` <1460071464.18732.57.camel-XoQW25Eq2zviZyQQd+hFbcojREIfoBdhmpATvIKMPHk@public.gmane.org>
2016-04-07 23:47           ` Bart Van Assche
     [not found] ` <57055BC6.7070402-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-04-06 18:57   ` [PATCH 4/4] IB/srpt: Convert to percpu_ida tag allocation Bart Van Assche
2016-04-07 13:43     ` Christoph Hellwig
2016-04-07 23:03     ` Christoph Hellwig
2016-04-07 23:31       ` Nicholas A. Bellinger
2016-04-07 22:55   ` [PATCH] IB/srpt: Revert "Convert to percpu_ida tag allocation" Bart Van Assche
2016-04-07 23:37     ` Nicholas A. Bellinger
     [not found]       ` <1460072224.18732.67.camel-XoQW25Eq2zviZyQQd+hFbcojREIfoBdhmpATvIKMPHk@public.gmane.org>
2016-04-07 23:44         ` Bart Van Assche
     [not found]           ` <5706F0E8.5020705-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-04-07 23:52             ` Nicholas A. Bellinger
     [not found]               ` <1460073123.18732.80.camel-XoQW25Eq2zviZyQQd+hFbcojREIfoBdhmpATvIKMPHk@public.gmane.org>
2016-04-07 23:54                 ` Christoph Hellwig
2016-04-08  0:00                   ` Nicholas A. Bellinger
2016-04-08  0:00                 ` Doug Ledford
2016-04-07 23:49       ` Linus Torvalds
     [not found]         ` <CA+55aFwOnCeKzg4SuceZm98DgN-tV7aCdtrenAS93LP7GqrZtw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-07 23:56           ` Nicholas A. Bellinger
     [not found]             ` <1460073392.18732.83.camel-XoQW25Eq2zviZyQQd+hFbcojREIfoBdhmpATvIKMPHk@public.gmane.org>
2016-04-08  0:13               ` Linus Torvalds

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=57055C10.3060108@sandisk.com \
    --to=bart.vanassche@sandisk.com \
    --cc=dledford@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-rdma@vger.kernel.org \
    --cc=nab@linux-iscsi.org \
    --cc=sagi@grimberg.me \
    --cc=target-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.