From patchwork Thu Nov 24 13:55:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13055006 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 201E0C4321E for ; Thu, 24 Nov 2022 13:56:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230112AbiKXN4f (ORCPT ); Thu, 24 Nov 2022 08:56:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbiKXN4c (ORCPT ); Thu, 24 Nov 2022 08:56:32 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AB80F8028; Thu, 24 Nov 2022 05:56:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298172; bh=acaYZLOzjstSk1ewiw/25/8EH4h8E4f6Mhp7/e/Rz5w=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=OaCBfR5NBfypcT1zSMwJD814rZYvvu1zviaK+TZg+laBXbTG99/ckYdVg+29iJCE3 WOZ0QoeyRJingQVkLhacS9qmFt7dFmT/BVS9P2cWDVEVk/JaCSvaGrob/VYOzMMFq/ Pk60gwgGt2+SCROVVFqaddpSrX+d/ACqQR/splHbNENsiX/pCxEdcADcagfC2ud3g8 a28SdMFKfFrp4X71P7cehGUZoHfCbQpR5nsGKXcENqZFMseXEG0U196+NCsXkcIMbm 8543BhEunC6OCN6Ii/qTFk3b6mk4IWY5FHWN6s41qXrTsqlbj3LEw4IxCVDw05zvq8 Bk00eDa6lFtzA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M6Db0-1orazs1YVM-006eG0; Thu, 24 Nov 2022 14:56:12 +0100 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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 07/14] tpm, tpm_tis: Move interrupt mask checks into own function Date: Thu, 24 Nov 2022 14:55:31 +0100 Message-Id: <20221124135538.31020-8-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:on5JjKFr/xjl/gz/QEuHuParjIQHmU7ELMmZZwpGlAZEBanrutQ 2DdmYrVPk4MXxqNOEjgNM1o/5202rmsWDop2c4+y1Dd+eAu6B0gEBvosJfuCbNs1QRZu+3V qP3NayH4ShRp4zVTwwcUQUUdFlefi6r2iBYNB/W19rryCjjBBk8hYlZSSFRtvztaMtg1uG0 hGWbAIvKJV3lEse9ay9ww== UI-OutboundReport: notjunk:1;M01:P0:qKA8UB9uP7o=;NJHWReHTds23j2YjqLN53o8czve pO8MMywFusnZoBq752jV++IRjLJ3npvTyinry9nqWvRaxmrIj1ZjrTkFGHztRgaFq6nIoP/Zz 8DeTgGAHaTLgr+VO+rgpBmuKQe/8kv0utfunymD9mFUhU1N6a3oul+HDqWavxCEVWie3H7wqW UvSbpL7PZEkEE1XCxGVJCzzku07N73BMxinTVZWZV/JJYPdUsfT/Mz6dRqMfFhEW9YZ/6NukL 18E0f+PRHZeQu/nkT7T2wFCo9caKtjwqQhGj5x4qZkFkuI2sowKfh/ygkS823SqAR46crAHTp VhdIVEb0w8F9naqRWqwD9wtGCJsadfQBQH4AHB2a4COnjHnxxx/Wf3V/quUzYVXf46uIXSRGW qJo8TkZ6Fhvnv+kOF7RAwG8JVCyq3C5Yc7BosykHuJrsZdPoexaLQRPRer3YGrYXp29kVaHa4 aN4Q5vHy5SmQGf5hEf/FE2kevdzxUBXBf0zdyMnLwWmuylpiQQdHkN1HZfBJveTjSRTd+DMuc fUmkKxLkiOIAambnVlznRKR8WeU6Yd9W6RsfrWKPQvSGwscWiQiWT53OGUbTZIG3SsaF60tf0 adsO+2SXenbr+g8X9O+olynu4D6kWljgjfyoc64tY0KldkoesA3PIbel7I3SsZTwp+zDfb9vR zwG4hPsyWf1d3Q2yPPtj61oQhBMlip8Tck/8cxu1f08FVXA6NnuTFZ499F5fny0/YFHxmcxCA a4DngGmbrZEcpxnGfnrff/CF2MKNxvb/8YsnXUIVtyeZ1hb+X/iFxYacOGKbq9i9nKtLdxm8y KhvcsEoCIGKfCOYQLyQACo7eGFHE0u4fdMeuK5yKGIe/nhsA3HdZSuTwUO7S9bXm4DabGxHHm 9fWkz0hojsmU0vfMjLCSrgkNfWFDc4wIStTkxskzUt0EdNzgs5qWqq4nlDb/rDEwEq2t2Jdgy dU+KeIa1xHjdKS2GFKMVIXadGKs= 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 2694b1bb77de..65d1ec7eb4c3 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 what 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 */