From patchwork Tue Jun 13 18:02:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 107503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp741576vqr; Tue, 13 Jun 2023 11:16:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4+qJ6I71M+/f4uqt+A85dJneqJv4obbkNcAFtyAS5dYpvl3s/ZZSxyQTupfsyKar+5mYRK X-Received: by 2002:a17:902:f546:b0:1b2:1942:9106 with SMTP id h6-20020a170902f54600b001b219429106mr10475462plf.64.1686680205713; Tue, 13 Jun 2023 11:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686680205; cv=none; d=google.com; s=arc-20160816; b=Y62uJ+xPDfkUDCrVjiiutiW7nCr8F7ERbyFZE+Ws0GZ5Dy4iCtxrx13UAEyhdIn/oZ BIRQk8zETqQn2DdfWbeBjcbTyB4ogRMq3BGaYj3xeQb5UNK1oJR2NZCo8k6w2Rpnpm7T 1rh3o3I5bAmSouEv537/TQMYk8tTYf4ZTCeacjdgoeskNkN2WNPkYZQCBqUt3un3NmQ9 r4P0hTI0RLXwXBWCRQoKte/JR4og/6wWPgOEu3BhL4nP5JjJbMvqiBjH6rLsSi+hPAsn JPHt/lhkGL8RlyVaeaddvOXth5WLvW4zCF/OTh1okT8jblv4etvehBWr0Hb8J5vlU7qz 5OGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jzMSX9szzmTEHGRBH/satl3OXsPQGP/TLq72FMBNX1I=; b=wMzJaFj/MKfkFXpLJAyJTvcVJr5LjIon0p0adnhJXz1/Wl/qPZ/AjTs4E8sNDHerx/ knf9xHvoBMTr+BX5gYF1KUH5in1MQm0Hma8HP4rS+ttEslQe6fNiLeZ5D0s4IGfMu36j lqShmSJxOVkMFmt5Fx7l8ELiT1Q51H+63hvSuyDMeRpGDcCm+Z+UGB/sHLnHMNaRv5f1 nkfdpAtNaOdYgrHnEAfMztfypYJC/TwcWaEaSk6bmGCz/g0ENWuAOaSApZzMbzlEqsvw mwrQCvtXWkxcqWu//o18e3uvd4IpnKs2C/rz3Wbr3OS7tdwMhuCSfxHQ1t/7GqZT6kki pD/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=ogEGAI7w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s4-20020a170902ea0400b001ab0727a2c0si4525574plg.424.2023.06.13.11.16.33; Tue, 13 Jun 2023 11:16:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=ogEGAI7w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239561AbjFMSD3 (ORCPT + 99 others); Tue, 13 Jun 2023 14:03:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232105AbjFMSDV (ORCPT ); Tue, 13 Jun 2023 14:03:21 -0400 Received: from smtp2.infineon.com (smtp2.infineon.com [IPv6:2a00:18f0:1e00:4::4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2832319B2; Tue, 13 Jun 2023 11:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1686679399; x=1718215399; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S+EviMEa0wKQ948HPrnrT9RrRoeXZs1hePPbHJoq8fk=; b=ogEGAI7wXvOGi9N6sxb+y7Ra7LUx7cORUqk92YBBvC/crv/l2OA43YjW W+KzzDeYBS0rh0B3VuIB/ieMMXE3cBj4Smgk1Gs/rGX/76q7XosGi8DgT MrmwKG3SMw0XFW6/ZOc/QFaJ9J5tqt13mh7pf7GxLi3l+K1ApqdbksnFj E=; X-IronPort-AV: E=McAfee;i="6600,9927,10740"; a="41820522" X-IronPort-AV: E=Sophos;i="6.00,240,1681164000"; d="scan'208";a="41820522" Received: from unknown (HELO MUCSE819.infineon.com) ([172.23.29.45]) by smtp2.infineon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2023 20:03:16 +0200 Received: from KLUSE818.infineon.com (172.28.156.171) by MUCSE819.infineon.com (172.23.29.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Tue, 13 Jun 2023 20:03:16 +0200 Received: from ISCNPC0VBFBX.infineon.com (10.161.6.196) by KLUSE818.infineon.com (172.28.156.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Tue, 13 Jun 2023 20:03:15 +0200 From: Alexander Steffen To: , , CC: Alexander Steffen , Subject: [PATCH v3 1/4] tpm_tis: Explicitly check for error code Date: Tue, 13 Jun 2023 20:02:56 +0200 Message-ID: <20230613180259.3525-2-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20230613180259.3525-1-Alexander.Steffen@infineon.com> References: <20230613180259.3525-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [10.161.6.196] X-ClientProxiedBy: MUCSE821.infineon.com (172.23.29.47) To KLUSE818.infineon.com (172.28.156.171) X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768612382984317677?= X-GMAIL-MSGID: =?utf-8?q?1768612382984317677?= recv_data either returns the number of received bytes, or a negative value representing an error code. Adding the return value directly to the total number of received bytes therefore looks a little weird, since it might add a negative error code to a sum of bytes. The following check for size < expected usually makes the function return ETIME in that case, so it does not cause too many problems in practice. But to make the code look cleaner and because the caller might still be interested in the original error code, explicitly check for the presence of an error code and pass that through. Cc: stable@vger.kernel.org Fixes: cb5354253af2 ("[PATCH] tpm: spacing cleanups 2") Signed-off-by: Alexander Steffen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 558144fa707a..aaaa136044ae 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -363,8 +363,13 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) goto out; } - size += recv_data(chip, &buf[TPM_HEADER_SIZE], - expected - TPM_HEADER_SIZE); + rc = recv_data(chip, &buf[TPM_HEADER_SIZE], + expected - TPM_HEADER_SIZE); + if (rc < 0) { + size = rc; + goto out; + } + size += rc; if (size < expected) { dev_err(&chip->dev, "Unable to read remainder of result\n"); size = -ETIME;