Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp482883ybx; Wed, 6 Nov 2019 21:18:15 -0800 (PST) X-Google-Smtp-Source: APXvYqzbVk5vuJe7JVgxhM8j+UprBg8jjfc2n6sms1/jsSRusOlDIuyREUvhHe/vLVsF3KzVOSw8 X-Received: by 2002:a17:906:4558:: with SMTP id s24mr1285004ejq.38.1573103895758; Wed, 06 Nov 2019 21:18:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573103895; cv=none; d=google.com; s=arc-20160816; b=WFWT0lZmCoDy84J9GG58q9PpWrku2MZ3YtxROVeIMWHvfka8wNXnnXN0qRU88ATaVj jc7RIoGaLLkiiBdv2s5S1qqdlOEa/Q5e5S5ZoVVIqYxpzJxwD/aTPfUY4YlknKwuEtBI Fc8tWS8woHUBFeWskI0WGDeklDkHhXx5wFztLGUBFRBEHiwOa4x4L4T9MGdclgPyt5XD UuvPqHm4LvAFx6tgwf/6QB7IdVQvQQ3tCr5ANsgDCm69zr/TRn0AJE0jx0On9nXkGT3V UqbCLsjz7tOtGMdfmIq1AYXswYgL+FehhSR3oTPJx1NerXCWO/FhlvJsHAowxOHa/2lA ybjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=r0OOkUsjxCUYtLmAPLLgt2l0dG9hyrlf7+4skyMeXEQ=; b=dmQPlVChwWHahT3WDJUWbtCx1Bw97HrFo81EIkR9t3Lzua3QzXFgQIXyGKjHTSlp3d JjbPIpPv077A/bHUpDWW2Ejdt8zkMozoGMQDCTXEFN3/J5dXGqJ7MOEHsHdSOyDV45fV RldvyUp7HkmKqSoUT+RjvGsz1LVBnFCGeM70Z1eOulxHQDZkZnXpFwEv+e7rNNWX4xSj IjlX91AFfMQWr6nsow8S8MYGlMbaAF+kFod5QdeKFF8qhchdX/MsoCtJaW2C74H72TmD sb2+f07E6sbuPB85WBxa/gy4SyFr2ZbhnOr20SGBnH3/k5YU8SiWZKgDcMmuGMcCpzYa wWAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UE+pDLh8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 14si627526edz.130.2019.11.06.21.17.40; Wed, 06 Nov 2019 21:18:15 -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=@linaro.org header.s=google header.b=UE+pDLh8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726019AbfKGFL7 (ORCPT + 99 others); Thu, 7 Nov 2019 00:11:59 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:39368 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725870AbfKGFL7 (ORCPT ); Thu, 7 Nov 2019 00:11:59 -0500 Received: by mail-lf1-f67.google.com with SMTP id 195so532352lfj.6 for ; Wed, 06 Nov 2019 21:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=r0OOkUsjxCUYtLmAPLLgt2l0dG9hyrlf7+4skyMeXEQ=; b=UE+pDLh8LWppVS2Pe9lH+YlK3AHf7m8j4dN7vWiHUoov11X198Km89WzVDjvZT1r+8 FtXNkSCwbRu8As4nZqyQcRihyTZnUD+4nwebsA2zaJ+cOr6FaoECt82rwLPDE4JrLfD5 tsAGSiAAw+1G8xIrobZjzvXf+CCjou9KihddjOlC31oIaDqo4kY0aVoVdX6dSKiK6n8I kaZh+R4Oklqm2U+H9963U5tuUU16umTc9LD8cE6hjAjf3cHlqIO4IcXlncOQDqvaQSRp 1EHhGSkRAZCcTL/ljsKblmAWGnoTezp92VPoNA0VjsW358rluwW+VmS7ShO5aymqh3cj BstQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=r0OOkUsjxCUYtLmAPLLgt2l0dG9hyrlf7+4skyMeXEQ=; b=H/UA1tYktecfLO7vSSch3W9SPQZYD8pf+3O3tAahSk38+g268Zor4+E5ibPxmQTpdg T6vwJMVzDy0FtXTwU2X2K0SPZIcLa7TFlkG10oV6WE5tQZsETYbiLl0R3HWYPr/eQgsF 2lYb/b5t5sAMj6SSgBCbxwhIHNKqCJvqwxPtbNvR+4B/OzhJI5yzAxrnIhHwGruY8pSk d1NpEk5jDl6m/C7FLirdvsBubyrER0zC4+FAGIBpo+J94ysp/o0vx51QGoEjrcHaSfOq Jq9jcewSQY/9kZdn2C15fkKnP4ja9F2ZjtqI6LND+JEJQ780fJ/yPikTrDaG+ZtTSgOQ NEPg== X-Gm-Message-State: APjAAAVsY6UTyyi3RwlXtcEPXm3Ab/rugXj+zDcPsyALfCbXGY90Eoku 1ixMPSFRdtwrDUxW/w3Kf8L7xQqEQmrFW0gJt8XV5Q== X-Received: by 2002:ac2:561b:: with SMTP id v27mr898331lfd.186.1573103517378; Wed, 06 Nov 2019 21:11:57 -0800 (PST) MIME-Version: 1.0 References: <20191106155538.5618-1-jens.wiklander@linaro.org> In-Reply-To: <20191106155538.5618-1-jens.wiklander@linaro.org> From: Sumit Garg Date: Thu, 7 Nov 2019 10:41:46 +0530 Message-ID: Subject: Re: [PATCH] tee: optee: fix device enumeration error handling To: Jens Wiklander Cc: Linux Kernel Mailing List , linux-arm-kernel , "tee-dev @ lists . linaro . org" , Victor Chong , Jerome Forissier , Etienne Carriere Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 6 Nov 2019 at 21:25, Jens Wiklander wrote: > > 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(-) > 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; > -- > 2.17.1 >