Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5954056rwd; Wed, 24 May 2023 08:55:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5NbkV/uxdA9+TA+e3Eg/67YdHOcCMsEoJ64FWmIwOeMnat3Jx2ZjG4v9+7ZjclCmC8soVz X-Received: by 2002:a05:6a20:918b:b0:104:e240:c365 with SMTP id v11-20020a056a20918b00b00104e240c365mr19771357pzd.44.1684943746853; Wed, 24 May 2023 08:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684943746; cv=none; d=google.com; s=arc-20160816; b=mLXNOTdF3bUEQZDVpfFjOqs5jc3yvBRMP6CaWG7YIP/PIXUAZ/jjycE0Dhe2rPi7fb dXaLbAyUOCBVuM8S+g1vaBdw5nlEwDnw66tfhKGgfmrTBnhPqx3kDBFf5/ULESDABq7u 0omfPDWfcRgv4sHArj9vXYK8Yx6tEi/GiqqxcQ5yPTEDC7ozN7Fn2ygCe3DyYzzlPnqX bLyHoZYKfbYXm+TyXq+BQQW+KJRAWb1i6MyjTTEPxN4Je25lIgPARMrzmKDY7/u4pqT8 WyG46OGxznrDvTk7ZfhFUQj6hoGr8oc7wETOknAboYEi3t7Bf1FDoRz+QjE+UEtbbajg V/hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=ZleL3ST0XPNGt2fgQSXW/cK2rv3FOpZbAigNjtSUHpo=; b=0mWMZRpK3incv89L/E8Pj1kvg3aIaQJGhvT8bGNpBvzSenRuTKoCYojCr2c8WWeO3O ACHJOGSZHW9ebMOZX1ngVWoyJ86IMKYiqMUvJWDlmg2ISYPT/JGhqi/q6gjz+2Uom0oR FhCDuuT84hSVyjqsaA/DCXCfcuVC+xz1gYxZVZBY5v0/eloyxC/NPMuxqkJfnjKGeTni 11iTwOr9OxsXKCGFgAhauIr6tnj/1xSXJRQgUbk+N4Qu4wHD1KIPyrAJyA5Yn4abBH/s gZARyt0fskMSkN1IQ6vJRfz1Z+gUQ/M063sRBgUU8SjkF5Ti29jKvn6K+dJmjEfm1OlS jwcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=Whtsf3ws; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b24-20020a639318000000b0051ae6c4084dsi8244133pge.512.2023.05.24.08.55.33; Wed, 24 May 2023 08:55:46 -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=pass header.i=@siemens.com header.s=fm1 header.b=Whtsf3ws; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237484AbjEXPmx (ORCPT + 99 others); Wed, 24 May 2023 11:42:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237289AbjEXPma (ORCPT ); Wed, 24 May 2023 11:42:30 -0400 Received: from mta-64-228.siemens.flowmailer.net (mta-64-228.siemens.flowmailer.net [185.136.64.228]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FC2FE72 for ; Wed, 24 May 2023 08:41:51 -0700 (PDT) Received: by mta-64-228.siemens.flowmailer.net with ESMTPSA id 202305241540505a8954b986c978e742 for ; Wed, 24 May 2023 17:40:50 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=alexander.sverdlin@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc; bh=ZleL3ST0XPNGt2fgQSXW/cK2rv3FOpZbAigNjtSUHpo=; b=Whtsf3wsUzZRPWC2b2MKrRj//aDpTZWpoxk2yrNtcz6L2rzh/g89piOB6KxKvavL21nSHz H2M2xfC1o48MyIri4KaltHmlHri2QW9AceMgY1TEkDff5jc/PpLq3EI9egyJtLl06LSE7sf2 lGKVRAr4qK8c0oNPgaeke9XMNG3XQ=; From: "A. Sverdlin" To: linux-integrity@vger.kernel.org Cc: Alexander Sverdlin , Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , linux-kernel@vger.kernel.org, Alexander Steffen , Michael Haener Subject: [PATCH 1/2] tpm: tis_i2c: Limit read bursts to I2C_SMBUS_BLOCK_MAX (32) bytes Date: Wed, 24 May 2023 17:40:39 +0200 Message-Id: <20230524154040.1204030-1-alexander.sverdlin@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-456497:519-21489:flowmailer X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Alexander Sverdlin Underlying I2C bus drivers not always support longer transfers and imx-lpi2c for instance doesn't. SLB 9673 offers 427-bytes packets. Visible symptoms are: tpm tpm0: Error left over data tpm tpm0: tpm_transmit: tpm_recv: error -5 tpm_tis_i2c: probe of 1-002e failed with error -5 Fixes: bbc23a07b072 ("tpm: Add tpm_tis_i2c backend for tpm_tis_core") Tested-by: Michael Haener Signed-off-by: Alexander Sverdlin --- drivers/char/tpm/tpm_tis_i2c.c | 37 ++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_i2c.c b/drivers/char/tpm/tpm_tis_i2c.c index c8c34adc14c0..106fd20d94e4 100644 --- a/drivers/char/tpm/tpm_tis_i2c.c +++ b/drivers/char/tpm/tpm_tis_i2c.c @@ -189,21 +189,28 @@ static int tpm_tis_i2c_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len, int ret; for (i = 0; i < TPM_RETRY; i++) { - /* write register */ - msg.len = sizeof(reg); - msg.buf = ® - msg.flags = 0; - ret = tpm_tis_i2c_retry_transfer_until_ack(data, &msg); - if (ret < 0) - return ret; - - /* read data */ - msg.buf = result; - msg.len = len; - msg.flags = I2C_M_RD; - ret = tpm_tis_i2c_retry_transfer_until_ack(data, &msg); - if (ret < 0) - return ret; + u16 read = 0; + + while (read < len) { + /* write register */ + msg.len = sizeof(reg); + msg.buf = ® + msg.flags = 0; + ret = tpm_tis_i2c_retry_transfer_until_ack(data, &msg); + if (ret < 0) + return ret; + + /* read data */ + msg.buf = result + read; + msg.len = len - read; + msg.flags = I2C_M_RD; + if (msg.len > I2C_SMBUS_BLOCK_MAX) + msg.len = I2C_SMBUS_BLOCK_MAX; + ret = tpm_tis_i2c_retry_transfer_until_ack(data, &msg); + if (ret < 0) + return ret; + read += msg.len; + } ret = tpm_tis_i2c_sanity_check_read(reg, len, result); if (ret == 0) -- 2.40.1