@@ -429,23 +429,16 @@ static int64_t opal_flash_op(enum flash_op op, uint64_t id, uint64_t offset,
struct flash *flash = NULL;
int rc;
- if (!try_lock(&flash_lock))
- return OPAL_BUSY;
-
list_for_each(&flashes, flash, list)
if (flash->id == id)
break;
- if (flash->id != id) {
+ if (flash->id != id)
/* Couldn't find the flash */
- rc = OPAL_PARAMETER;
- goto err;
- }
+ return OPAL_PARAMETER;
- if (flash->busy) {
- rc = OPAL_BUSY;
- goto err;
- }
+ if (!flash_reserve(flash))
+ return OPAL_BUSY;
if (size > flash->size || offset >= flash->size
|| offset + size > flash->size) {
@@ -481,13 +474,13 @@ static int64_t opal_flash_op(enum flash_op op, uint64_t id, uint64_t offset,
goto err;
}
- unlock(&flash_lock);
+ flash_release(flash);
opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, token, rc);
return OPAL_ASYNC_COMPLETION;
err:
- unlock(&flash_lock);
+ flash_release(flash);
return rc;
}