Received: by 10.223.185.116 with SMTP id b49csp153504wrg; Thu, 22 Feb 2018 18:46:50 -0800 (PST) X-Google-Smtp-Source: AH8x227eKF0oPQnVSIlulx8gQjHCNThkBtGxsECpHmHt4MjdDgalkSmi/LN5if9sVQ4iqG8Svso1 X-Received: by 2002:a17:902:d20a:: with SMTP id t10-v6mr184103ply.257.1519354010300; Thu, 22 Feb 2018 18:46:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519354010; cv=none; d=google.com; s=arc-20160816; b=SQqyVMTTZ1EjYt5XApc+zGiC1uanerQ4pd2Wu5T1ShZYXkIXA/lrnAihyFYRFNJzUk 6VOpOMKR+xv/Ycl4n/ePFmser0V0b2GoPn9N9vjjAsHj03cig05WiBg4L4Dm8M7ORFUa l2uJqObBbQ3tp7lYABglMasoWFAQani+7UjeN4hBkT7RrF+QfeaaNDAeQ0PcHUxnDkX8 FFbmiMpRjadJCcimzYdmcGCWZBKUGu/3l2rEIO/nRsT/b0qsPvJ3TnlS+mCS+k3XnBBM gO/U8Kwlr2mSRYVd36+2xfh7WbF0J9CS70+twsFrdXT/0t/Hi3k5FmUN05RG8bfTpfyY 7w4w== 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=sLmisZiLcg74Nmk2hskkQWkziE+YqrEaTri8udvrLvE=; b=RkwPvEXclTHGYEO/yuWeNtLxuvBTLw2B93kFmBrSbemQcwkwjge5MjH6MwFL01cFCt igFHbopYI4PBYMWZhfarz4c8JyK0lYgRtRn7C7Frc9CAaTKsOMkktWYgE1km/0tZ7HF6 uRRUa30D0T7RBImXKxkV2dEiARmZ3+kpZPxAje2wpFWe7lWiCdY7gC9NmTkPE2o/cUBv SeEYskjNoT5ge4G+00pGWjz+ird+ncv+Br6Sj0C5QU/3BKMi+5Nx5i+utc4I+g9lOrmI yoosNn0aMWSA9T0JJTK08HzNoy35aPQm80fuXuR87PHeOyPjRXVF/tu/sj2SLqvJFDF0 tjvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RCq1wgJd; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y73-v6si1020756plh.49.2018.02.22.18.46.35; Thu, 22 Feb 2018 18:46:50 -0800 (PST) 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 header.i=@gmail.com header.s=20161025 header.b=RCq1wgJd; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751411AbeBWCpz (ORCPT + 99 others); Thu, 22 Feb 2018 21:45:55 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:39422 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751252AbeBWCpy (ORCPT ); Thu, 22 Feb 2018 21:45:54 -0500 Received: by mail-pl0-f68.google.com with SMTP id s13so4091445plq.6 for ; Thu, 22 Feb 2018 18:45:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=sLmisZiLcg74Nmk2hskkQWkziE+YqrEaTri8udvrLvE=; b=RCq1wgJdC/2ji7JjJl9VWm+y2H4IFbbCnbMAXa/8o4P+1fPaQ3MoqpDg44inrzdiSE bwW1QEjemMQCRLW1jSsFbN1e/x0D/2jbn7iZ4O/Eh3LHtFFTf9a6JnStgguSn9T1pRpO 6HX5Aa8MP1kWbP8wJa/+OJthNJ9rp1dOxNTyXElmzKx6/01+qPNswOR/1HJ2RwS7a3kI 9UnBFC0pdA+niKMjmNk6ItcAa4px3VDhfpTTDu2vRVIPIhUjhJ6yPVsZo5sjL/LoDH83 N6m32KlEAPA2YmiDkR2eqlQh7hvXc+M1zlZdMfXjH+H/2K/J9xL3W1NW6eXzc4pqsThp aLRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=sLmisZiLcg74Nmk2hskkQWkziE+YqrEaTri8udvrLvE=; b=LvkvORzOX/i8eN7jVBdlrx1knB25yTi/sfy6+92IsMWf8hxQ1ylicvJ8tsxky+WflB 3YLm31UKlAOIXLPXN0QunXaFFGGKUqKeAx86SNvNuN6xZMTzPpach0oLQ/56vY65yM8x NK5Ot0X9rNqjLUC3cShM6EoA3llECD/99xi3RYQBA+OajfXktIdcM9qCbAuovIiO2uLz MmvEP2aA595kat7sXdjXz4wMeHT/LDHMS4i6pd9a3iPeak8ljP7XanoTn5SHY/6rgGx1 AtUMBuAdKgHbm6l/wYOBb8k4nqB3JJQ0Sa2xjFA9aMZVjzhUHbokXbXUJq10XWEZ4ou2 +hUA== X-Gm-Message-State: APf1xPCxHPMSWFp8mD+YCbeGWlj3gWiSUFjncR43l9hstKeJ1BI/HwOl 8rmZ6gJq1j9Kwe8jNtx024Y= X-Received: by 2002:a17:902:8215:: with SMTP id x21-v6mr211830pln.164.1519353953923; Thu, 22 Feb 2018 18:45:53 -0800 (PST) Received: from shlinux2 (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.googlemail.com with ESMTPSA id y124sm1817809pgb.29.2018.02.22.18.45.50 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 22 Feb 2018 18:45:52 -0800 (PST) Date: Fri, 23 Feb 2018 10:43:20 +0800 From: Peng Fan To: Peng Fan Cc: jens.wiklander@linaro.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: Re: [PATCH] tee: correct max value for id allocation Message-ID: <20180223024320.GA321@shlinux2> References: <20180115092735.20969-1-peng.fan@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180115092735.20969-1-peng.fan@nxp.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jens, Any comments on this patch? Thanks, Peng On Mon, Jan 15, 2018 at 05:27:35PM +0800, Peng Fan wrote: >The privileged dev id range is [TEE_NUM_DEVICES / 2, TEE_NUM_DEVICES). >The non-privileged dev id range is [0, TEE_NUM_DEVICES / 2). > >So when finding a slot for them, need to use different max value. > >Signed-off-by: Peng Fan >Cc: Jens Wiklander >--- > drivers/tee/tee_core.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > >diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c >index 3d49ac2e3c84..d1f4ecdbc8cc 100644 >--- a/drivers/tee/tee_core.c >+++ b/drivers/tee/tee_core.c >@@ -701,7 +701,7 @@ struct tee_device *tee_device_alloc(const struct tee_desc *teedesc, > { > struct tee_device *teedev; > void *ret; >- int rc; >+ int rc, max_id; > int offs = 0; > > if (!teedesc || !teedesc->name || !teedesc->ops || >@@ -715,16 +715,20 @@ struct tee_device *tee_device_alloc(const struct tee_desc *teedesc, > goto err; > } > >- if (teedesc->flags & TEE_DESC_PRIVILEGED) >+ max_id = TEE_NUM_DEVICES / 2; >+ >+ if (teedesc->flags & TEE_DESC_PRIVILEGED) { > offs = TEE_NUM_DEVICES / 2; >+ max_id = TEE_NUM_DEVICES; >+ } > > spin_lock(&driver_lock); >- teedev->id = find_next_zero_bit(dev_mask, TEE_NUM_DEVICES, offs); >- if (teedev->id < TEE_NUM_DEVICES) >+ teedev->id = find_next_zero_bit(dev_mask, max_id, offs); >+ if (teedev->id < max_id) > set_bit(teedev->id, dev_mask); > spin_unlock(&driver_lock); > >- if (teedev->id >= TEE_NUM_DEVICES) { >+ if (teedev->id >= max_id) { > ret = ERR_PTR(-ENOMEM); > goto err; > } >-- >2.14.1 > --