Skip to content

Commit

Permalink
opal: Fix get string for bigger length
Browse files Browse the repository at this point in the history
Skip token header length which varies for short,
medium and long atom.

Fix Issue spdk#898

Change-Id: I2351193e5a43608495f3d816ff4e5932399a6312
Signed-off-by: Chunyang Hui <[email protected]>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/464502
Reviewed-by: Changpeng Liu <[email protected]>
Reviewed-by: Ben Walker <[email protected]>
Tested-by: SPDK CI Jenkins <[email protected]>
  • Loading branch information
jessehui authored and jimharris committed Aug 8, 2019
1 parent 8cf1945 commit a4516ad
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/nvme/nvme_opal.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@ static size_t
opal_response_get_string(const struct spdk_opal_resp_parsed *resp, int n,
const char **store)
{
uint8_t header_len;
struct spdk_opal_resp_token token = resp->resp_tokens[n];

*store = NULL;
if (!resp) {
SPDK_ERRLOG("Response is NULL\n");
Expand All @@ -561,13 +564,28 @@ opal_response_get_string(const struct spdk_opal_resp_parsed *resp, int n,
return 0;
}

if (resp->resp_tokens[n].type != OPAL_DTA_TOKENID_BYTESTRING) {
if (token.type != OPAL_DTA_TOKENID_BYTESTRING) {
SPDK_ERRLOG("Token is not a byte string!\n");
return 0;
}

*store = resp->resp_tokens[n].pos + 1;
return resp->resp_tokens[n].len - 1;
switch (token.width) {
case OPAL_WIDTH_SHORT:
header_len = 1;
break;
case OPAL_WIDTH_MEDIUM:
header_len = 2;
break;
case OPAL_WIDTH_LONG:
header_len = 4;
break;
default:
SPDK_ERRLOG("Can't get string from this Token\n");
return 0;
}

*store = token.pos + header_len;
return token.len - header_len;
}

static int
Expand Down

0 comments on commit a4516ad

Please sign in to comment.