Commit b68f09ec authored by David Kozub's avatar David Kozub Committed by Jens Axboe

block: sed-opal: reuse response_get_token to decrease code duplication

response_get_token had already been in place, its functionality had
been duplicated within response_get_{u64,bytestring} with the same error
handling. Unify the handling by reusing response_get_token within the
other functions.
Co-authored-by: default avatarJonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Signed-off-by: default avatarDavid Kozub <zub@linux.fjfi.cvut.cz>
Signed-off-by: default avatarJonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Reviewed-by: default avatarScott Bauer <sbauer@plzdonthack.me>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJon Derrick <jonathan.derrick@intel.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 7d9b62ae
...@@ -883,27 +883,19 @@ static size_t response_get_string(const struct parsed_resp *resp, int n, ...@@ -883,27 +883,19 @@ static size_t response_get_string(const struct parsed_resp *resp, int n,
const char **store) const char **store)
{ {
u8 skip; u8 skip;
const struct opal_resp_tok *token; const struct opal_resp_tok *tok;
*store = NULL; *store = NULL;
if (!resp) { tok = response_get_token(resp, n);
pr_debug("Response is NULL\n"); if (IS_ERR(tok))
return 0;
}
if (n >= resp->num) {
pr_debug("Response has %d tokens. Can't access %d\n",
resp->num, n);
return 0; return 0;
}
token = &resp->toks[n]; if (tok->type != OPAL_DTA_TOKENID_BYTESTRING) {
if (token->type != OPAL_DTA_TOKENID_BYTESTRING) {
pr_debug("Token is not a byte string!\n"); pr_debug("Token is not a byte string!\n");
return 0; return 0;
} }
switch (token->width) { switch (tok->width) {
case OPAL_WIDTH_TINY: case OPAL_WIDTH_TINY:
case OPAL_WIDTH_SHORT: case OPAL_WIDTH_SHORT:
skip = 1; skip = 1;
...@@ -919,37 +911,29 @@ static size_t response_get_string(const struct parsed_resp *resp, int n, ...@@ -919,37 +911,29 @@ static size_t response_get_string(const struct parsed_resp *resp, int n,
return 0; return 0;
} }
*store = token->pos + skip; *store = tok->pos + skip;
return token->len - skip; return tok->len - skip;
} }
static u64 response_get_u64(const struct parsed_resp *resp, int n) static u64 response_get_u64(const struct parsed_resp *resp, int n)
{ {
if (!resp) { const struct opal_resp_tok *tok;
pr_debug("Response is NULL\n");
return 0;
}
if (n >= resp->num) { tok = response_get_token(resp, n);
pr_debug("Response has %d tokens. Can't access %d\n", if (IS_ERR(tok))
resp->num, n);
return 0; return 0;
}
if (resp->toks[n].type != OPAL_DTA_TOKENID_UINT) { if (tok->type != OPAL_DTA_TOKENID_UINT) {
pr_debug("Token is not unsigned it: %d\n", pr_debug("Token is not unsigned int: %d\n", tok->type);
resp->toks[n].type);
return 0; return 0;
} }
if (!(resp->toks[n].width == OPAL_WIDTH_TINY || if (tok->width != OPAL_WIDTH_TINY && tok->width != OPAL_WIDTH_SHORT) {
resp->toks[n].width == OPAL_WIDTH_SHORT)) { pr_debug("Atom is not short or tiny: %d\n", tok->width);
pr_debug("Atom is not short or tiny: %d\n",
resp->toks[n].width);
return 0; return 0;
} }
return resp->toks[n].stored.u; return tok->stored.u;
} }
static bool response_token_matches(const struct opal_resp_tok *token, u8 match) static bool response_token_matches(const struct opal_resp_tok *token, u8 match)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment