From patchwork Thu Dec 14 16:06:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 10112617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2364560327 for ; Thu, 14 Dec 2017 16:07:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13D7E299EB for ; Thu, 14 Dec 2017 16:07:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0875E29AA6; Thu, 14 Dec 2017 16:07:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D0FC299EB for ; Thu, 14 Dec 2017 16:07:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753307AbdLNQHD (ORCPT ); Thu, 14 Dec 2017 11:07:03 -0500 Received: from smtp11.infineon.com ([217.10.52.105]:54471 "EHLO smtp11.infineon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752944AbdLNQHC (ORCPT ); Thu, 14 Dec 2017 11:07:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1513267624; x=1544803624; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=z+Q+nIORRNFs/eHvF9q16gyFO2VwukNoGDkOiGzmJlo=; b=pwbzuRytgMY7FpKFJdkK2reVVCcz5GOzb02SFuAr3ToaGr5IWB8fSMPS j47uvqKh7pbjG1A6QrgLPg8P4vbBtcyc/MZCTPpA7fugd+jHaOzYJ2y9h UAgy/J3kcOdARZ04nPb1e1PujH/cErWME6cUmo9IvfBWsKfniUxMYsZqI I=; X-SBRS: None Received: from unknown (HELO mucxv003.muc.infineon.com) ([172.23.11.20]) by smtp11.infineon.com with ESMTP/TLS/AES256-GCM-SHA384; 14 Dec 2017 17:06:51 +0100 Received: from MUCSE708.infineon.com (mucse708.infineon.com [172.23.7.82]) by mucxv003.muc.infineon.com (Postfix) with ESMTPS; Thu, 14 Dec 2017 17:06:49 +0100 (CET) Received: from ABGN5CG4522MQD.eu.infineon.com (172.23.8.247) by MUCSE708.infineon.com (172.23.7.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.669.32; Thu, 14 Dec 2017 17:06:47 +0100 From: Alexander Steffen To: , CC: Alexander Steffen Subject: [RFC][PATCH 1/3] tpm-chip: Move idr_replace calls to appropriate places Date: Thu, 14 Dec 2017 17:06:12 +0100 Message-ID: <20171214160614.11808-2-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.11.1.windows.1 In-Reply-To: <20171214160614.11808-1-Alexander.Steffen@infineon.com> References: <20171214160614.11808-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [172.23.8.247] X-ClientProxiedBy: MUCSE705.infineon.com (172.23.7.79) To MUCSE708.infineon.com (172.23.7.82) Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to the comments, adding/removing the chip from the list should be the first/last action in (un)register. But currently it is done in a subfunction in the middle of the process. Moving the code from the subfunctions to the appropriate places within (un)register ensures that the code matches the comments. Signed-off-by: Alexander Steffen --- drivers/char/tpm/tpm-chip.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index a114e8f..25ebe49 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -321,11 +321,6 @@ static int tpm_add_char_device(struct tpm_chip *chip) } } - /* Make the chip available. */ - mutex_lock(&idr_lock); - idr_replace(&dev_nums_idr, chip, chip->dev_num); - mutex_unlock(&idr_lock); - return rc; } @@ -333,11 +328,6 @@ static void tpm_del_char_device(struct tpm_chip *chip) { cdev_device_del(&chip->cdev, &chip->dev); - /* Make the chip unavailable. */ - mutex_lock(&idr_lock); - idr_replace(&dev_nums_idr, NULL, chip->dev_num); - mutex_unlock(&idr_lock); - /* Make the driver uncallable. */ down_write(&chip->ops_sem); if (chip->flags & TPM_CHIP_FLAG_TPM2) @@ -432,6 +422,11 @@ int tpm_chip_register(struct tpm_chip *chip) return rc; } + /* Make the chip available. */ + mutex_lock(&idr_lock); + idr_replace(&dev_nums_idr, chip, chip->dev_num); + mutex_unlock(&idr_lock); + return 0; } EXPORT_SYMBOL_GPL(tpm_chip_register); @@ -451,6 +446,11 @@ EXPORT_SYMBOL_GPL(tpm_chip_register); */ void tpm_chip_unregister(struct tpm_chip *chip) { + /* Make the chip unavailable. */ + mutex_lock(&idr_lock); + idr_replace(&dev_nums_idr, NULL, chip->dev_num); + mutex_unlock(&idr_lock); + tpm_del_legacy_sysfs(chip); tpm_bios_log_teardown(chip); if (chip->flags & TPM_CHIP_FLAG_TPM2)