From patchwork Mon Jun 5 17:59: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: 103428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2875757vqr; Mon, 5 Jun 2023 11:27:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6njJKLJfhy6zeB7ydhbzCKO7rqq1LrXxo29V/SwScrI3hjzLF9khQi49t+r++UIw/va098 X-Received: by 2002:a17:902:6509:b0:1af:bbfd:1c07 with SMTP id b9-20020a170902650900b001afbbfd1c07mr8064937plk.57.1685989670188; Mon, 05 Jun 2023 11:27:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685989670; cv=none; d=google.com; s=arc-20160816; b=TgVTtC+Kjh4nSpSpBxR2TzQJ+x1qyMGOaNC4lilntKRL5IksT+NQkz0IthrAM+2GYR doJ9jdlznFvQNOkNpKn0+V6t4O1CaOeJFVZJ6fn7Ly6xRdWjw9yXvVPjH48GVmuiB0d8 vMt/3q3qvmf0AHzfWBUg2k4tsEix3fmhSmQ5iJLVifdqwBRKCS0JP61V5mDPnXiYmegP 4yiiPxnoWYc2wJEqx2frxf48JTejgjM79hm0iUkWyY1+bv9++n+IfoQpNcmCGLpMVs9m LUoChUAgaNRADjp+6B6n/9evjYqVphK3cCEpGlR5CYOI94LHFXfiUOHVDt/mA4/9fwIm nLpg== 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=lhIvdsY1fmzgl4mlwx9ldBWMXg48hj3vrnGED3H/TbQ=; b=BTrvs/DfJHGIxE4WixAovLO0nA2yoWU5QYvWb9qHsKwA79o6ykJ2r0F53x0b7AZd3i ramWmxUxsjxAozrEP78qmTakfcRe9ayM3qPhBcf+AfcVxTeaz/lz2pCEz2VBpSmrdCoL CwcNlvWmIQ/Dy/XAgTYR3iD5q8VSRXFsCBaaAO4pPbJGDCKy1CxMGQIpAOXbkc1wd2xo PSudi4ObRdcHtG9Lc/usJf4xaM/rhwSqnERUcVTAyR4MjzN8boFux2Vtue3joXj6WmwN v+6CmESFfyZIZ4Z5pp4gJqe3BRqHKyjca/iFQbLGZQtz3WXO7MtPNMLlHk5BX4hzaG7l LzrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=STzSKAPq; 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 x1-20020a170902a38100b001ac2ff9fbf8si5553475pla.403.2023.06.05.11.27.34; Mon, 05 Jun 2023 11:27:50 -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=STzSKAPq; 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 S233705AbjFESAS (ORCPT + 99 others); Mon, 5 Jun 2023 14:00:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjFESAL (ORCPT ); Mon, 5 Jun 2023 14:00:11 -0400 Received: from smtp2.infineon.com (smtp2.infineon.com [IPv6:2a00:18f0:1e00:4::4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66602D3; Mon, 5 Jun 2023 11:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1685988010; x=1717524010; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=unN7GipSX//PB49ZOaB1Vh0lCsSkaIGKdO4Lzy+O6v0=; b=STzSKAPqj5lHk2fwDHS8N+VvYAUrgzmw1F7345Lpe6AcscqXRZlACb/X SKvVkhVTH78GQjxbvD35EUhj0MeWtztak7VUhdGg0DJxujd7ga80pXVbF GL4Q+2nGFWJfAZbRBYMXqVM7lneVw7Oj90hcajcYY3715ls/gFHEIwCcz g=; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="40773232" X-IronPort-AV: E=Sophos;i="6.00,218,1681164000"; d="scan'208";a="40773232" Received: from unknown (HELO MUCSE803.infineon.com) ([172.23.29.29]) by smtp2.infineon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 20:00:08 +0200 Received: from KLUSE818.infineon.com (172.28.156.171) by MUCSE803.infineon.com (172.23.29.29) 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 20:00:08 +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 20:00:08 +0200 From: Alexander Steffen To: , , CC: Alexander Steffen Subject: [PATCH v2 1/4] tpm_tis: Explicitly check for error code Date: Mon, 5 Jun 2023 19:59:56 +0200 Message-ID: <20230605175959.2131-2-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20230605175959.2131-1-Alexander.Steffen@infineon.com> References: <20230605175959.2131-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [10.161.6.196] X-ClientProxiedBy: MUCSE804.infineon.com (172.23.29.30) 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?1767888304179760733?= X-GMAIL-MSGID: =?utf-8?q?1767888304179760733?= 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. 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;