Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2405439imu; Thu, 17 Jan 2019 13:38:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN4Mf+yMcqKElhgUA3B9Ikd8PgWsYFs5Vm7q9nEEiXkwhw1Lg0n+q3GGYxIoqtlwBM08l4Dz X-Received: by 2002:a17:902:108a:: with SMTP id c10mr16727245pla.131.1547761090290; Thu, 17 Jan 2019 13:38:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547761090; cv=none; d=google.com; s=arc-20160816; b=w5PPge+fh+DTb1cjsMK3XSwXkq1SYns39JI6zAaZFnuyL7yQuddJGISd6BDPW9UkZO S94duUqCPvi8YwVoWRrYiTEe14773PTgUC5Elwcp+0AZyFkkmqZ6xowxWrZbDq7mOHy8 gj2aiuJyqKDb9bXF1gDu+imF9a1fSPA5hWiy/f038y8MtkGI71WNYCWD8csDD+3yu6E3 7LmHsczLeJGsTWiCGkQixEpfXKPpwTqcmjtiozcQeFVIo/CdZKeDaGRRthd7DUKbYBaU MBI2Kc4SYkeMsdsejktjl8ma95vrSRfdt19cNmbAgs0qhsDaRdH/B2NEYeejaNBLZRXW qX5w== 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=uX2eDIOSDa5Anhf6mUlNXG64ORX24xhnNJO0u9bCxaY=; b=MLXA3FvPomYRUaL7LKTTXzZose+Ih2Kn859dxBK+CpAKX2UrybrPT+iCjeuYR/H6Jz e3po+6YIPB+Y2sEBWCG2tXwxzIU7YZuxzm95qlGzeKL/90V9UJavrtEvnIulZr1JPNdP SHGHtMOqgSxkShUGvT/V+amaT79ER6o2vO8LM0WaqtwWsfJi2y/g8jyb4SF1/L4BK90E dlt/oggE9WQ5BUguwUfM/AN1zGcU+ZEtkbxY6W4YdEvOP1woksIXZg6HuE5zvxqdU9DJ 81+wPZKhcQTU40ndWAH4wBAytVNwO3IN4F6QeC+xHe2goSN50N6ZjL20OMsbO1sh52ET pneg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fjfi.cvut.cz header.s=20151024 header.b=BkwbGKGW; 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 l129si2926044pfl.284.2019.01.17.13.37.55; Thu, 17 Jan 2019 13:38:10 -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=BkwbGKGW; 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 S1729799AbfAQVda (ORCPT + 99 others); Thu, 17 Jan 2019 16:33:30 -0500 Received: from mailgw1.fjfi.cvut.cz ([147.32.9.3]:35466 "EHLO mailgw1.fjfi.cvut.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729738AbfAQVd0 (ORCPT ); Thu, 17 Jan 2019 16:33:26 -0500 Received: from localhost (localhost [127.0.0.1]) by mailgw1.fjfi.cvut.cz (Postfix) with ESMTP id C21E5A3964; Thu, 17 Jan 2019 22:33:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fjfi.cvut.cz; s=20151024; t=1547760802; i=@fjfi.cvut.cz; bh=uX2eDIOSDa5Anhf6mUlNXG64ORX24xhnNJO0u9bCxaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BkwbGKGWg5p0jtiyN1oZxn6lWLWaIE6FWbz/kWXibOpMB+rEgXpHmyXhCnpusO/80 Axo/AcjWLfIgKsAbOGK+RFU5CN4TEAdBroy1D5GaxRPF1CAAnkSbAwK06/YSSdzRVq Hk5RhHneAFZBw2TCmfwHySIiWOLBOprhmBhLcDnE= 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 42Mm6Jcgea19; Thu, 17 Jan 2019 22:33:13 +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 0BFD5A2F18; Thu, 17 Jan 2019 22:33:09 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mailgw1.fjfi.cvut.cz 0BFD5A2F18 Received: by linux.fjfi.cvut.cz (Postfix, from userid 1001) id D48F06004E; Thu, 17 Jan 2019 22:33:08 +0100 (CET) From: David Kozub To: Jens Axboe , Jonathan Derrick , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonas Rabenstein , David Kozub Subject: [PATCH v2 07/16] block: sed-opal: reuse response_get_token to decrease code duplication Date: Thu, 17 Jan 2019 22:31:47 +0100 Message-Id: <1547760716-7304-8-git-send-email-zub@linux.fjfi.cvut.cz> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1547760716-7304-1-git-send-email-zub@linux.fjfi.cvut.cz> References: <1547760716-7304-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 --- 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 537cd73ea88a..1332547e5a99 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -889,27 +889,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; @@ -925,37 +917,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