Received: by 10.223.164.221 with SMTP id h29csp2132166wrb; Wed, 25 Oct 2017 12:47:38 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Thsaeerk4aI0T1uRIKZa9tS0hv6R65roYPAQ557Y/4Ukj4cA7UdagGwbGXnyqaoMGrG+V4 X-Received: by 10.84.132.104 with SMTP id 95mr2533263ple.170.1508960858454; Wed, 25 Oct 2017 12:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508960858; cv=none; d=google.com; s=arc-20160816; b=uxDMBc8SsLpQ934mldUdw7N1aSzWrOUx7Dy5suRte2uV6H+087wflgBCBbZnoPRhto XZGM9mfE31uuWe0JmBWVMPuzUI5w74c4d9EClnkPnIWWH6Vgkljju3dZcnoX7zBiREaV rpmh3fKso2lLjnTkM7TjXolLJBtc8HSG5DarUK+3OZe3ZxwMR8h39x2/AB20UnH6Msc/ ELF69mkUIIejhn1hkhTIUoY4FkKYVNvwc/w7nAfTGWwJ1AG4UjyhP72wzc5xh24s/PpE E3veb4YnJaiC/8KdP0lR5/gmayLEa9mW9iFGqJhmQq5w1UCIRFsNhPV1a4ve2ZScLWbd SEOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=5MJod0vWNovL7+bHTdUx1fW+VtuMJZ6tXKixMZsGFTk=; b=nL2zJt8zGodNAcsTZ66wztM564mvpC+dNrGY/DF22ih+POeILJbOdgWZUw6g6UkO1H xkA+G/bv4JVmVSPPZZzTjCOvR+i9eTY3SXIMWjl/wLI/yhpKwXi8ssAA6Hgx12joSBL7 F5lGkBl2MUIOO+7n0bPJ3oYTuhYMEuYezTrkJa2y2zlINowI3rQwYl7zrzJoq2trs7jZ my81LdWnqh337DVPmOITZxkwCKwvsjqvNBODjwDpzAFbk84ZwN7v11UYms5BAZFWAcJ1 nHmSZoOXTU0YjJVE4Db2v63Mw5k9pw7ekT29glIWLXfCHuHt2DSHGUZommCeXJRuebv3 tKkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@obsidianresearch.com header.s=rsa1 header.b=RNhZyqUf; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u125si2246838pgc.149.2017.10.25.12.47.14; Wed, 25 Oct 2017 12:47:38 -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; dkim=pass (test mode) header.i=@obsidianresearch.com header.s=rsa1 header.b=RNhZyqUf; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751956AbdJYTqv (ORCPT + 99 others); Wed, 25 Oct 2017 15:46:51 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:46131 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751833AbdJYTqs (ORCPT ); Wed, 25 Oct 2017 15:46:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=5MJod0vWNovL7+bHTdUx1fW+VtuMJZ6tXKixMZsGFTk=; b=RNhZyqUfHN1H5RUFnty0ssUquk7rIz6pPqphexhYaqSAkMZQosIHbAMZu8C73IUlLaEKxltSHx/sWLtlbsmPJQkE5+nOBicxaI9oOp9pC2qw3QiMnSkPnpwkYHhQ0xuVGFhllcLN9Qu7xOeYmjZ2tk0e53JhdnnR5Z8xbcB1SAw=; Received: from jgg by quartz.orcorp.ca with local (Exim 4.84_2) (envelope-from ) id 1e7RdJ-0000RS-D0; Wed, 25 Oct 2017 13:46:33 -0600 Date: Wed, 25 Oct 2017 13:46:33 -0600 From: Jason Gunthorpe To: Jarkko Sakkinen Cc: PrasannaKumar Muralidharan , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, Matt Mackall , Herbert Xu , Peter Huewe , Marcel Selhorst , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , David Safford , David Howells , Jerry Snitselaar , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , open list , "moderated list:TPM DEVICE DRIVER" , "open list:INTEGRITY MEASUREMENT ARCHITECTURE (IMA)" , "open list:INTEGRITY MEASUREMENT ARCHITECTURE (IMA)" , "open list:KEYS-TRUSTED" Subject: Re: [PATCH v2] tpm: use struct tpm_chip for tpm_chip_find_get() Message-ID: <20171025194633.GB998@obsidianresearch.com> References: <20171025115508.5682-1-jarkko.sakkinen@linux.intel.com> <20171025193452.d4qa4dhacfgqejk7@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171025193452.d4qa4dhacfgqejk7@linux.intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > struct tpm_chip *tpm_chip_find_get(u64 id) > { > struct tpm_chup *chip; > struct tpm_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 && (!id || id == chip->id) && !tpm_try_get_ops(chip)) { > res = chip; > break; > } > } while (chip_prev != chip_num); > > mutex_unlock(&idr_lock); > > return res; > } ?? The old version was correct, idr_find_slowpath is better than an idr_get_next serach if you already know id. PrasannaKumar's solution seems right, if we already have chip, then we just need to lock it again: struct tpm_chip *tpm_chip_find_get(struct tpm_chip *chip) { struct tpm_chip *res = NULL; mutex_lock(&idr_lock); if (!chip) { int chip_num = 0; int chip_prev; do { chip_prev = chip_num; chip = idr_get_next(&dev_nums_idr, &chip_num); if (chip && !tpm_try_get_ops(chip)) { res = chip; break; } } while (chip_prev != chip_num); } else { if (!tpm_try_get_ops(chip)) res = chip; } mutex_unlock(&idr_lock); return res; } Jason From 1582259499724838388@xxx Wed Oct 25 19:37:26 +0000 2017 X-GM-THRID: 1582230549885813514 X-Gmail-Labels: Inbox,Category Forums