Received: by 10.213.65.68 with SMTP id h4csp341320imn; Tue, 13 Mar 2018 06:12:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELuWvfhFMe/wFgMi2OXUWny12Lw/68enHa4ruoaGOgpztRx7tHqUQlyNkKcOuPsL0OIgQ3z4 X-Received: by 2002:a17:902:6ec5:: with SMTP id l5-v6mr539718pln.113.1520946764844; Tue, 13 Mar 2018 06:12:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520946764; cv=none; d=google.com; s=arc-20160816; b=NqwhGSuTeMgxVHMcYaHcLg6JlP4xl7Wv6Ifk64HOh59UQ9Kn9MX6pxs3sg6eyLJ5VF 6ykaJhx+hMyYGn3vBSA3plSjSAyGwHqh9CLDO2Mlgr+ZNMFo5XDi+pEcStAIXukmpuL5 2SHDPTsRwWSHlo3iO6RKRdZguk48wQk0V/JkdB4JVySyR976X57UZJHSHbMa4j1vwABu 6vgpu7zChGz3mryIMhsIv9kdGs0A3Hu3ztwcR5iQzrV9nfoQZiHtUcSEqeAwsQ8iJceL vTb0nQzTyjZrkbNcXqCyIWR7Waui1P5WbFQ0/5zHr+MlPecmWPUeYmmuxTMliEB56AMy 4QyQ== 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=mBOM/Lb8s4vuKkbZGwgFYqlHKPnwBi40Aeakj6B3b3g=; b=fxfsG5F70imGwcQRWGn5plOY+j9FtzCopXbTb0p06DE1tQT4VEz5qv4WkPd/a4gg2U nW/4TRUVmpUjyCvAW6bybAF69PMEyWnRFC1wfKXpkoCbd1mNToVSC64HXOuH20pACApv uRDrZeUii1MsTmYPev+kGsCqBdAfW/YKja5sUzXQpAwqCooGDK1uZM4yuCmVSeP7con2 9XwbS0RcThtuOCapdbYwADf25A+YaH4h4L+KFn8eByjvw9PGohiC6PZxiAZxJqEqvqog RPSN3SxMXUB53dtH4X2i8YYFpmP7M+8RjKwGRWqiBeHaCL2QHVFExY+bSuVbTjSAvDug HqaA== 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 e4si110268pgt.185.2018.03.13.06.12.30; Tue, 13 Mar 2018 06:12:44 -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 S932570AbeCMNJu (ORCPT + 99 others); Tue, 13 Mar 2018 09:09:50 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de ([131.188.11.21]:34448 "EHLO mx-rz-2.rrze.uni-erlangen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752604AbeCMNJm (ORCPT ); Tue, 13 Mar 2018 09:09:42 -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 400wDh755tzPjls; Tue, 13 Mar 2018 14:09:40 +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 boeck4.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:3c2:e00:dbd1:5c46:f440:b630 Received: from fau.de (p200300D503C20E00DBD15C46F440B630.dip0.t-ipconnect.de [IPv6:2003:d5:3c2:e00:dbd1:5c46:f440:b630]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: U2FsdGVkX19ZLbQdYwjY/Jf4wXxFFvklGF+6x0X2sC4=) by smtp-auth.uni-erlangen.de (Postfix) with ESMTPSA id 400wDd4w2mzPkKG; Tue, 13 Mar 2018 14:09:37 +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 Subject: [PATCH 4/8] block: sed-opal: unify error handling of responses Date: Tue, 13 Mar 2018 14:08:57 +0100 Message-Id: <04455788aa86e6d2e8cd09e24f64c23af5070c08.1520946114.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 --- block/sed-opal.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/block/sed-opal.c b/block/sed-opal.c index 22dbea7cf4d1..5a448a3ba1df 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -698,6 +698,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); @@ -883,18 +888,10 @@ static size_t response_get_string(const struct parsed_resp *resp, int n, const struct opal_resp_tok *token; *store = NULL; - if (!resp) { - pr_debug("Response is NULL\n"); + token = response_get_token(resp, n); + if (IS_ERR(token)) return 0; - } - if (n > resp->num) { - pr_debug("Response has %d tokens. Can't access %d\n", - resp->num, n); - return 0; - } - - token = &resp->toks[n]; if (token->type != OPAL_DTA_TOKENID_BYTESTRING) { pr_debug("Token is not a byte string!\n"); return 0; @@ -922,16 +919,11 @@ static size_t response_get_string(const struct parsed_resp *resp, int n, 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 *token; - if (n > resp->num) { - pr_debug("Response has %d tokens. Can't access %d\n", - resp->num, n); + token = response_get_token(resp, n); + if (IS_ERR(token)) return 0; - } if (resp->toks[n].type != OPAL_DTA_TOKENID_UINT) { pr_debug("Token is not unsigned it: %d\n", -- 2.16.1