Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp669815pxb; Fri, 14 Jan 2022 13:38:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLvTk82DwxoYHoEUvA+Xgt/bhVK+YBX+++3e3ie3uGsdvEWbnvm8soklAhjupxmmYCA6Or X-Received: by 2002:a17:906:c441:: with SMTP id ck1mr8466600ejb.257.1642196293427; Fri, 14 Jan 2022 13:38:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642196293; cv=none; d=google.com; s=arc-20160816; b=WyZ7cKsCixZzT5ZJ3ZFC13ncxu4fV0H/Hi+2EY0FcPh0NIc+Y80PSENZK2qA7pzD2a HuEEprR+OWwRvXMkB+Ik3ydzIzG/M/s9IPWuQJzoQ2t0lacW4lZHadMoi7iuMAe3rKAk KZ2fJrMNxTxLw0S2v50F58o/yxZJJqv5WM+ldLrXT8tVh+NdUz/f6X62G7+DG9277Zx2 C6LHHE6uFtP+IcK3t4SWk2q4t5yxbWJ4qR5M82DorHJ9JZXQBg0GC8/8NCI8lVq82kkw K3qzt55xTjRbgBSAf4shT2bbPhCK+/IV9syU4uTE7TpudsIBqWDuBFdEtJoGC2Mi74wL SuqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=z+PMrt9ZoFFUyS+nI8cuBydf4l/fJgxfwN4fEj0TGMU=; b=iYnFJKR37ML0bV8Fqg+geT80paYF59W2yibZm90O8C0S/HURsX4LG/zakIsJe7gNGw f4Iu9IrlLjfWxHRJU3Gl50Y5CtzQCj2MIQhMoJeEYewD+dD2b8auV1OUBI0dtAmaLeYv E/tkf65rtPHAongrq2yMIZWu7QhBrexR+F7q4YMVzfvscmJy59uviTzvd00w92SkHoki SGa30GCEyeKKISZ1QKnRpUFd+5KqCj4B5OBt7XZHNpqe4pU4gCRzxfNhLY5P8T2frp+m 4VOvNgxs5FUKTcKsmCI0lig6KP/VTFwYAFLVH5P2d6FvrdxbnSVdq5Y+XqD9GqCYZIGW FFhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lzW8KWNo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b23si3382575ejj.81.2022.01.14.13.37.48; Fri, 14 Jan 2022 13:38:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lzW8KWNo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242334AbiANPJU (ORCPT + 99 others); Fri, 14 Jan 2022 10:09:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242228AbiANPIs (ORCPT ); Fri, 14 Jan 2022 10:08:48 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C458AC061574 for ; Fri, 14 Jan 2022 07:08:47 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id b14so12738648lff.3 for ; Fri, 14 Jan 2022 07:08:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z+PMrt9ZoFFUyS+nI8cuBydf4l/fJgxfwN4fEj0TGMU=; b=lzW8KWNoC1fqc7SLWfi4NlHlo4piN1ZDgKk2ofcWfVdLPQ2kIaUFYEvGPHI3gowT6E 13RCNdmP7OKfdix2j61FC129j/LIGiSpc5HHvQpRE47x/GEvx0QjB7Z1v2/463iz5G3O ZXZBcht1c8rYbiJHJScCXvSf1D7x/IuPbikVm6yboktWlyGKY/LVUQWDRM7GUewbPsbK F4/Yl5XhZWfofuVVACdLi5heb0iPMOrltKZjKhtDbBbM/sMUbPMZ5Js3sVPp1ufGXTg/ 8eC+ktqhOG3mi7+UqQZPyCx/lOGxJjr6RALVDKVQ1FZB2eNP3nXZDSZRM4RR8uEkzcgR Zo2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z+PMrt9ZoFFUyS+nI8cuBydf4l/fJgxfwN4fEj0TGMU=; b=DCxZT+omLDxls9SlKFXd9GCNBPrz+gxE6vTkc2GNTIUaupPynIoINsDSjRDL6DtJ+l a1dAKqRdzcjvMAC73fYfV+Cs3uNdAYO9G+IpAs0RQYjAYMCKuqg2TXBYC4GgD9xDaSsy o3DNqd5/b/rFMUh8qgpojbl38Tg+Y8BN5MJhC3Aof3etckKQVQ6Grn29XZzJ0welfVX2 zd/ErVtUDWeY1puCoJKzurk0zPZ/8lVKDxdCWWFGWV9fSWpOFv2hdmrKO2I3LSpsow6L hGSW+4VXio7VzOd1K8tYRkaNX1m5FWTYmPXPGy5ASsZmMjSmHCn7CoIRtwnpSx2YoFk2 2q3w== X-Gm-Message-State: AOAM533t3lHCpAQ0XJiD7BjiKcUrtcE6aFs0M94tBIKlIF6gdNXpYqaX qtrd6xgkQwYo/sJZupymnY4V+65zc+T+mQ== X-Received: by 2002:a2e:9bcd:: with SMTP id w13mr6721364ljj.360.1642172925879; Fri, 14 Jan 2022 07:08:45 -0800 (PST) Received: from jade.urgonet (h-94-254-48-165.A175.priv.bahnhof.se. [94.254.48.165]) by smtp.gmail.com with ESMTPSA id i31sm40517lfv.67.2022.01.14.07.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jan 2022 07:08:45 -0800 (PST) From: Jens Wiklander To: linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org Cc: Sumit Garg , Herbert Xu , Devaraj Rangasamy , Rijo Thomas , David Howells , Tyler Hicks , Jens Wiklander Subject: [PATCH v2 08/12] optee: add optee_pool_op_free_helper() Date: Fri, 14 Jan 2022 16:08:20 +0100 Message-Id: <20220114150824.3578829-9-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220114150824.3578829-1-jens.wiklander@linaro.org> References: <20220114150824.3578829-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adds a common helper function to free a tee_shm allocated using the helper function optee_pool_op_alloc_helper(). Signed-off-by: Jens Wiklander --- drivers/tee/optee/core.c | 10 ++++++++++ drivers/tee/optee/ffa_abi.c | 4 +--- drivers/tee/optee/optee_private.h | 3 +++ drivers/tee/optee/smc_abi.c | 7 +++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index f4bccb5f0e93..daf947e98d14 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -69,6 +69,16 @@ int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *shm, return rc; } +void optee_pool_op_free_helper(struct tee_shm_pool *pool, struct tee_shm *shm, + int (*shm_unregister)(struct tee_context *ctx, + struct tee_shm *shm)) +{ + if (shm_unregister) + shm_unregister(shm->ctx, shm); + free_pages((unsigned long)shm->kaddr, get_order(shm->size)); + shm->kaddr = NULL; +} + static void optee_bus_scan(struct work_struct *work) { WARN_ON(optee_enumerate_devices(PTA_CMD_GET_DEVICES_SUPP)); diff --git a/drivers/tee/optee/ffa_abi.c b/drivers/tee/optee/ffa_abi.c index 5ec484b42432..4cbc45035f92 100644 --- a/drivers/tee/optee/ffa_abi.c +++ b/drivers/tee/optee/ffa_abi.c @@ -379,9 +379,7 @@ static int pool_ffa_op_alloc(struct tee_shm_pool *pool, static void pool_ffa_op_free(struct tee_shm_pool *pool, struct tee_shm *shm) { - optee_ffa_shm_unregister(shm->ctx, shm); - free_pages((unsigned long)shm->kaddr, get_order(shm->size)); - shm->kaddr = NULL; + optee_pool_op_free_helper(pool, shm, optee_ffa_shm_unregister); } static void pool_ffa_op_destroy_pool(struct tee_shm_pool *pool) diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h index df3a483bbf46..e77765c78878 100644 --- a/drivers/tee/optee/optee_private.h +++ b/drivers/tee/optee/optee_private.h @@ -236,6 +236,9 @@ int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *shm, struct page **pages, size_t num_pages, unsigned long start)); +void optee_pool_op_free_helper(struct tee_shm_pool *pool, struct tee_shm *shm, + int (*shm_unregister)(struct tee_context *ctx, + struct tee_shm *shm)); void optee_remove_common(struct optee *optee); diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c index f2ef76451443..0b27688d1e97 100644 --- a/drivers/tee/optee/smc_abi.c +++ b/drivers/tee/optee/smc_abi.c @@ -548,10 +548,9 @@ static void pool_op_free(struct tee_shm_pool *pool, struct tee_shm *shm) { if (!(shm->flags & TEE_SHM_PRIV)) - optee_shm_unregister(shm->ctx, shm); - - free_pages((unsigned long)shm->kaddr, get_order(shm->size)); - shm->kaddr = NULL; + optee_pool_op_free_helper(pool, shm, optee_shm_unregister); + else + optee_pool_op_free_helper(pool, shm, NULL); } static void pool_op_destroy_pool(struct tee_shm_pool *pool) -- 2.31.1