Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1068763imm; Fri, 22 Jun 2018 09:48:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJv0JbaDdBSCpJmRTZi9YYMyXWrICY4VsBTrxQZilH3W04+iSzYmmJFnr4CTILY5xyq6FEq X-Received: by 2002:a17:902:8210:: with SMTP id x16-v6mr2433721pln.307.1529686090692; Fri, 22 Jun 2018 09:48:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529686090; cv=none; d=google.com; s=arc-20160816; b=myC7tzo3JPs4jL50rt/bZfw4iDnqp61ygEu39Cd9LtizYSsN+iW9MAMWEvSqG3hZkL Hz1lGesvnfvJMF+65K/GHPdkqzx/F3kEScL5mcWnorIWqu5JSucpOdDHEWt3JCNoX+F6 1WExsqho5nBctR+QtWyUPXNvZTtfy/5rQn83yp3EsDL9Lrt6wjCRAM6CbDbF+AOEGDWI j2TyXEL4oWCw3uEfDnd2Wejofe8/IdJAHtutQI8fkRsn79RLAVwMeSkY1l2s+UpXLv/l WPBRtldPgVZ08ExptW1Nb2iaKw37tIdCRgM/UCfNRzivA4Ed6lCpS9JNrgM0jY8FGUTl VsaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=FkrragGhOwIP2wR7ZzbQmmQQSlvbwjZnSo19NN5rRTE=; b=IkwCn3vZwzJmjk+P859U0Gx2TXqULjPGdv7WKYj7SDu/g1xpzmvlnHZl/TdHLJgpT4 BofH7NYDNK69oD/ZWIaDC5k2U1JqxyY2wFhzeGIgOXbO1K1IaMcsKzRSuvsHQKW0S1/t Pn9WUXEUUHsvMWVljcjx9d2+LsjLDqxFmDMBzO1Ep63uu0XpULlCKsUYm8d/5YvkU4BE do4IZ+0eH+X0A3W1tkpkz0X8tq9Xjhd1303Okiqh459YRs7OcNk/1j2D3HHVc2sNa0A/ 8RqKhrJoNCzT90sHSzQKCM6tedEsGn72iVaFMZb9PT176eqQjRvGMPTgkbwbpEvtbvEx ynvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o126-v6si7654617pfo.72.2018.06.22.09.47.55; Fri, 22 Jun 2018 09:48:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934514AbeFVQq2 (ORCPT + 99 others); Fri, 22 Jun 2018 12:46:28 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:35920 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934310AbeFVQqX (ORCPT ); Fri, 22 Jun 2018 12:46:23 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w5MGi5h8045399 for ; Fri, 22 Jun 2018 12:46:23 -0400 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2js2pqx41b-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 22 Jun 2018 12:46:22 -0400 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Jun 2018 12:46:20 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 22 Jun 2018 12:46:18 -0400 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w5MGkH4g9699838 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 22 Jun 2018 16:46:17 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EB921112064; Fri, 22 Jun 2018 12:46:13 -0400 (EDT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D3130112062; Fri, 22 Jun 2018 12:46:13 -0400 (EDT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 22 Jun 2018 12:46:13 -0400 (EDT) From: Stefan Berger To: linux-integrity@vger.kernel.org, jarkko.sakkinen@linux.intel.com, zohar@linux.vnet.ibm.com Cc: jgg@ziepe.ca, linux-kernel@vger.kernel.org, Stefan Berger Subject: [PATCH v3 2/4] tpm: Implement tpm_chip_find() for other subsystems to find a TPM chip Date: Fri, 22 Jun 2018 12:46:11 -0400 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180622164613.1609313-1-stefanb@linux.vnet.ibm.com> References: <20180622164613.1609313-1-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18062216-2213-0000-0000-000002BEB7F1 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009240; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01050751; UDB=6.00538515; IPR=6.00829721; MB=3.00021808; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-22 16:46:20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18062216-2214-0000-0000-00005A92BE9A Message-Id: <20180622164613.1609313-3-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-22_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=851 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1806220186 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement tpm_chip_find() for other subsystems to find a TPM chip and get a reference to that chip. Signed-off-by: Stefan Berger --- drivers/char/tpm/tpm-chip.c | 27 +++++++++++++++++++++++++++ include/linux/tpm.h | 5 +++++ 2 files changed, 32 insertions(+) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 4e83695af068..2520555b1e17 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -81,6 +81,33 @@ void tpm_put_ops(struct tpm_chip *chip) EXPORT_SYMBOL_GPL(tpm_put_ops); /** + * tpm_chip_find() - find a TPM chip and get a reference to it + */ +struct tpm_chip *tpm_chip_find(void) +{ + struct tpm_chip *chip, *res = NULL; + int chip_num = 0; + int chip_prev; + + mutex_lock(&idr_lock); + + do { + chip_prev = chip_num; + chip = idr_get_next(&dev_nums_idr, &chip_num); + if (chip) { + get_device(&chip->dev); + res = chip; + break; + } + } while (chip_prev != chip_num); + + mutex_unlock(&idr_lock); + + return res; +} +EXPORT_SYMBOL_GPL(tpm_chip_find); + +/** * tpm_get_ops() - find and reserve a TPM chip * @chip: a &struct tpm_chip instance, %NULL for the default chip * diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 06639fb6ab85..a9c65f5670b6 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -61,6 +61,7 @@ extern int tpm_seal_trusted(struct tpm_chip *chip, extern int tpm_unseal_trusted(struct tpm_chip *chip, struct trusted_key_payload *payload, struct trusted_key_options *options); +extern struct tpm_chip *tpm_chip_find(void); #else static inline int tpm_is_tpm2(struct tpm_chip *chip) { @@ -96,5 +97,9 @@ static inline int tpm_unseal_trusted(struct tpm_chip *chip, { return -ENODEV; } +static inline struct tpm_chip *tpm_chip_find(void) +{ + return NULL; +} #endif #endif -- 2.13.6