Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757302AbdDRB6i (ORCPT ); Mon, 17 Apr 2017 21:58:38 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36562 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755785AbdDRB6f (ORCPT ); Mon, 17 Apr 2017 21:58:35 -0400 From: Stefan Berger To: tpmdd-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org, James.Bottomley@HansenPartnership.com Cc: jgunthorpe@obsidianresearch.com, jarkko.sakkinen@linux.intel.com, linux-kernel@vger.kernel.org, Stefan Berger Subject: [PATCH] tpm: Fix reference count to main device Date: Mon, 17 Apr 2017 21:58:26 -0400 X-Mailer: git-send-email 2.5.5 X-TM-AS-GCONF: 00 x-cbid: 17041801-8235-0000-0000-00000B53D705 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006935; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000208; SDB=6.00848914; UDB=6.00419126; IPR=6.00627554; BA=6.00005292; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015073; XFM=3.00000013; UTC=2017-04-18 01:58:32 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17041801-8236-0000-0000-00003B37EE61 Message-Id: <1492480706-6928-1-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-04-18_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704180015 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1097 Lines: 30 The main device is currently not properly released due to one additional reference to the 'devs' device which is only released in case of a TPM 2. So, also get the additional reference only in case of a TPM2. Fixes: fdc915f7f719 ("tpm: expose spaces via a device link /dev/tpmrm") Signed-off-by: Stefan Berger --- drivers/char/tpm/tpm-chip.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index a321bd5..9dec9f5 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -191,9 +191,10 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, /* get extra reference on main device to hold on * behalf of devs. This holds the chip structure * while cdevs is in use. The corresponding put - * is in the tpm_devs_release + * is in the tpm_devs_release (TPM2 only) */ - get_device(&chip->dev); + if (chip->flags & TPM_CHIP_FLAG_TPM2) + get_device(&chip->dev); if (chip->dev_num == 0) chip->dev.devt = MKDEV(MISC_MAJOR, TPM_MINOR); -- 2.4.3