Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp483686ybl; Fri, 24 Jan 2020 04:08:56 -0800 (PST) X-Google-Smtp-Source: APXvYqy+sva/Ej4hNdTWwRHfD7xoeLCSYD4OnLoDtCiFiU+mYTz6BHLieOXehIq/LI5LJrgPsreC X-Received: by 2002:a9d:7ccc:: with SMTP id r12mr2565296otn.22.1579867736150; Fri, 24 Jan 2020 04:08:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579867736; cv=none; d=google.com; s=arc-20160816; b=wZl2KR9FBA4w8ua/y4+bEaSIECT+uoqVlPHr77/4kImbpYQ1sfH2hFXHkx4PAM40i8 ALFdaZslZi6xejgaPgV13w4gQGkcdV973J3fozEFhlMESYDcxwF8doIhmpZTKWd41Dkh nvnH6+ptZOCb5CT2oG27fTS+CoEnINaze2q420MX1ccBmyW3+gokyHDHKrFQFSNSukrT zJeaxM0SqpEu+ZvVTIP7SroYadhczzJ0kmEQjz/Tzo+Nc4ovab1NFrGWJAa1z5ap8cTS ajos1BrKQTYhjR5/lB2Jw/jHDKMkzgg/n3T6zXZHqRfkJx7DWuCVfANKb1UhZ1qlg1j2 7Ncg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mAUtUIgtcBoXvpXPjxJVQqCXSqzkDc9re9N+4TSp4Bg=; b=By+AG8rCAGd4E5+IS7St1gMOlzv1wS7lQJRB3aDE+bYiulbNZpMcvwqw25mSmFTSQl TlPfZjYlNZEEKxdNpl/5yo+EK7HOaquyf8qg7WR2WDymxvM67Dpu7xKtq9wgXfYwYIVE Ma87NWQn0hhvJsd8kXOv0ouy1CkwpLqT/Fy77yLMEg4e7P7xeNUois5fYBhFcV9ulx45 rYG/3FPm+tTJVPclZA5TLbPt/RiWNlapOg+oFo1Z/P48m3cGSvZdEtS5sMzhxDeVq2Zk IHU9B9Ki15b75VP1KYWUX5yiplmpaaYVpHKKFq2aiq75P2TGJVkd6QPrdhcC2pUmRiwR /gvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RJr5ZxxW; 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 i6si2578334oth.182.2020.01.24.04.08.43; Fri, 24 Jan 2020 04:08:56 -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=@kernel.org header.s=default header.b=RJr5ZxxW; 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 S1733140AbgAXJmZ (ORCPT + 99 others); Fri, 24 Jan 2020 04:42:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:40100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732644AbgAXJmX (ORCPT ); Fri, 24 Jan 2020 04:42:23 -0500 Received: from localhost (unknown [145.15.244.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9D5D320718; Fri, 24 Jan 2020 09:42:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579858943; bh=1Z30YvobrovymqmVeIeZ2ZcTosiixf4aUJ3Vw5PR/R0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RJr5ZxxWOXC/xl9tfW0mAr9QJhkVeLuE1cEPsIkhK2Af2XwJXdFOEx+JeT3WlkNuM +ObaBXRTgw/lpAHKMEO4JdLlwgQjy3HCo9b8I1ff96lQ+3Lsv8IUalwzKs8Z14+olz Z0MpmuFcCo2q+/CV5xbYQw9Ta74YW/sXG8jfKPqc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sumit Garg , Jens Wiklander , Sasha Levin Subject: [PATCH 5.4 086/102] tee: optee: fix device enumeration error handling Date: Fri, 24 Jan 2020 10:31:27 +0100 Message-Id: <20200124092819.662526497@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124092806.004582306@linuxfoundation.org> References: <20200124092806.004582306@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Wiklander [ Upstream commit 03212e347f9443e524d6383c6806ac08295c1fb0 ] Prior to this patch in optee_probe() when optee_enumerate_devices() was called the struct optee was fully initialized. If optee_enumerate_devices() returns an error optee_probe() is supposed to clean up and free the struct optee completely, but will at this late stage need to call optee_remove() instead. This isn't done and thus freeing the struct optee prematurely. With this patch the call to optee_enumerate_devices() is done after optee_probe() has returned successfully and in case optee_enumerate_devices() fails everything is cleaned up with a call to optee_remove(). Fixes: c3fa24af9244 ("tee: optee: add TEE bus device enumeration support") Reviewed-by: Sumit Garg Signed-off-by: Jens Wiklander Signed-off-by: Sasha Levin --- drivers/tee/optee/core.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 1854a3db73457..b830e0a87fbac 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -643,11 +643,6 @@ static struct optee *optee_probe(struct device_node *np) if (optee->sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) pr_info("dynamic shared memory is enabled\n"); - rc = optee_enumerate_devices(); - if (rc) - goto err; - - pr_info("initialized driver\n"); return optee; err: if (optee) { @@ -702,9 +697,10 @@ static struct optee *optee_svc; static int __init optee_driver_init(void) { - struct device_node *fw_np; - struct device_node *np; - struct optee *optee; + struct device_node *fw_np = NULL; + struct device_node *np = NULL; + struct optee *optee = NULL; + int rc = 0; /* Node is supposed to be below /firmware */ fw_np = of_find_node_by_name(NULL, "firmware"); @@ -723,6 +719,14 @@ static int __init optee_driver_init(void) if (IS_ERR(optee)) return PTR_ERR(optee); + rc = optee_enumerate_devices(); + if (rc) { + optee_remove(optee); + return rc; + } + + pr_info("initialized driver\n"); + optee_svc = optee; return 0; -- 2.20.1