[openib-general] Re: RDMA Generic Connection Management

Roland Dreier rolandd at cisco.com
Tue Aug 30 20:33:55 PDT 2005


I just committed this SRP fix, which should make sure we don't use a
device after it's gone.  And it actually simplifies the code a teeny bit...

- R.


--- ib_srp.c	(revision 3262)
+++ ib_srp.c	(working copy)
@@ -1030,7 +1030,7 @@ static void srp_release_class_dev(struct
 	struct srp_host *host =
 		container_of(class_dev, struct srp_host, class_dev);
 
-	kfree(host);
+	complete(&host->released);
 }
 
 static struct class srp_class = {
@@ -1289,6 +1289,7 @@ static struct srp_host *srp_add_port(str
 
 	INIT_LIST_HEAD(&host->target_list);
 	init_MUTEX(&host->target_mutex);
+	init_completion(&host->released);
 	host->dev  = device;
 	host->port = port;
 
@@ -1317,12 +1318,6 @@ static struct srp_host *srp_add_port(str
 		goto err_class;
 	/* XXX ibdev / port files as well */
 
-	/*
-	 * Take another reference so we can unregister and then free
-	 * IB resources afterwards.
-	 */
-	class_device_get(&host->class_dev);
-
 	return host;
 
 err_class:
@@ -1392,6 +1387,11 @@ static void srp_remove_one(struct ib_dev
 	dev_list = ib_get_client_data(device, &srp_client);
 
 	list_for_each_entry_safe(host, tmp_host, dev_list, list) {
+		class_device_unregister(&host->class_dev);
+		wait_for_completion(&host->released);
+
+		printk(KERN_ERR "Hey, host (port %d) is released\n", host->port);
+
 		down(&host->target_mutex);
 
 		list_for_each_entry_safe(target, tmp_target,
@@ -1403,10 +1403,9 @@ static void srp_remove_one(struct ib_dev
 
 		up(&host->target_mutex);
 
-		class_device_unregister(&host->class_dev);
 		ib_dereg_mr(host->mr);
 		ib_dealloc_pd(host->pd);
-		class_device_put(&host->class_dev);
+		kfree(host);
 	}
 }
 
Index: ib_srp.h
===================================================================
--- ib_srp.h	(revision 3262)
+++ ib_srp.h	(working copy)
@@ -74,6 +74,7 @@ struct srp_host {
 	struct class_device	class_dev;
 	struct list_head	target_list;
 	struct semaphore        target_mutex;
+	struct completion	released;
 	struct list_head	list;
 };
 



More information about the general mailing list