From patchwork Wed Nov 6 15:55:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 178722 Delivered-To: patches@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp796758ilf; Wed, 6 Nov 2019 07:55:59 -0800 (PST) X-Received: by 2002:a05:651c:303:: with SMTP id a3mr2402797ljp.55.1573055759538; Wed, 06 Nov 2019 07:55:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573055759; cv=none; d=google.com; s=arc-20160816; b=nY6ghEEnn5JH53H9mG1OqRSDVkkk5IDnawNn64Kj7eWCONBHiVFs9XkuGgPDbhN4y2 bTydiYj/FW3jlxqSBjBAhaj1PG4yq6Az09xyiqm/L41CfDtmVumCe9ICQeyiPpvE7y75 E0v4yUKDCKWSydXbXJkx6TbaS7c+Mq8kd0Q8xkfG10FeNnrX0KjzbFKn+oN7q4OgmnOE tH8qdkz7LRPMf0htwKH+o9/YF4JjSmyQy4J3iDmmZjFCw9geooOHo4Z9ZLJLQ2oyvNRF ymhHvfwKe/21a9D/sk9U3d0S8s5Aii991xZpe4jyNlD84Xh8rnnG9BSlBaXAJVcN8Tg7 fDSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=Qpl59SkxVGxYRO1y4hy9vYURdogoOxolBZEq335zpV0=; b=v+94Hz5FE5O0cUxMkkDxQGo+xWFUvgtdoXsQFtqCf2oq0FFnsKvm9Z38x9uAKCot/6 +0PHMUDtzSR6btJt75oNf/L9R7VGDr9ZkZ31+0CzU7HgD/53CcBMxEZHwaTtxjHQWNXH guth+uD9m1rtftO9X2sayOzRRrZQBTy2rpGV00vStJRxXIEXzS1KQT9wMsneHx7ejJwj VMOMSW+SXP7/j5BHdoSUEyuWPKW5xvNQbfp9ybPbN1DEdMvP9XH/+Tcc5Eb4zI3T2iBX 0fvEASoj6UHz6tXa6SHafUUymNNrN4Z+QwS6wmt3PCCpjJuIRQaiN1ZLZcdw4Ukhs4FE 3pRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=crGU2R9a; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b1sor4711975lji.47.2019.11.06.07.55.59 for (Google Transport Security); Wed, 06 Nov 2019 07:55:59 -0800 (PST) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=crGU2R9a; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Qpl59SkxVGxYRO1y4hy9vYURdogoOxolBZEq335zpV0=; b=crGU2R9aBYvgI4zzKv7bUfa+SWTkLwQp6yyPjoaL6tkbjuYf5Ky2/o4a7yo/q/UUzV MBKRcJbbSQRyYxLd6Pg0NoIVnxAi+FiKD00neMcezQYG2t5xy+BRy6DxX9ERkkQw4xjn HhcBt4EHaXif2TNLuNf5HP2YPobFp3mCibv/P6flxs4eex0tKWF7MIInNsyjx+AjG1Zs gV5B1AXA5+r95uMX6mSO+4fdyWnRzLsbRk/5WKmIOPTyXX0Q3aL29fzpyEmX0R7ePaQZ DwM7Tor8rWKV6+1QRPGX08LlbvGpfXU+vkYl2kR87IQwFOkMoDpxSmOjN0z9WAOJDAZ/ Hdxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Qpl59SkxVGxYRO1y4hy9vYURdogoOxolBZEq335zpV0=; b=eWAAj/wC+ABRP4eUC1UQPtPHC9HaQCyDiAftlewWjqtfyC7Hx8XHjDSV1i9Wq06tE2 5sMmky7k5wfPdTcGFDCa8MHYLkpw4CJfoRE22joIK0QJNdOQH2LgvsISWAk+TmOtq2Rn 0lm1W64QM1EidGTWL3lrX0TPOls9+HdWIhtYTtCWGU7dEa8AFB1Gs1noN4BYze7/8tNH 3CcADtvtSepphYeoCYLK/qQUx+s6Z95v9jPZ9Rj6zEkAKHYm0lQ917qQbvxuTyjXNDh4 8g6iVZu84fDct23FTghu6bqki3xshvU7+M8NVFdTA7QNHvgwiDpbe02khfemgikufO6K ceCQ== X-Gm-Message-State: APjAAAUbmZ5+/hA7lBOgY6pD5bsYY8mu8vpUErDXkYTyQJJ0Ui+2iRjU 2gFkJppGFcipXs994u/lbvPEql/v X-Google-Smtp-Source: APXvYqyIDCj1EArqUS/KfCY+Ed7DLtEfID0IusRmXwjbGvjfcC5kpcSMGPxpQznGRhH1feDUSsZBdQ== X-Received: by 2002:a2e:88c1:: with SMTP id a1mr2591237ljk.204.1573055758918; Wed, 06 Nov 2019 07:55:58 -0800 (PST) Return-Path: Received: from jax.urgonet (h-48-83.A175.priv.bahnhof.se. [94.254.48.83]) by smtp.gmail.com with ESMTPSA id k187sm4704895lfd.54.2019.11.06.07.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2019 07:55:58 -0800 (PST) From: Jens Wiklander To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tee-dev@lists.linaro.org Cc: Victor Chong , Jerome Forissier , Sumit Garg , Etienne Carriere , Jens Wiklander Subject: [PATCH] tee: optee: fix device enumeration error handling Date: Wed, 6 Nov 2019 16:55:38 +0100 Message-Id: <20191106155538.5618-1-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 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") Signed-off-by: Jens Wiklander --- drivers/tee/optee/core.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) -- 2.17.1 Reviewed-by: Sumit Garg diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 1854a3db7345..b830e0a87fba 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;