mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: dongsu.park@profitbricks.com
To: bvanassche@acm.org
Cc: dillowda@ornl.gov, roland@kernel.org, sean.hefty@intel.com,
	hal.rosenstock@gmail.com, JBottomley@parallels.com,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-scsi@vger.kernel.org,
	Dongsu Park <dongsu.park@profitbricks.com>
Subject: [PATCH 1/5] ib_srp: free memory correctly in srp_free_iu()
Date: Fri, 31 Aug 2012 22:00:37 +0200	[thread overview]
Message-ID: <1346443241-24844-2-git-send-email-dongsu.park@profitbricks.com> (raw)
In-Reply-To: <1346443241-24844-1-git-send-email-dongsu.park@profitbricks.com>

From: Dongsu Park <dongsu.park@profitbricks.com>

As a potential fix for a race condition in srp_free_iu(),
hold a mutex in srp_free_target_ib() before calling srp_free_iu().

In addition, also clear rx/tx ring after freeing memory.
Both rx_ring[] and tx_ring[] should be reinitialized to NULL,
to prevent other tasks from accessing the freed memory.

Signed-off-by: Dongsu Park <dongsu.park@profitbricks.com>
---
 drivers/infiniband/ulp/srp/ib_srp.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 7ae5a00..a0d0ca2 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -291,10 +291,16 @@ static void srp_free_target_ib(struct srp_target_port *target)
 	ib_destroy_cq(target->send_cq);
 	ib_destroy_cq(target->recv_cq);
 
-	for (i = 0; i < SRP_RQ_SIZE; ++i)
+	mutex_lock(&target->mutex);
+	for (i = 0; i < SRP_RQ_SIZE; ++i) {
 		srp_free_iu(target->srp_host, target->rx_ring[i]);
-	for (i = 0; i < SRP_SQ_SIZE; ++i)
+		target->rx_ring[i] = NULL;
+	}
+	for (i = 0; i < SRP_SQ_SIZE; ++i) {
 		srp_free_iu(target->srp_host, target->tx_ring[i]);
+		target->tx_ring[i] = NULL;
+	}
+	mutex_unlock(&target->mutex);
 }
 
 static void srp_path_rec_completion(int status,
-- 
1.7.11.1


  reply	other threads:[~2012-08-31 20:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-31 20:00 [PATCH 0/5] Fix bugs in ib_srp patches for H.A. purposes dongsu.park
2012-08-31 20:00 ` dongsu.park [this message]
2012-08-31 20:00 ` [PATCH 2/5] ib_srp: removed superfluous warning in send timeout case dongsu.park
2012-08-31 20:00 ` [PATCH 3/5] ib_srp: hold a mutex when adding a new target port dongsu.park
2012-08-31 20:00 ` [PATCH 4/5] ib_srp: check if rport->lld_data is NULL before removing rport dongsu.park
2012-08-31 20:00 ` [PATCH 5/5] ib_srp: fix an error accessing invalid memory in rport_dev_loss_timedout dongsu.park
2012-09-01  8:09 ` [PATCH 0/5] Fix bugs in ib_srp patches for H.A. purposes Bart Van Assche

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=1346443241-24844-2-git-send-email-dongsu.park@profitbricks.com \
    --to=dongsu.park@profitbricks.com \
    --cc=JBottomley@parallels.com \
    --cc=bvanassche@acm.org \
    --cc=dillowda@ornl.gov \
    --cc=hal.rosenstock@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=roland@kernel.org \
    --cc=sean.hefty@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®