Skip to content

Commit b68f09e

Browse files
David Kozubnonapode
authored andcommitted
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: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jon Derrick <jonathan.derrick@intel.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 7d9b62a commit b68f09e

1 file changed

Lines changed: 15 additions & 31 deletions

File tree

‎block/sed-opal.c‎

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -883,27 +883,19 @@ static size_t response_get_string(const struct parsed_resp *resp, int n,
883883
const char **store)
884884
{
885885
u8 skip;
886-
const struct opal_resp_tok *token;
886+
const struct opal_resp_tok *tok;
887887

888888
*store = NULL;
889-
if (!resp) {
890-
pr_debug("Response is NULL\n");
891-
return 0;
892-
}
893-
894-
if (n >= resp->num) {
895-
pr_debug("Response has %d tokens. Can't access %d\n",
896-
resp->num, n);
889+
tok = response_get_token(resp, n);
890+
if (IS_ERR(tok))
897891
return 0;
898-
}
899892

900-
token = &resp->toks[n];
901-
if (token->type != OPAL_DTA_TOKENID_BYTESTRING) {
893+
if (tok->type != OPAL_DTA_TOKENID_BYTESTRING) {
902894
pr_debug("Token is not a byte string!\n");
903895
return 0;
904896
}
905897

906-
switch (token->width) {
898+
switch (tok->width) {
907899
case OPAL_WIDTH_TINY:
908900
case OPAL_WIDTH_SHORT:
909901
skip = 1;
@@ -919,37 +911,29 @@ static size_t response_get_string(const struct parsed_resp *resp, int n,
919911
return 0;
920912
}
921913

922-
*store = token->pos + skip;
923-
return token->len - skip;
914+
*store = tok->pos + skip;
915+
return tok->len - skip;
924916
}
925917

926918
static u64 response_get_u64(const struct parsed_resp *resp, int n)
927919
{
928-
if (!resp) {
929-
pr_debug("Response is NULL\n");
930-
return 0;
931-
}
920+
const struct opal_resp_tok *tok;
932921

933-
if (n >= resp->num) {
934-
pr_debug("Response has %d tokens. Can't access %d\n",
935-
resp->num, n);
922+
tok = response_get_token(resp, n);
923+
if (IS_ERR(tok))
936924
return 0;
937-
}
938925

939-
if (resp->toks[n].type != OPAL_DTA_TOKENID_UINT) {
940-
pr_debug("Token is not unsigned it: %d\n",
941-
resp->toks[n].type);
926+
if (tok->type != OPAL_DTA_TOKENID_UINT) {
927+
pr_debug("Token is not unsigned int: %d\n", tok->type);
942928
return 0;
943929
}
944930

945-
if (!(resp->toks[n].width == OPAL_WIDTH_TINY ||
946-
resp->toks[n].width == OPAL_WIDTH_SHORT)) {
947-
pr_debug("Atom is not short or tiny: %d\n",
948-
resp->toks[n].width);
931+
if (tok->width != OPAL_WIDTH_TINY && tok->width != OPAL_WIDTH_SHORT) {
932+
pr_debug("Atom is not short or tiny: %d\n", tok->width);
949933
return 0;
950934
}
951935

952-
return resp->toks[n].stored.u;
936+
return tok->stored.u;
953937
}
954938

955939
static bool response_token_matches(const struct opal_resp_tok *token, u8 match)

0 commit comments

Comments
 (0)