From patchwork Sun Nov 20 13:31: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: 13050032 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 AD645C4332F for ; Sun, 20 Nov 2022 13:32:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbiKTNc3 (ORCPT ); Sun, 20 Nov 2022 08:32:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A779D9; Sun, 20 Nov 2022 05:32:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951127; bh=qYlv/2skNZrIAGuyoSI3M0nAcicGS7Q3OukmLXnsYCU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=bINaJezFcxVr1hZkuhXGGG/2P5YvXFPExjykSf9Aq9BWFSnyc/JG0CKtSXqG0ernX 2mzba7mnHeqr+CI+MxQlACgpMiOgLUiQKiDPcvzYVKo5LmUJC8E1ZYysC3HIzOevwz yHGHpCVB/RiUHpBUL3D21AMXSsSQtRSkMpIzM/O+Hr3/9hr7/aquYtCWt27BLLdZ+2 XswO/1Nl25iqGmwI0O8jXAKJbua+gi02OGgYQRPc/9gonIcF7kEduS5t9XyQ+R7yA7 vLGfUtwqmo3pGUsebmfyl1gcrcQrLj1ezfEAurNIpdtXXURybv8BCbpjWtUODnIuDA Am3yXkp2FwWeg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mn2aD-1pO4dU02Ex-00k9Um; Sun, 20 Nov 2022 14:32:07 +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 v10 07/14] tpm, tpm_tis: Move interrupt mask checks into own function Date: Sun, 20 Nov 2022 14:31:27 +0100 Message-Id: <20221120133134.28926-8-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:pWAON8thYn0lythSLMLr5a6vn8X+rSQV7RGJf4FePhBemJDVbHJ Hewfyiy1zoHiO0PppPaKhgFHzzdJOC87VLsVk9STi0amA2vvqZY0KydBmpGEFPiv5DDM9LX Fd7tTrVkkVkDcP62zmMBR1J4jzv90OhubpvkyUnQ5jEaBXN1GJNQe3zG54pm5ksBZS0J8pr YsENuCqXjdQ1cejij1sGA== UI-OutboundReport: notjunk:1;M01:P0:8z07yEUH/Mc=;A3pki4bQWNkoOeu7W1hASW4PWAp r+JGTVzFFTA4hfnr/BNz6rB5gwW0j/zWH+SzD6VS7gA7246S4p6yh29mk6jemwuqSHqctC0rR Z3IDdr7u1ZPcUv6m+zxOJmHl46pKj1g85IPP4AKnJCR6TwqlqBFj2nHp+8tXqJBPmlaNd8CGR IJ6QdjMCaSNDiIWs3FTcP5+CCF8m1i4NYT+pig63RE0I7EWaRZ49auUxHlaJK0KAkWJvYkD/5 dxBRW0zL7wqz+Wp1JeH0v47gAnDrnW9N9ktJcnv17vnFcI3Jp81xgGKERe+mN0DBnC5yOv/yv MZ61v/wpHVl51hwWoSPTVYzhQAxtZ2dWYqZAxMcOy4dlUUCSE9a5aQFwJ/i/owt4QaLSkidCb RROsFrLFFo7AH3jbLn7G198Dk7Q0hgkUx18P0THrCqu0ajd1ZrMoATmjgSDccFpW5rwGrM5DW KUscoqZi/ZwhGMGXVbIKRvQcaB7jNbN6+AZ0m0YjBcSsnbHuwc4I9OMNQyWpiLAyPoI5y5TbB Yq26m37IruH9lOLydrMmDpT5n/grc5/4SfbBNNI01EW6IFB2pPmXoNv+qM8giVg9BBXlMuxph tQUxZrCoCqS6TFed3LcGgCmuMQQjXYpZaxMm9UWm8ZI6QVQ934DBMIt+fN5RBPCMOOmZV0iF7 +EIBMgVBExnCUiwdRXEdB1svC9cwz0WJeuc1pgZsNNqTCkmx2Lq0XBHxWbaqoijPOC4CL47t7 ZA2576RoFBqrmub9VI1ZzCnLEJVJvrdy+DJOY7ys5sHNom6HeXQhB18WttHi3z78pBOnIf8iv Rz/+Sq6Mo+lCQZGF50TzGpZknmc3oVKTIHFGLXkEgkbTTo1So8cNZWtAHKAo596cqoiFmJ68V /GzG3GLcBXw4wvPlyFsVaKMuGgjFPTTHcmK9l3GmyCpdLVHMfmLXx6UAvGkZn+pq7IqlcYgjR 6kVPQg== 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 fbad92b18788..5ff4ca5fb936 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 */