From patchwork Tue Jul 4 13:56:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 784004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x25T61V9fz9t2P for ; Wed, 5 Jul 2017 00:08:42 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sourceforge.net header.i=@sourceforge.net header.b="X0YvJYas"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sf.net header.i=@sf.net header.b="hKmaQc4Q"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=infineon.com header.i=@infineon.com header.b="OGXv1Yd4"; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dSOVI-0007lR-Rr; Tue, 04 Jul 2017 14:08:36 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dSOVH-0007lM-80 for tpmdd-devel@lists.sourceforge.net; Tue, 04 Jul 2017 14:08:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=WCkDinf0lAM6r1FS+TgAIp1dNfOlnxrX8n4sK47t+as=; b=X0YvJYasduyyavxnWwzJLxyy4bOAk/8q1gyPngIiKWUolcqQDp1Ie40WMfV1+NDtmOVwaNAk7PkKwD2Ec/nxoo4q1scDyGLvB+/v22L1ww9K2qzyv6Aci3redUvVv1vSKokeWQYtFJN7WpDNf1YtWiNWGQg8DM7LPPuCPusq1+4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=WCkDinf0lAM6r1FS+TgAIp1dNfOlnxrX8n4sK47t+as=; b=hKmaQc4QnfuMZsAbkWKl4M200FcekW3z9qzzAD87PwnVrPQyNMP+xPpakVvId4iOFbrWiDoaE2JcOwnlGwkS0FciAdCzcrXR4DyOa17MS3arQSanSHHoJ7kYRdqbASeua00Fqwx8i89DcS8vqj3sHYtJasY40CWvxDnz5V/Z28g=; Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of infineon.com designates 217.10.52.18 as permitted sender) client-ip=217.10.52.18; envelope-from=alexander.steffen@infineon.com; helo=smtp2.infineon.com; Received: from smtp2.infineon.com ([217.10.52.18]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1dSOVG-0005TG-7f for tpmdd-devel@lists.sourceforge.net; Tue, 04 Jul 2017 14:08:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1499177314; x=1530713314; h=from:to:cc:subject:date:message-id:mime-version; bh=khWuhRc3yeYnUkGAqbJNYxvYFM1cI1KZbe9Pu4bP12A=; b=OGXv1Yd4284VNG4EZhEoXyYSBwYrxJLCd6QHn+BigKU49WToFD82dylk JetFgIcCvsxDh1/3QIBKKhFVHb7fGSztO56fUCe2Qdqud0Lor5j1GcKbj tmLIl1e2e0Ecp0yFCwffvJ3tMPlmUTYXgHIAdFGFNjD2OoC/7VPmfkYxW 8=; X-SBRS: None Received: from unknown (HELO mucxv001.muc.infineon.com) ([172.23.11.16]) by smtp2.infineon.com with ESMTP/TLS/AES256-GCM-SHA384; 04 Jul 2017 15:56:58 +0200 Received: from MUCSE608.infineon.com (unknown [172.23.7.109]) by mucxv001.muc.infineon.com (Postfix) with ESMTPS for ; Tue, 4 Jul 2017 15:56:58 +0200 (CEST) Received: from MUCSE603.infineon.com (172.23.7.104) by MUCSE608.infineon.com (172.23.7.109) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Tue, 4 Jul 2017 15:56:58 +0200 Received: from ABGN5CG4522MQD.eu.infineon.com (172.29.170.97) by MUCSE603.infineon.com (172.23.7.104) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Tue, 4 Jul 2017 15:56:57 +0200 From: Alexander Steffen To: Date: Tue, 4 Jul 2017 15:56:46 +0200 Message-ID: <20170704135648.7360-1-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.11.1.windows.1 MIME-Version: 1.0 X-Originating-IP: [172.29.170.97] X-ClientProxiedBy: MUCSE601.infineon.com (172.23.7.102) To MUCSE603.infineon.com (172.23.7.104) X-Spam-Score: -1.6 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1dSOVG-0005TG-7f Subject: [tpmdd-devel] [PATCH 1/3] tpm-chip: Move idr_replace calls to appropriate places X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces@lists.sourceforge.net 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 67ec9d3..a353b7a 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -327,11 +327,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; } @@ -339,11 +334,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) @@ -438,6 +428,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); @@ -457,6 +452,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)