diff --git a/drivers/s390/crypto/ap_queue.c b/drivers/s390/crypto/ap_queue.c index 232b786d81d1..bc03b2101e39 100644 --- a/drivers/s390/crypto/ap_queue.c +++ b/drivers/s390/crypto/ap_queue.c @@ -961,34 +961,37 @@ static ssize_t se_bind_store(struct device *dev, __ap_flush_queue(aq); aq->rapq_fbit = 1; _ap_queue_init_state(aq); - rc = count; - goto out; + spin_unlock_bh(&aq->lock); + return count; } + /* lock this ap to have fetch and update in an atomic way */ + spin_lock_bh(&aq->lock); + /* Bind. Check current SE bind state */ status = ap_test_queue(aq->qid, 1, &hwinfo); if (status.response_code) { AP_DBF_WARN("%s RC 0x%02x on tapq(0x%02x.%04x)\n", __func__, status.response_code, AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); - return -EIO; + rc = -EIO; + goto error; } /* Update BS state */ - spin_lock_bh(&aq->lock); aq->se_bstate = hwinfo.bs; if (hwinfo.bs != AP_BS_Q_AVAIL_FOR_BINDING) { AP_DBF_WARN("%s bind attempt with bs %d on queue 0x%02x.%04x\n", __func__, hwinfo.bs, AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); rc = -EINVAL; - goto out; + goto error; } /* Check SM state */ if (aq->sm_state < AP_SM_STATE_IDLE) { rc = -EBUSY; - goto out; + goto error; } /* invoke BAPQ */ @@ -998,7 +1001,7 @@ static ssize_t se_bind_store(struct device *dev, __func__, status.response_code, AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); rc = -EIO; - goto out; + goto error; } aq->assoc_idx = ASSOC_IDX_INVALID; @@ -1009,7 +1012,7 @@ static ssize_t se_bind_store(struct device *dev, __func__, status.response_code, AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); rc = -EIO; - goto out; + goto error; } aq->se_bstate = hwinfo.bs; if (!(hwinfo.bs == AP_BS_Q_USABLE || @@ -1018,16 +1021,19 @@ static ssize_t se_bind_store(struct device *dev, __func__, hwinfo.bs, AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); rc = -EIO; - goto out; + goto error; } /* SE bind was successful */ + spin_unlock_bh(&aq->lock); + AP_DBF_INFO("%s bapq(0x%02x.%04x) success\n", __func__, AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); ap_send_se_bind_uevent(&aq->ap_dev); - rc = count; -out: + return count; + +error: spin_unlock_bh(&aq->lock); return rc; } @@ -1093,15 +1099,18 @@ static ssize_t se_associate_store(struct device *dev, if (value >= ASSOC_IDX_INVALID) return -EINVAL; + /* lock this ap to have fetch and update in an atomic way */ + spin_lock_bh(&aq->lock); + /* check current SE bind state */ status = ap_test_queue(aq->qid, 1, &hwinfo); if (status.response_code) { AP_DBF_WARN("%s RC 0x%02x on tapq(0x%02x.%04x)\n", __func__, status.response_code, AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); - return -EIO; + rc = -EIO; + goto out; } - spin_lock_bh(&aq->lock); aq->se_bstate = hwinfo.bs; if (hwinfo.bs != AP_BS_Q_USABLE_NO_SECURE_KEY) { AP_DBF_WARN("%s association attempt with bs %d on queue 0x%02x.%04x\n", @@ -1125,17 +1134,16 @@ static ssize_t se_associate_store(struct device *dev, aq->sm_state = AP_SM_STATE_ASSOC_WAIT; aq->assoc_idx = value; ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); + rc = count; break; default: AP_DBF_WARN("%s RC 0x%02x on aapq(0x%02x.%04x)\n", __func__, status.response_code, AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); rc = -EIO; - goto out; + break; } - rc = count; - out: spin_unlock_bh(&aq->lock); return rc;