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: 25539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3410586wrr; Thu, 24 Nov 2022 05:57:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf62HMApBsrH8CZJS9z040pYoAusnTeKgWCCsyjP7tZM6gGg7WwGoPsYiatNcbtrU/wKtrlS X-Received: by 2002:a17:906:b794:b0:7ae:6450:c620 with SMTP id dt20-20020a170906b79400b007ae6450c620mr11448398ejb.270.1669298246659; Thu, 24 Nov 2022 05:57:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298246; cv=none; d=google.com; s=arc-20160816; b=MS4ngnDFWOTtbllcF3SN01ichCUI4Xmyvny3ZP0woezyBZAZyIJUx9lWLCxzybM17V gOh97JQhYRG4dqjV+RzOOQzXZUbM/DGKIq69C9u2iGLEhtDGSMcC9X2lCz1+9WAcB0UC euZH6BilkSfuIeDPf0xYrV3dd4dGIF/upNE3Cye48NyPjpaI1lwP6mOho2iKc9QSCGWB 2ch3bulri6hi4b0Um92qvbQaDzYh65btEdBos2/1uv0SUDKlF96URhVVBEHEl+VTJwG/ RwilS4vmPmGu7BJsQSPmWfESDlhxJkdNBYQmlPccsQUxyXBtt38DwKdZelhfYfFkWcti UZnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=acaYZLOzjstSk1ewiw/25/8EH4h8E4f6Mhp7/e/Rz5w=; b=gdp5NEsVN5BvrPbOyzf5E72tCz0Ek8fE84WJQCles+PfJfa+lDhTOi1uQy7Xqg5vsw knSBdsEGuJx3/UG3wRoPboEDCSaH1FvhAU/nhgSAvtyVGUEH0gpwseOAU2hhXGDHpKaz zorVBofhT86nI7YgDkQO54tesjg8Ft2yQgF0bsm3/tVmPNfKKDn1bN7toxoL5dT9o+un qPV2Gl0nzPsWMY/csnx47FxXAP6VaSygJPK4O4787E2C9ciTHxtDksSRslEzzJKkKAXq dsx/Koei0UqyqfT+Bxbj3SN6jpdc+E7Qt+1RT1gr+mdAabmUPTSuHZ6keSQF7eLElMnN rVXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=OaCBfR5N; 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=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga27-20020a1709070c1b00b007ade20fc40csi1020816ejc.810.2022.11.24.05.57.02; Thu, 24 Nov 2022 05:57:26 -0800 (PST) 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=@gmx.de header.s=s31663417 header.b=OaCBfR5N; 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=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230153AbiKXN4k (ORCPT + 99 others); Thu, 24 Nov 2022 08:56:40 -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= X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MIME_BASE64_TEXT, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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?1750386078044488616?= X-GMAIL-MSGID: =?utf-8?q?1750386078044488616?= 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 */