Received: by 10.213.65.68 with SMTP id h4csp1731056imn; Mon, 19 Mar 2018 11:41:22 -0700 (PDT) X-Google-Smtp-Source: AG47ELtuc//k7llizokOBeXrACR+vbPkEE8p4KD8Bj6yBZXQxSMmLutynC15YvsRFNoU6dPI19H4 X-Received: by 10.99.120.5 with SMTP id t5mr10184387pgc.30.1521484882305; Mon, 19 Mar 2018 11:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521484882; cv=none; d=google.com; s=arc-20160816; b=u3Qz7+gIlE7EaWONkC5VGkecf1qdkLDwtz9ntiuj3w1wJADrF1EnMU3nq6LmO4xbOH uICXUbCAuZDe27OvjuDzKxzFlUZun/TzkVhOfbSDRk767WaKKxgCvvshRrauIoTvWgf2 0q6bNebG9m9YgjzbQk4uyjwLCwWdGIAV5dh4NQ/i3p+8wYGbACTgtNCpRgJbzQahPJHU 4M6/jkzet5M4hRd2uetKymLOWQe0gVLzdqyKpWYOihG29Q9VRbSgrsL8Fo6br82A3xhT BC8yHm7uRDXLCF0L2hfzHgm8xkVOAAkYfkFuGiUYyAT7W7Gn1+ZVsZ24H6lsbjI+n+ox yPAg== 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:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=sPyIAkVDtysUbBMvdD24X5WBJq3Szo9ze+uz0pqBhtQ=; b=aCswvTQJpmGQwCzj/G5Xm7uV6JmbNVSiojrGTuC75lVhuShy2MO0Vzg6wDohwubJiF i82jA0jDVwWE3PP8iIhXYrZcuFR+MU/ITMAK/ZELhJpQnJc9h+M0UIwDhWvldnmjYaro jcYe5h7BAalhGmPo1Ia3IDnLHZLwXzOOb4D99pV2Hm95iDwPMhKDVDNCTuJ3Mf6ewiBc ddwLds41QQGv4H3+7eHOzavSTVLDXHDf6ANTq9pphZH83EEDuFPr+nJ6UDc33v7EMTQI hFemv8bWQKWhgR7XBm/RGLrAh+BEUpS946aBn25nn6oZC6mFM9aN1jhDHAUWvs/7xlRz 4LAw== ARC-Authentication-Results: i=1; mx.google.com; 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 i35-v6si409447plg.48.2018.03.19.11.41.07; Mon, 19 Mar 2018 11:41:22 -0700 (PDT) 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; 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 S1032065AbeCSSh6 (ORCPT + 99 others); Mon, 19 Mar 2018 14:37:58 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de ([131.188.11.21]:58480 "EHLO mx-rz-2.rrze.uni-erlangen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935161AbeCSShx (ORCPT ); Mon, 19 Mar 2018 14:37:53 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de (mx-rz-2.rrze.uni-erlangen.de [IPv6:2001:638:a000:1025::15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx-rz-2.rrze.uni-erlangen.de (Postfix) with ESMTPS id 404lDb4dbBzPkDb; Mon, 19 Mar 2018 19:37:51 +0100 (CET) Authentication-Results: mx-rz-2.rrze.uni-erlangen.de; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Quarantine-ID: X-Virus-Scanned: amavisd-new at boeck2.rrze.uni-erlangen.de (RRZE) X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-RRZE-Flag: Not-Spam X-RRZE-Submit-IP: 2003:d5:3db:1800:60b5:55d8:d757:229 Received: from fau.de (p200300D503DB180060B555D8D7570229.dip0.t-ipconnect.de [IPv6:2003:d5:3db:1800:60b5:55d8:d757:229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: U2FsdGVkX18m1BE7IX8NRW54ZMlVhp8pN0H0DHqvXkg=) by smtp-auth.uni-erlangen.de (Postfix) with ESMTPSA id 404lDX2BZXzPjpJ; Mon, 19 Mar 2018 19:37:48 +0100 (CET) From: Jonas Rabenstein To: Jonas Rabenstein , Scott Bauer , Jonathan Derrick , Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig Subject: [PATCH v2 04/11] block: sed-opal: unify error handling of responses Date: Mon, 19 Mar 2018 19:36:46 +0100 Message-Id: <4a20f9848927d0f654491136e4821f2adab131cc.1521482295.git.jonas.rabenstein@studium.uni-erlangen.de> X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Also 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. Signed-off-by: Jonas Rabenstein diff --git a/block/sed-opal.c b/block/sed-opal.c index efe5d2a7f3dc..30f6e46518a6 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -697,6 +697,11 @@ static const struct opal_resp_tok *response_get_token( { const struct opal_resp_tok *tok; + if (!resp) { + pr_debug("Response is NULL\n"); + return ERR_PTR(-EINVAL); + } + if (n >= resp->num) { pr_debug("Token number doesn't exist: %d, resp: %d\n", n, resp->num); @@ -879,27 +884,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; @@ -915,37 +912,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 it: %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.16.1