opal: Fix get string for bigger length
Skip token header length which varies for short,
medium and long atom.
Fix Issue #898
Signed-off-by: Chunyang Hui <chunyang.hui@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/464502 (master)
(cherry picked from commit a4516ad2ed
)
Change-Id: I2351193e5a43608495f3d816ff4e5932399a6312
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/467129
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Chunyang Hui <chunyang.hui@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
bbac3e8541
commit
23cd855116
@ -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");
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user