From patchwork Wed Jun 29 23:26:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12900803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9A30CCA47E for ; Wed, 29 Jun 2022 23:27:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231523AbiF2X1r (ORCPT ); Wed, 29 Jun 2022 19:27:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231368AbiF2X1k (ORCPT ); Wed, 29 Jun 2022 19:27:40 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7597624F13; Wed, 29 Jun 2022 16:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656545245; bh=FO1qKvjwo5OYPnKK1TQ+U7MMExJ4/KOfblZ/tjJSnxI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=jtTO7FOnilg87GhuFWwBPTq/qv/GMfnu/MrKug3vt4+GVjenkEbVGxAGCAn3aKMs0 /BGnUY7D/HUMk1hbZluL60hnO/UqNijfROrt95whTlCFgA7lpL6Uo9iH1++A7k1X6k 7iBfo5oLl62nnCCjDTn4sXVk9YuiYy2MoxRAmDeg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.23]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N49lD-1ngOgG23zV-0108ik; Thu, 30 Jun 2022 01:27:25 +0200 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v7 06/10] tpm, tpm_tis: Move interrupt mask checks into own function Date: Thu, 30 Jun 2022 01:26:49 +0200 Message-Id: <20220629232653.1306735-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:NK8V6gYmS9shuxcrgqlJD2IVankIghQH/8sonM50vYYQWUMuy8/ M6RiAs5r3z2QL7Dq1LGMWSkqdc+/QXaqtXT5PfT1r1goRtROuQfOQ6zzGdPN0ZKhcNqYT7i R50Y+jzin0V7tRBJqXSxKagbDHcjJJpsMmcTh8suHkSqofml97iD24sxJJyI0Ua9CgWGWxg XV+CpN7+fUi3NapKcUqKA== X-UI-Out-Filterresults: notjunk:1;V03:K0:4zETysfYVlw=:Z4puwgExUg62rspa9x73sk HBeJyveXQ29pji3+OnyuK/bmRWdX3lqtN0rHD7eKyqhRs1Fkw9gBUL61ZtfA+T4DEGl39ABx2 IE4aoOlr8K3Xay++20AX+Iek28fkQ+pHHuZ1WspveKXUJsfWlRKKXqf/OsXl9ufkC4WqKnVsX qmv0USFh2sAFZywJh9mkBX4lLkpwuaDumfYc6jlf3EHcWjvJZXceLS7CG65G/dSvViXrDSogB 860dD/gEli6NrtuhRvsnFTM61LtdQ3jFO7LvXBs58Bxrc/nZ3yG/ObWJNdtWCt15+82u75Jdz 5PGWmkt5fiYa7j7KBgmXJTj74Vgf68brLcy8VxW/drNR2UZJRc/gRmREA+EAcTqzL6ReysysK h6wymat8V6PEhRaTB52leBE0j3HG3xHmim8677hWuTvIfars4rwBLqIHBMDMrjnKHSDvyMIt8 G6XpY6CTkj8q45YXhwXisizdRA2GzoOtelyOqdlq/jey3TwHpe69ixP2dRnlhO4CsD6SfkqLW BQSrIvjGUy4ewzMX4TebejFfbkd+jd6agnH84a4KB/BfvGDt/Mju5Xogn34mqa9BO88JpTMC+ dCeehcj/OAcGlBrPt5Ca0Rg0zNTlUsmW/LlfWPhol1w7Vu+baapj1MrV2Gs0Hp5qmSzz88hwK i4IsoZtyatfSBl/uV1cADxzJ1Rt0TMe14aBO/QHTgr+u+3z02VlCM6W82Pw/xGIjwhwLu+S+c 6+JS2otPjK7QGDInWdifGgw/vJYRTmTOAxgCA5oJo4xGkMycXsI70ZnkE3HPLHIOxPqMbKnFK tg2qIBKRi19zxJJ3gEc3G0O920yHmFv63uMsA/JKpBDYZcbjKX1VQ4ted4LxmM+DHDB0B3CeF aVcFvOHZ4f69Yjm1qnwEoPDaUK4NPnyoEpHR7DB9/4OpSH8jVWg0WJXeqqLIhZHdQjn3/F3Iu KsXD9cy49e86/3lo5TDdvBjZ06K4E/xBmsIdtuKEZZTm7cIpFBjVUn3OggTrS8VbN5nKFtR5E 6jLU2bk9mtnN6O7fLHBP3FyeLx1HFiLRTxdzkFdZw29QqyMAV9zIEAloxRSDKqYFr2Ht8g3Qn odH8HDvoUF4wLFQzeC4wXN9OJ668jvWNyrVGqElID7tsQoUCLA+7E+KIg== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Clean up wait_for_tpm_stat() by moving multiple similar interrupt mask checks into an own function. Signed-off-by: Lino Sanfilippo Suggested-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index c13599e94ab6..bd4eeb0b2192 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -44,6 +44,20 @@ static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask, return false; } +static u8 tpm_tis_filter_sts_mask(u8 int_mask, u8 sts_mask) +{ + if (!(int_mask & TPM_INTF_STS_VALID_INT)) + sts_mask &= ~TPM_STS_VALID; + + if (!(int_mask & TPM_INTF_DATA_AVAIL_INT)) + sts_mask &= ~TPM_STS_DATA_AVAIL; + + if (!(int_mask & TPM_INTF_CMD_READY_INT)) + sts_mask &= ~TPM_STS_COMMAND_READY; + + return sts_mask; +} + static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, wait_queue_head_t *queue, bool check_cancel) @@ -53,7 +67,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, long rc; u8 status; bool canceled = false; - u8 sts_mask = 0; + u8 sts_mask; int ret = 0; /* check current status */ @@ -61,17 +75,10 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, if ((status & mask) == mask) return 0; + sts_mask = mask & (TPM_STS_VALID | TPM_STS_DATA_AVAIL | + TPM_STS_COMMAND_READY); /* check which status changes can be handled by irqs */ - if (priv->int_mask & TPM_INTF_STS_VALID_INT) - sts_mask |= TPM_STS_VALID; - - if (priv->int_mask & TPM_INTF_DATA_AVAIL_INT) - sts_mask |= TPM_STS_DATA_AVAIL; - - if (priv->int_mask & TPM_INTF_CMD_READY_INT) - sts_mask |= TPM_STS_COMMAND_READY; - - sts_mask &= mask; + sts_mask = tpm_tis_filter_sts_mask(priv->int_mask, sts_mask); stop = jiffies + timeout; /* process status changes with irq support */