RDMA/iwcm: Don't access a cm_id after dropping reference
authorSteve Wise <swise@opengridcomputing.com>
Tue, 4 Mar 2008 22:44:52 +0000 (16:44 -0600)
committerRoland Dreier <rolandd@cisco.com>
Tue, 11 Mar 2008 04:22:22 +0000 (21:22 -0700)
cm_work_handler() can access cm_id_priv after it drops its reference
by calling iwch_deref_id(), which might cause it to be freed.  The fix
is to look at whether IWCM_F_CALLBACK_DESTROY is set _before_ dropping
the reference.  Then if it was set, free the cm_id on this thread.

Signed-off-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
drivers/infiniband/core/iwcm.c

index 223b1aa7d92b40f17b2367cc0166f2afc994d8e8..81c9195b512a1e5d63ae610bb3961e14a097f49e 100644 (file)
@@ -839,6 +839,7 @@ static void cm_work_handler(struct work_struct *_work)
        unsigned long flags;
        int empty;
        int ret = 0;
+       int destroy_id;
 
        spin_lock_irqsave(&cm_id_priv->lock, flags);
        empty = list_empty(&cm_id_priv->work_list);
@@ -857,9 +858,9 @@ static void cm_work_handler(struct work_struct *_work)
                        destroy_cm_id(&cm_id_priv->id);
                }
                BUG_ON(atomic_read(&cm_id_priv->refcount)==0);
+               destroy_id = test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags);
                if (iwcm_deref_id(cm_id_priv)) {
-                       if (test_bit(IWCM_F_CALLBACK_DESTROY,
-                                    &cm_id_priv->flags)) {
+                       if (destroy_id) {
                                BUG_ON(!list_empty(&cm_id_priv->work_list));
                                free_cm_id(cm_id_priv);
                        }