From patchwork Mon Jun 5 17:52:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 103409 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2860737vqr; Mon, 5 Jun 2023 11:02:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7h8r6C1vuFe2ywR74JK04+z+vlwfA+GUw+fBhV8IaETA/waaN67VTc/P4Sa93cP9tT2U5Z X-Received: by 2002:a05:6a21:9988:b0:10b:8a27:bb59 with SMTP id ve8-20020a056a21998800b0010b8a27bb59mr5021738pzb.47.1685988146772; Mon, 05 Jun 2023 11:02:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685988146; cv=none; d=google.com; s=arc-20160816; b=xabDqZbDvL4y4+fAqB61Sqs0nFjdjfI7CpkD+gonkxMei+Jckh0Z1WVYXLzEU0NknC Vb3qnuuGs5E6rqBRqImAHdM3bnPGmma+XrEYRz8mDFfkqR+4t/2V7AHPw9NjIKObhbdi 2lvj8XOUBMtra0bvtjXiqoshjgDHX0RtXgYTtsOyDfsYSHZW4eLKBGXhPwCK4fXa0XIb mqE4hDiuHyjswoouby9iNHkPVQkStVm5FslOO/NL+kiZFB2Xc3EF5vXb1ArJK/XZdVPK CBwxGuBzFtyR+GyRSghr9j40UKHnzlMZiPCVPltOlla+l4YNVFTbz/f2hV4x+/k6WsDv 5iHg== 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=dBGZeEYdkTm3ANHKfBq4PB4RQ0alOFfFcDbeccpyrM0=; b=HJgzx/UKGXNy67vyl4HVVWVJB2pZWoNm+lxn1eFw8WBZlE9Lia6ny1o1BwXsA/4J6J fnjO0BS4mEH/xQwYz7Hr5JSidmCpficRM5swCx5OspzxiNtqWRDdT/KDMIbuMdNBE9Xd BzUir7+wl1TZvgFgiqodveGfAtW/W+fo/z+5wj6iRD5eOxs4wp3pFr0nZyZHcwc7gQX6 +uibkWkqB5zdmIzlOl0ouQ/WqM1An4LEntcbZeC3Uu3gNc6QX/+cXAscZooGdyLdaH/j 5PWKnBW+LMogX/w/bHFvtc8dD62rogfZrRJxFUiM+gV02wMLsyHz1lJ3gzgVstRwRIRo 9P6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=ln13UZZc; 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 l7-20020a63be07000000b005303a26dbf8si5594274pgf.408.2023.06.05.11.02.10; Mon, 05 Jun 2023 11:02:26 -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=ln13UZZc; 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 S235153AbjFERxf (ORCPT + 99 others); Mon, 5 Jun 2023 13:53:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235187AbjFERx2 (ORCPT ); Mon, 5 Jun 2023 13:53:28 -0400 Received: from smtp11.infineon.com (smtp11.infineon.com [IPv6:2a00:18f0:1e00:4::5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B279100; Mon, 5 Jun 2023 10:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1685987607; x=1717523607; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=v9H0eyeHOdjewny8tzzedWjAUOkDdFz5OOsBgwYf/hM=; b=ln13UZZc9v+A3SRds2Y6QsIrFJxYaAQ9U9QlYLX31r2Oh5e2PVuKEx+r Wd655OUxB3/HBPeO96/eC/vG4DCbF4d3PTCXE0iXyPxM9gS1r7mMdvoRz J/VM4E9MrfPC04KPXaJF9hOrQhiML6c3EOazBvnBsJFKMS6ggVrtvtf0W I=; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="17446197" X-IronPort-AV: E=Sophos;i="6.00,218,1681164000"; d="scan'208";a="17446197" Received: from unknown (HELO MUCSE814.infineon.com) ([172.23.29.40]) by smtp11.infineon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 19:53:24 +0200 Received: from KLUSE818.infineon.com (172.28.156.171) by MUCSE814.infineon.com (172.23.29.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 5 Jun 2023 19:53:24 +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; Mon, 5 Jun 2023 19:53:23 +0200 From: Alexander Steffen To: , , CC: Alexander Steffen Subject: [PATCH 1/4] tpm_tis: Explicitly check for error code Date: Mon, 5 Jun 2023 19:52:47 +0200 Message-ID: <20230605175250.2055-2-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20230605175250.2055-1-Alexander.Steffen@infineon.com> References: <20230605175250.2055-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [10.161.6.196] X-ClientProxiedBy: MUCSE817.infineon.com (172.23.29.43) 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 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?1767886707182900774?= X-GMAIL-MSGID: =?utf-8?q?1767886707182900774?= 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. Change-Id: I5a310daaa71f0acaaf7fff62cadd79d5edaa9207 Signed-off-by: Alexander Steffen --- 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;