From patchwork Mon Oct 17 23:57:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009723 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 8D73FC43219 for ; Mon, 17 Oct 2022 23:58:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231208AbiJQX6X (ORCPT ); Mon, 17 Oct 2022 19:58:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231161AbiJQX6S (ORCPT ); Mon, 17 Oct 2022 19:58:18 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AD047E03A; Mon, 17 Oct 2022 16:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051072; bh=BzRmHyDjx6k9QxSMFomIGBOCh5qkOm5olPta9ZMqnS8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=j/khhM9e5wP+lpawLuxx74yOycNZXoKBT8E+6UYh2N4nvDr3jZCVR2NR0MfC9UUjW v1i1nNtrlQNm/nxRPJFFAw4ffa+MKvNCqbgebowRaQWfqu5L/Azcw3JpSRH5ZbdwJx gpFcC52q61PtXpoYj5CU0gxa04wxFgo66VzPL03c= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MFKGP-1ovHNh1Lzd-00FhEt; Tue, 18 Oct 2022 01:57:52 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 06/11] tpm, tpm_tis: Move interrupt mask checks into own function Date: Tue, 18 Oct 2022 01:57:27 +0200 Message-Id: <20221017235732.10145-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:WDob0q+nal8PS7PWDU+fKAFyHJK7IwCY8X4P/1Xsz/Pgvm8OM6r sl7h41ANDn+c6YsHCP7tPEqtOCh5M/LnOpygKNBlI/Vgg7DqrPRqmi42JeCocQncP3j+ZTs LNxp+JnMjWWWuavT/jQb2ErlHMtJhG7cbQ3X2lNDQxpMeRNULLAKqWoc0C8as7Qyps7ub1P B5QLqclCbJJZZx4EBYH6Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:gXPKTH2PjG4=:obtYWnaAhcTFSm6nRSj41U 4L0ea1LbBk+IGzYTWSIkiQ2KAWTWOeL1Mg4ds1i9Z1uVPMHNgdzgzBphJWkXeCqUU7iWC6CDQ ncACL0qaYwYuaraYtDuaApr47WWSiJdw6SxVziYLWigKZOCTXejOunP6FoBwj9NqgDdws8wmH gFujY6APnrkbsOoSEaZW7sZs6f7JqyXlry7PWbgg4f4j3dPWPutfbDo23n9bRIb/PisVF1QGk 79TfhGmOn9V6mUlzn9uo3DjyjlLtDS0+SBJeTQyl3slnzKT3wXjagtMcx0XQGE73vtVqSS8Jb C63XDNAaq2QNB0WaSLEFGRhvbEDs7om8GwQaZ3h27er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eEECHUz4IGsm24e9yvhp/at05WhTkiiIZMCf1KD67PYO9kS6H veBKYlaiDEhhtXPT2eJUoQaY0jXrawG6xnwNVnhvXF7Z9XStCw8O+qI/uJXvcoUJKUxMHxfvb yUihLO8RDuJh2HJLB6DDV+6IS7jPIPErp/s9rfgnBjpVU 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 d07debc3182c..181c291b0bb8 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 */