--- initial
+++ final
@@ -1,177 +1,177 @@
 int iwch_modify_qp(struct iwch_dev *rhp, struct iwch_qp *qhp, enum iwch_qp_attr_mask mask, struct iwch_qp_attributes *attrs, int internal) {
   int ret = 0;
   struct iwch_qp_attributes newattr = qhp->attr;
   unsigned long flag;
   int disconnect = 0;
   int terminate = 0;
   int abort = 0;
   int free = 0;
   struct iwch_ep *ep = NULL;
   PDBG("%s qhp %p qpid 0x%x ep %p state %d -> %d\n", __func__, qhp, qhp->wq.qpid, qhp->ep, qhp->attr.state, (mask & IWCH_QP_ATTR_NEXT_STATE) ? attrs->next_state : -1);
   spin_lock_irqsave(&qhp->lock, flag);
   /* Process attr changes if in IDLE */
   if (mask & IWCH_QP_ATTR_VALID_MODIFY) {
     if (qhp->attr.state != IWCH_QP_STATE_IDLE) {
       ret = -EIO;
       goto out;
     }
     if (mask & IWCH_QP_ATTR_ENABLE_RDMA_READ) newattr.enable_rdma_read = attrs->enable_rdma_read;
     if (mask & IWCH_QP_ATTR_ENABLE_RDMA_WRITE) newattr.enable_rdma_write = attrs->enable_rdma_write;
     if (mask & IWCH_QP_ATTR_ENABLE_RDMA_BIND) newattr.enable_bind = attrs->enable_bind;
     if (mask & IWCH_QP_ATTR_MAX_ORD) {
       if (attrs->max_ord > rhp->attr.max_rdma_read_qp_depth) {
         ret = -EINVAL;
         goto out;
       }
       newattr.max_ord = attrs->max_ord;
     }
     if (mask & IWCH_QP_ATTR_MAX_IRD) {
       if (attrs->max_ird > rhp->attr.max_rdma_reads_per_qp) {
         ret = -EINVAL;
         goto out;
       }
       newattr.max_ird = attrs->max_ird;
     }
     qhp->attr = newattr;
   }
   if (!(mask & IWCH_QP_ATTR_NEXT_STATE)) goto out;
   if (qhp->attr.state == attrs->next_state) goto out;
   switch (qhp->attr.state) {
   case IWCH_QP_STATE_IDLE:
     switch (attrs->next_state) {
     case IWCH_QP_STATE_RTS:
       if (!(mask & IWCH_QP_ATTR_LLP_STREAM_HANDLE)) {
         ret = -EINVAL;
         goto out;
       }
       if (!(mask & IWCH_QP_ATTR_MPA_ATTR)) {
         ret = -EINVAL;
         goto out;
       }
       qhp->attr.mpa_attr = attrs->mpa_attr;
       qhp->attr.llp_stream_handle = attrs->llp_stream_handle;
       qhp->ep = qhp->attr.llp_stream_handle;
       qhp->attr.state = IWCH_QP_STATE_RTS;
       /*
        * Ref the endpoint here and deref when we
        * disassociate the endpoint from the QP.  This
        * happens in CLOSING->IDLE transition or *->ERROR
        * transition.
        */
       get_ep(&qhp->ep->com);
       spin_unlock_irqrestore(&qhp->lock, flag);
       ret = rdma_init(rhp, qhp, mask, attrs);
       spin_lock_irqsave(&qhp->lock, flag);
       if (ret) goto err;
       break;
     case IWCH_QP_STATE_ERROR:
       qhp->attr.state = IWCH_QP_STATE_ERROR;
       flush_qp(qhp);
       break;
     default: ret = -EINVAL; goto out;
     }
     break;
   case IWCH_QP_STATE_RTS:
     switch (attrs->next_state) {
     case IWCH_QP_STATE_CLOSING:
-      BUG_ON(atomic_read(&qhp->ep->com.kref.refcount) < 2);
+      BUG_ON(kref_read(&qhp->ep->com.kref) < 2);
       qhp->attr.state = IWCH_QP_STATE_CLOSING;
       if (!internal) {
         abort = 0;
         disconnect = 1;
         ep = qhp->ep;
         get_ep(&ep->com);
       }
       break;
     case IWCH_QP_STATE_TERMINATE:
       qhp->attr.state = IWCH_QP_STATE_TERMINATE;
       if (qhp->ibqp.uobject) cxio_set_wq_in_error(&qhp->wq);
       if (!internal) terminate = 1;
       break;
     case IWCH_QP_STATE_ERROR:
       qhp->attr.state = IWCH_QP_STATE_ERROR;
       if (!internal) {
         abort = 1;
         disconnect = 1;
         ep = qhp->ep;
         get_ep(&ep->com);
       }
       goto err;
       break;
     default: ret = -EINVAL; goto out;
     }
     break;
   case IWCH_QP_STATE_CLOSING:
     if (!internal) {
       ret = -EINVAL;
       goto out;
     }
     switch (attrs->next_state) {
     case IWCH_QP_STATE_IDLE:
       flush_qp(qhp);
       qhp->attr.state = IWCH_QP_STATE_IDLE;
       qhp->attr.llp_stream_handle = NULL;
       put_ep(&qhp->ep->com);
       qhp->ep = NULL;
       wake_up(&qhp->wait);
       break;
     case IWCH_QP_STATE_ERROR: goto err;
     default: ret = -EINVAL; goto err;
     }
     break;
   case IWCH_QP_STATE_ERROR:
     if (attrs->next_state != IWCH_QP_STATE_IDLE) {
       ret = -EINVAL;
       goto out;
     }
     if (!Q_EMPTY(qhp->wq.sq_rptr, qhp->wq.sq_wptr) || !Q_EMPTY(qhp->wq.rq_rptr, qhp->wq.rq_wptr)) {
       ret = -EINVAL;
       goto out;
     }
     qhp->attr.state = IWCH_QP_STATE_IDLE;
     break;
   case IWCH_QP_STATE_TERMINATE:
     if (!internal) {
       ret = -EINVAL;
       goto out;
     }
     goto err;
     break;
   default:
     printk(KERN_ERR "%s in a bad state %d\n", __func__, qhp->attr.state);
     ret = -EINVAL;
     goto err;
     break;
   }
   goto out;
 err:
   PDBG("%s disassociating ep %p qpid 0x%x\n", __func__, qhp->ep, qhp->wq.qpid);
   /* disassociate the LLP connection */
   qhp->attr.llp_stream_handle = NULL;
   ep = qhp->ep;
   qhp->ep = NULL;
   qhp->attr.state = IWCH_QP_STATE_ERROR;
   free = 1;
   wake_up(&qhp->wait);
   BUG_ON(!ep);
   flush_qp(qhp);
 out:
   spin_unlock_irqrestore(&qhp->lock, flag);
   if (terminate) iwch_post_terminate(qhp, NULL);
   /*
    * If disconnect is 1, then we need to initiate a disconnect
    * on the EP.  This can be a normal close (RTS->CLOSING) or
    * an abnormal close (RTS/CLOSING->ERROR).
    */
   if (disconnect) {
     iwch_ep_disconnect(ep, abort, GFP_KERNEL);
     put_ep(&ep->com);
   }
   /*
    * If free is 1, then we've disassociated the EP from the QP
    * and we need to dereference the EP.
    */
   if (free) put_ep(&ep->com);
   PDBG("%s exit state %d\n", __func__, qhp->attr.state);
   return ret;
 }<sep>@@
expression e; 
@@
-               atomic_read(&e.refcount)
+               kref_read(&e)