Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1149516imj; Thu, 14 Feb 2019 02:00:46 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ0Np1yl8EJKzT3Ckp/iNJ/rRMHgGcBQgZiEHoCtxmCQoWB6Z6pwvPndFCf/eN4luh1UGoA X-Received: by 2002:a63:c34e:: with SMTP id e14mr2730463pgd.231.1550138446743; Thu, 14 Feb 2019 02:00:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550138446; cv=none; d=google.com; s=arc-20160816; b=U/PB57mvmFyfx7NBYI8SXCgGBDw/nXiX/cY5EFeQxs4I+lYq8+Gir5ZGV8ijF/ASz1 qfHR5FvyCpdlIbXY14yfRVGwcINYRu9VWUAwMSiidskuRfjTfeaboScvH/0zzy6KrZBm f2hs2g8cWoLFCOH9gfoHv4GKZ/AB4ooo3amQjvvYHtjLwOyQFZzSIWNxFwVosUTexhEQ BqZP4Mr7gToXMHM804zHbC+UwlQisMAzXGT5r4HvP/j8lw0CohLvwOEWOGyAlwChKhgw PJUTyyFhxnyQJj/E1HQaQ0CBawnrpFa0LQkUDkpXEWpxWDXdBkumt2iMbeDvv59fELrw EBxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-filter:dkim-signature; bh=CcnDxriYxqcpTwrZh8ckQuwxWlV8bTgVDsSTjVTkKS4=; b=gklOyD50sRheuq46ChMkZvwTqfh7gL9LyQ4+HgDbR7W5152ibC6HsLg4JNpzY+gnt1 xRUxML/ezaOY6/RPklXNKHVLdkj09fP3SobvNsD6LTGym1JA2dHIVaiUZuL9aSGg4wpR P5BDIT2h4kZ3br95zIdNYAqlNfh9xT2UKESKKmBorPYpStchuLl4qOF3atbMDWUFeQsL EWvyIU0oe2zb5PPvJZZmEq5ldVHGeA2gOgS53mq3mXTZbOfExjCxs/1WGMfbGMGCaeIz Gf3aW5etLkk+4TPNgUOMdTjnbOTeimpY5UenX2MzArpJAC+3HqRJ4KCb8NoDeZ8Arh0D gACw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fjfi.cvut.cz header.s=20151024 header.b=CVOKAUIA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j66si7854pfb.182.2019.02.14.02.00.30; Thu, 14 Feb 2019 02:00:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fjfi.cvut.cz header.s=20151024 header.b=CVOKAUIA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404833AbfBNARL (ORCPT + 99 others); Wed, 13 Feb 2019 19:17:11 -0500 Received: from mailgw1.fjfi.cvut.cz ([147.32.9.3]:47566 "EHLO mailgw1.fjfi.cvut.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733227AbfBNARI (ORCPT ); Wed, 13 Feb 2019 19:17:08 -0500 Received: from localhost (localhost [127.0.0.1]) by mailgw1.fjfi.cvut.cz (Postfix) with ESMTP id 32EF8AA293; Thu, 14 Feb 2019 01:17:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fjfi.cvut.cz; s=20151024; t=1550103425; i=@fjfi.cvut.cz; bh=CcnDxriYxqcpTwrZh8ckQuwxWlV8bTgVDsSTjVTkKS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CVOKAUIAIKoILOHfy8EGBNhAd4tgzcdnwjVIA7mztxdyKig+RjayirfSEQaKLGA4f gyFNdTDr0jkjzFRc0o7plt+XLauQ5fkp7+jm0likNXDs43TPemv9pn3Ifc8QkoBl/G sVUdEMYHBjdy1OhWb0aorWc1LQipMhiaXY3Dxc0I= X-CTU-FNSPE-Virus-Scanned: amavisd-new at fjfi.cvut.cz Received: from mailgw1.fjfi.cvut.cz ([127.0.0.1]) by localhost (mailgw1.fjfi.cvut.cz [127.0.0.1]) (amavisd-new, port 10022) with ESMTP id fQfIGqScLLLx; Thu, 14 Feb 2019 01:16:55 +0100 (CET) Received: from linux.fjfi.cvut.cz (linux.fjfi.cvut.cz [147.32.5.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mailgw1.fjfi.cvut.cz (Postfix) with ESMTPS id CE2B8AA28A; Thu, 14 Feb 2019 01:16:54 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mailgw1.fjfi.cvut.cz CE2B8AA28A Received: by linux.fjfi.cvut.cz (Postfix, from userid 1001) id B258D6004E; Thu, 14 Feb 2019 01:16:54 +0100 (CET) From: David Kozub To: Jens Axboe , Jonathan Derrick , Scott Bauer , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonas Rabenstein , David Kozub Subject: [PATCH 08/16] block: sed-opal: reuse response_get_token to decrease code duplication Date: Thu, 14 Feb 2019 01:16:00 +0100 Message-Id: <1550103368-4605-9-git-send-email-zub@linux.fjfi.cvut.cz> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1550103368-4605-1-git-send-email-zub@linux.fjfi.cvut.cz> References: <1550103368-4605-1-git-send-email-zub@linux.fjfi.cvut.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: David Kozub Signed-off-by: Jonas Rabenstein Reviewed-by: Scott Bauer Reviewed-by: Christoph Hellwig Reviewed-by: Jon Derrick --- block/sed-opal.c | 46 +++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/block/sed-opal.c b/block/sed-opal.c index 3f368b14efd9..5cb8034b53c8 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -883,27 +883,19 @@ static size_t response_get_string(const struct parsed_resp *resp, int n, const char **store) { u8 skip; - const struct opal_resp_tok *token; + const struct opal_resp_tok *tok; *store = NULL; - if (!resp) { - pr_debug("Response is NULL\n"); - return 0; - } - - if (n >= resp->num) { - pr_debug("Response has %d tokens. Can't access %d\n", - resp->num, n); + tok = response_get_token(resp, n); + if (IS_ERR(tok)) return 0; - } - token = &resp->toks[n]; - if (token->type != OPAL_DTA_TOKENID_BYTESTRING) { + if (tok->type != OPAL_DTA_TOKENID_BYTESTRING) { pr_debug("Token is not a byte string!\n"); return 0; } - switch (token->width) { + switch (tok->width) { case OPAL_WIDTH_TINY: case OPAL_WIDTH_SHORT: skip = 1; @@ -919,37 +911,29 @@ static size_t response_get_string(const struct parsed_resp *resp, int n, return 0; } - *store = token->pos + skip; - return token->len - skip; + *store = tok->pos + skip; + return tok->len - skip; } static u64 response_get_u64(const struct parsed_resp *resp, int n) { - if (!resp) { - pr_debug("Response is NULL\n"); - return 0; - } + const struct opal_resp_tok *tok; - if (n >= resp->num) { - pr_debug("Response has %d tokens. Can't access %d\n", - resp->num, n); + tok = response_get_token(resp, n); + if (IS_ERR(tok)) return 0; - } - if (resp->toks[n].type != OPAL_DTA_TOKENID_UINT) { - pr_debug("Token is not unsigned it: %d\n", - resp->toks[n].type); + if (tok->type != OPAL_DTA_TOKENID_UINT) { + pr_debug("Token is not unsigned int: %d\n", tok->type); return 0; } - if (!(resp->toks[n].width == OPAL_WIDTH_TINY || - resp->toks[n].width == OPAL_WIDTH_SHORT)) { - pr_debug("Atom is not short or tiny: %d\n", - resp->toks[n].width); + if (tok->width != OPAL_WIDTH_TINY && tok->width != OPAL_WIDTH_SHORT) { + pr_debug("Atom is not short or tiny: %d\n", tok->width); 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) -- 2.20.1