From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E869C433EF for ; Tue, 12 Oct 2021 07:34:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3D5526108F for ; Tue, 12 Oct 2021 07:34:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3D5526108F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Prn4XSPkC+7LhwO3MOhBB7hZnZMTvKLdLzKyTIH6rRw=; b=nHB3Nhx0fVUF5v e9FcT+Yq4MDyAy+WaKtnkZZr9pw6gBlnbRNXvtCGKPWD/9qRIr/6KsP6yj+imjIiGZcdh85qZY8T5 fKNvrLsVGuq6gHB6KPloOgWTjJdZC1Ia4c4meciEF+DCKdHhVpCSfzOpgpLOLCYbt2CO4jVJr7si/ PHI1WDF1VJBDFDb99k5SorD6QaRd6RRBEgcF0GkP+ZMLSZmHQgH7hn1sQEd2jo0tKioAYDOfvOx3R qbZQGnzkBWeHEj/7GM+ccRB0e4L1drpC+UN5CGPI/8D+JzBwN1OdtrmMkI6pY86V405rij5EFdC+/ lIHc2hW6E/PrAQzxi2NQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1maCG9-00BmPJ-KF; Tue, 12 Oct 2021 07:31:37 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1maCG6-00BmOb-1L for linux-arm-kernel@lists.infradead.org; Tue, 12 Oct 2021 07:31:35 +0000 Received: by mail-pf1-x432.google.com with SMTP id 187so16878885pfc.10 for ; Tue, 12 Oct 2021 00:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WKIBNSq7zcpTlIrOfspDfNxkrUhFt3Q+atkNmbPY00c=; b=lY9ss1VNWZYaDl2V7LvI9KhMrd34v1kW+F88RdrMq1iKTq3zZX5KRRwQIhZzMv+IN9 GkQ7UEMXR+jnnsJtvLvNNailmOZ/74+YTat7qmJHEs76hJsPxCJFHe7Ccn9dbPuWY44l 0stsTbQIOYxMie+3AdSsyZ4JpN+GzsITtxyoMlFPxSuCcHEfMvDERlLuPo6ii74DNQIy hmNaa0eKX/k35PzGJttIiCGazGbVQzrhYzdoA876fi3yMlEiztOP/QSH/ZbeB1t3uIe2 tGppmaSVXMqkm/WwKODNziWjjoQ4DC34ygImVuIibopPnDcouUWGmNiFzpl3UwaeVbz9 gN/A== 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:mime-version :content-transfer-encoding; bh=WKIBNSq7zcpTlIrOfspDfNxkrUhFt3Q+atkNmbPY00c=; b=1tkK5DR6SOKUKM6klVSXy1i7vOLBc1G3f0nhPrelNZQDIwPgsVcC02k41V7AYuN4PP a8bR/ZdzCZXwsw3iHNAm2/N4iyKZbPramG8zclWb3uv6pU4A1y3gjpMIvvVsSiflTb7J eY+KjpqPgbl+MN2fU1kK7Htc22r+8DZbIhQGOuMYKPx+cldnfZVEs4i+tiLM8ZHKZQUo 3YlFAW59S/ElyEWqpaLyTRIQ3sYjcNNeGpYzNLED9M8uzmk0GBTHofgG6pKNyJtj5Xmt lfuJYJlCbN7A8EuIkDjdtLuLgZG2Dww0eKYaOqTFBDJ78HKFO6eOdV8kkb2zSd0eLF14 zkUA== X-Gm-Message-State: AOAM532S3tcCpGVjTA9zlf1dPGpj1l4h8AgdmjgFNEa0ISRfc3NwZSZ7 4EM8XGjTUWBRsLCtVtcqVSV0tg== X-Google-Smtp-Source: ABdhPJzZlIS5cSGRq4AT7xeuY+T12+CRjbGYIGrv76NOr2svLmO1II5hUMIAgEYP4EsGRy6yacphHQ== X-Received: by 2002:a63:e24b:: with SMTP id y11mr21466972pgj.452.1634023891741; Tue, 12 Oct 2021 00:31:31 -0700 (PDT) Received: from localhost.localdomain ([223.178.212.208]) by smtp.gmail.com with ESMTPSA id lw14sm1927634pjb.34.2021.10.12.00.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 00:31:31 -0700 (PDT) From: Sumit Garg To: op-tee@lists.trustedfirmware.org Cc: jens.wiklander@linaro.org, sudeep.holla@arm.com, jerome@forissier.org, daniel.thompson@linaro.org, maxim.uvarov@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sumit Garg Subject: [PATCH] tee: optee: Fix missing devices unregister during optee_remove Date: Tue, 12 Oct 2021 13:01:16 +0530 Message-Id: <20211012073116.4156054-1-sumit.garg@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211012_003134_107307_D73C1F57 X-CRM114-Status: GOOD ( 14.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When OP-TEE driver is built as a module, OP-TEE client devices registered on TEE bus during probe should be unregistered during optee_remove. So implement optee_unregister_devices() accordingly. Fixes: c3fa24af9244 ("tee: optee: add TEE bus device enumeration support") Reported-by: Sudeep Holla Signed-off-by: Sumit Garg --- drivers/tee/optee/core.c | 3 +++ drivers/tee/optee/device.c | 22 ++++++++++++++++++++++ drivers/tee/optee/optee_private.h | 1 + 3 files changed, 26 insertions(+) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index ccad3c7c8f6d..3915dc574503 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -586,6 +586,9 @@ static int optee_remove(struct platform_device *pdev) { struct optee *optee = platform_get_drvdata(pdev); + /* Unregister OP-TEE specific client devices on TEE bus */ + optee_unregister_devices(); + /* * Ask OP-TEE to free all cached shared memory objects to decrease * reference counters and also avoid wild pointers in secure world diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c index ec1d24693eba..128a2d2a50a1 100644 --- a/drivers/tee/optee/device.c +++ b/drivers/tee/optee/device.c @@ -53,6 +53,13 @@ static int get_devices(struct tee_context *ctx, u32 session, return 0; } +static void optee_release_device(struct device *dev) +{ + struct tee_client_device *optee_device = to_tee_client_device(dev); + + kfree(optee_device); +} + static int optee_register_device(const uuid_t *device_uuid) { struct tee_client_device *optee_device = NULL; @@ -63,6 +70,7 @@ static int optee_register_device(const uuid_t *device_uuid) return -ENOMEM; optee_device->dev.bus = &tee_bus_type; + optee_device->dev.release = optee_release_device; if (dev_set_name(&optee_device->dev, "optee-ta-%pUb", device_uuid)) { kfree(optee_device); return -ENOMEM; @@ -154,3 +162,17 @@ int optee_enumerate_devices(u32 func) { return __optee_enumerate_devices(func); } + +static int __optee_unregister_device(struct device *dev, void *data) +{ + if (!strncmp(dev_name(dev), "optee-ta", strlen("optee-ta"))) + device_unregister(dev); + + return 0; +} + +void optee_unregister_devices(void) +{ + bus_for_each_dev(&tee_bus_type, NULL, NULL, + __optee_unregister_device); +} diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h index e25b216a14ef..39be9aa7bd22 100644 --- a/drivers/tee/optee/optee_private.h +++ b/drivers/tee/optee/optee_private.h @@ -183,6 +183,7 @@ void optee_fill_pages_list(u64 *dst, struct page **pages, int num_pages, #define PTA_CMD_GET_DEVICES 0x0 #define PTA_CMD_GET_DEVICES_SUPP 0x1 int optee_enumerate_devices(u32 func); +void optee_unregister_devices(void); /* * Small helpers -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel