Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3031738pxb; Mon, 18 Oct 2021 06:59:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7WnxOkcTH8zog6IPK2Oxk16AfQ3aBJgG3PyXncwqynShjNvPjR+znNaPVVaSAzKBErWSq X-Received: by 2002:a17:902:c713:b0:13f:295d:803c with SMTP id p19-20020a170902c71300b0013f295d803cmr27616260plp.46.1634565553477; Mon, 18 Oct 2021 06:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634565553; cv=none; d=google.com; s=arc-20160816; b=KcxILc2Gslj5sBPi5L/h9plRDz9J1CcsmK1iQ19G/ct+8X3K9qQZLUDI6UJwqf3wbP pZkbYWiJg1W0rsl12BRqJwdc3B8POCS8Znqo4mjBcCjatKUq6vATBbxTJ/SEz+J2j74E dvalPq5sh9CDJhD4kqbIglPkFPB5gknDTTD6smV4lEye5Rszi7FRUNrJnarbJ/4vMfSk lW+QSBvAlVvRZfANJyvQDYHRt7myPD0cdM7X8fJHNNSFfdfc1Qn+10B1YYaATlW/eilH rUzb7qhR0+nWnW0dd//UjzBo+H79b9i8t2/+fHYEZXDyYFCmuupxD/DnNmcZaIKPMPYO rhwQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=I+cuCo/0/FKMls803fdZimHuxRagUD0RPNEiwQ6Ds8I=; b=hrM9ZyorfFoCVhSfA4FX0kcxKqJIt8fDjrqMNaVOF0SsHJ1x/m04RI38I7mnbQUuG/ 5gYY4lk9q7/gzIDXGFelrXBlVVA4DMVBV1KCHWrxZXNwy343pEO+4R9ZheAGhRg0kZAP ueHISxqPsINYxmqc7pbqhbCUl/zvGpkAbsQXJPFKpNXz3VotZsDbGRJhhSci2mqyMGVK 86VhaW2WsvvDNkffcmQ9uvmzBnfSFjibj1ZJN3M5ptygd2LC2KitOjlxhSDHNWvZiQKX U8bw4XTBcEPC3+aNT+as1JbMehQTg6FBxpj2tVBy1x47jjyHQwUGxASqAzUK8bsAg6gt bwsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MgR0f3K8; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g1si20581398pjl.47.2021.10.18.06.59.00; Mon, 18 Oct 2021 06:59:13 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=MgR0f3K8; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233166AbhJRN7A (ORCPT + 99 others); Mon, 18 Oct 2021 09:59:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:56732 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234212AbhJRN4f (ORCPT ); Mon, 18 Oct 2021 09:56:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4E4746141B; Mon, 18 Oct 2021 13:40:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564435; bh=X3ObWkAPaz0Q6ij8Vde/caH4aQ/NT4FzE0Y0IRNZV5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MgR0f3K8xXe0pFRKzzAVSnSpuP/7Zp/CGJZIoJTBbHcOE0CLxIa8k3tgY3zU8Sy8y PCTUQVUlLyvG0LwqQkX2fyb061SvcoCa/mTKR4ft6rN7vlnjcuCZX8eTGtDj5wu/oL 0ww/jND++ngFzmvlt45LYCTlQ7SQYtefTb94W3ig= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sudeep Holla , Sumit Garg , Jens Wiklander Subject: [PATCH 5.14 088/151] tee: optee: Fix missing devices unregister during optee_remove Date: Mon, 18 Oct 2021 15:24:27 +0200 Message-Id: <20211018132343.546471372@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132340.682786018@linuxfoundation.org> References: <20211018132340.682786018@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sumit Garg commit 7f565d0ead264329749c0da488de9c8dfa2f18ce upstream. 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 Signed-off-by: Jens Wiklander Signed-off-by: Greg Kroah-Hartman --- drivers/tee/optee/core.c | 3 +++ drivers/tee/optee/device.c | 22 ++++++++++++++++++++++ drivers/tee/optee/optee_private.h | 1 + 3 files changed, 26 insertions(+) --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -585,6 +585,9 @@ static int optee_remove(struct platform_ { 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 --- a/drivers/tee/optee/device.c +++ b/drivers/tee/optee/device.c @@ -53,6 +53,13 @@ static int get_devices(struct tee_contex 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 u 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); +} --- a/drivers/tee/optee/optee_private.h +++ b/drivers/tee/optee/optee_private.h @@ -184,6 +184,7 @@ void optee_fill_pages_list(u64 *dst, str #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