Set handle_caw_read_cbk in caw_init_readcmd
This moves caw_init_readcmd to before handle_caw_read_cbk and then
has caw_init_readcmd set the callback for the caller so the setup is
done in one place.
@@ -1610,39 +1610,6 @@ struct caw_state {
struct tcmulib_cmd *origcmd;
};
-static struct tcmulib_cmd *
-caw_init_readcmd(struct tcmulib_cmd *origcmd, size_t length)
-{
- struct tcmulib_cmd *readcmd;
- struct caw_state *state;
-
- state = calloc(1, sizeof(*state));
- if (!state)
- goto out;
- readcmd = calloc(1, sizeof(*readcmd));
- if (!readcmd)
- goto free_state;
- readcmd->cdb = origcmd->cdb;
-
- if (alloc_iovec(readcmd, length))
- goto free_cmd;
-
- /* multi-op state maintainance */
- state->read_buf = readcmd->iovec->iov_base;
- state->requested = length;
- state->origcmd = origcmd;
-
- readcmd->cmdstate = state;
- return readcmd;
-
-free_cmd:
- free(readcmd);
-free_state:
- free(state);
-out:
- return NULL;
-}
-
static void caw_free_readcmd(struct tcmulib_cmd *readcmd)
{
struct caw_state *state = readcmd->cmdstate;
@@ -1702,6 +1669,40 @@ finish_err:
caw_free_readcmd(readcmd);
}
+static struct tcmulib_cmd *
+caw_init_readcmd(struct tcmulib_cmd *origcmd, size_t length)
+{
+ struct tcmulib_cmd *readcmd;
+ struct caw_state *state;
+
+ state = calloc(1, sizeof(*state));
+ if (!state)
+ goto out;
+ readcmd = calloc(1, sizeof(*readcmd));
+ if (!readcmd)
+ goto free_state;
+ readcmd->cdb = origcmd->cdb;
+ readcmd->done = handle_caw_read_cbk;
+
+ if (alloc_iovec(readcmd, length))
+ goto free_cmd;
+
+ /* multi-op state maintainance */
+ state->read_buf = readcmd->iovec->iov_base;
+ state->requested = length;
+ state->origcmd = origcmd;
+
+ readcmd->cmdstate = state;
+ return readcmd;
+
+free_cmd:
+ free(readcmd);
+free_state:
+ free(state);
+out:
+ return NULL;
+}
+
static int handle_caw_check(struct tcmu_device *dev, struct tcmulib_cmd *cmd)
{
int ret;
@@ -1762,8 +1763,6 @@ static int handle_caw(struct tcmu_device *dev, struct tcmulib_cmd *cmd)
goto out;
}
- readcmd->done = handle_caw_read_cbk;
-
pthread_mutex_lock(&rdev->caw_lock);
ret = async_handle_cmd(dev, readcmd, read_work_fn);
