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 X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80EDBC5DF61 for ; Thu, 7 Nov 2019 05:12:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4E6282166E for ; Thu, 7 Nov 2019 05:12:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UE+pDLh8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726099AbfKGFL7 (ORCPT ); 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-Google-Smtp-Source: APXvYqzrIU0XwhPrjxbqFZQJcpq5ITRWmgKpPGRWjqVw0VNKYwAzlWe/P03xiYh/AIWZx1psx8xjBIV63cxT4vEeank= 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 > 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 X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E0CCC5DF60 for ; Thu, 7 Nov 2019 05:12:07 +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 14DA02166E for ; Thu, 7 Nov 2019 05:12:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WcSC88RS"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UE+pDLh8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 14DA02166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zdt1xdZ16D5GZsUNUQfkImSarD6+gs/Wr7XqYo7I0HI=; b=WcSC88RSeZ8S+S 4mVniGnBAWwphmOsnlwsScas5vCPc0zjRIYon9cy8u6zyCXxrl/LFvhRrhyUtBjWKLhjmBLkwvKFi zPDfCL3pNro99MTlNZuxlB6Q8oQEmo3yK5d/v7ZAv/jvYxaI2WDE6F8PBR6XhwrfWtrH+BVKSQNKT CAtKJhEK+r+1/yrRYdBGMNbVH/AilOtTQlkzkO9cpofA2KmCcmcmMSBZ9NVl9yZ52ZXlUneyBPBlH MRX3pBE6FE748W5AJrS963e2imcGagcR907pX/BmO6679F/apmT8HvH5adR9At9vnzz4GsqmgUMjo 1KSLxwXRND05AFoV/7aA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSa5W-0006PB-DV; Thu, 07 Nov 2019 05:12:06 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSa5S-0006ON-Os for linux-arm-kernel@lists.infradead.org; Thu, 07 Nov 2019 05:12:04 +0000 Received: by mail-lf1-x142.google.com with SMTP id f4so531632lfk.7 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=Y6s7OVN0RwDJchOWFhYeGDfDaA43kPf2R0/oJVjrTuUD9RDIyqP2aijXZpPZGeTNtz rcsHaj3D+FC+J0j1J5sLE4Gtub4Ev7GdTCfj3uVniveheV7XS/z5+OJh4qfe3bNa3Vv6 gqx0Z9e0Wv6PsQ+OYPedSGeKVHIlX4OQjAheEfoag3YGogaaq+cZYGQZRxDNDVEJ+vN7 3Lx9dnLu4qKtA1EN/XEcKalgubpZspvazEnUu/r3ONtabqDBviNuOTpnjOXAFqI44yJ9 vpr5WilR/mQwtGSICEduZQZGzULQWhcvGEO/rQYJ2wqYUE/z8XjvFW3E/lWWSireuQ4B rZgw== X-Gm-Message-State: APjAAAV24hW9EXva3/PaR/4GroAqop1wnjZn0A4K6S5l4cSbjC5hBnDq KN9GFTX2xz5ImIv8jDFNpVjmVlDeXRHZwxD/O+3vHg== X-Google-Smtp-Source: APXvYqzrIU0XwhPrjxbqFZQJcpq5ITRWmgKpPGRWjqVw0VNKYwAzlWe/P03xiYh/AIWZx1psx8xjBIV63cxT4vEeank= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191106_211202_945607_D458CD26 X-CRM114-Status: GOOD ( 20.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jerome Forissier , Linux Kernel Mailing List , "tee-dev @ lists . linaro . org" , Victor Chong , Etienne Carriere , linux-arm-kernel Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.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 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel