From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Igor Opaniuk <igor.opaniuk@gmail.com>, jens.wiklander@linaro.org
Cc: u-boot@lists.denx.de, Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH v4 2/5] cmd: optee_rpmb: close tee session
Date: Thu, 4 Apr 2024 11:40:33 +0300 [thread overview]
Message-ID: <Zg5ngbQinAX6bOjM@hera> (raw)
In-Reply-To: <20240404081352.3224643-3-igor.opaniuk@gmail.com>
Hi Igor,
I was about to apply the series, but noticed neither me or Jens were cc'ed
on this. Adding Jens to the party
On Thu, Apr 04, 2024 at 10:13:49AM +0200, Igor Opaniuk wrote:
> Add calls for closing tee session after every read/write operation.
What the patch is pretty obvious, but I am missing an explanation of why
this is needed
>
> Signed-off-by: Igor Opaniuk <igor.opaniuk@gmail.com>
> ---
>
> (no changes since v1)
>
> cmd/optee_rpmb.c | 23 +++++++++++++++++------
> 1 file changed, 17 insertions(+), 6 deletions(-)
>
> diff --git a/cmd/optee_rpmb.c b/cmd/optee_rpmb.c
> index e0e44bbed04..b3cafd92410 100644
> --- a/cmd/optee_rpmb.c
> +++ b/cmd/optee_rpmb.c
> @@ -87,8 +87,10 @@ static int read_persistent_value(const char *name,
>
> rc = tee_shm_alloc(tee, name_size,
> TEE_SHM_ALLOC, &shm_name);
> - if (rc)
> - return -ENOMEM;
> + if (rc) {
> + rc = -ENOMEM;
> + goto close_session;
> + }
I don't think you need the session to be opened to allocate memory.
So instead of of doing this, why don't we just move the alloc call before
opening the session?
>
> rc = tee_shm_alloc(tee, buffer_size,
> TEE_SHM_ALLOC, &shm_buf);
> @@ -125,6 +127,9 @@ out:
> tee_shm_free(shm_buf);
> free_name:
> tee_shm_free(shm_name);
> +close_session:
> + tee_close_session(tee, session);
> + tee = NULL;
>
> return rc;
> }
> @@ -139,17 +144,20 @@ static int write_persistent_value(const char *name,
> struct tee_param param[2];
> size_t name_size = strlen(name) + 1;
>
> + if (!value_size)
> + return -EINVAL;
> +
> if (!tee) {
> if (avb_ta_open_session())
> return -ENODEV;
> }
> - if (!value_size)
> - return -EINVAL;
>
> rc = tee_shm_alloc(tee, name_size,
> TEE_SHM_ALLOC, &shm_name);
> - if (rc)
> - return -ENOMEM;
> + if (rc) {
> + rc = -ENOMEM;
> + goto close_session;
> + }
ditto
>
> rc = tee_shm_alloc(tee, value_size,
> TEE_SHM_ALLOC, &shm_buf);
> @@ -178,6 +186,9 @@ out:
> tee_shm_free(shm_buf);
> free_name:
> tee_shm_free(shm_name);
> +close_session:
> + tee_close_session(tee, session);
> + tee = NULL;
>
> return rc;
> }
> --
> 2.34.1
>
Thanks
/Ilias
next prev parent reply other threads:[~2024-04-04 8:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-04 8:13 [PATCH v4 0/5] TEE: minor cleanup Igor Opaniuk
2024-04-04 8:13 ` [PATCH v4 1/5] tee: optee: fix description in Kconfig Igor Opaniuk
2024-04-04 8:13 ` [PATCH v4 2/5] cmd: optee_rpmb: close tee session Igor Opaniuk
2024-04-04 8:40 ` Ilias Apalodimas [this message]
2024-04-04 8:53 ` Ilias Apalodimas
2024-04-04 10:18 ` Igor Opaniuk
2024-04-04 10:59 ` Ilias Apalodimas
2024-04-04 11:40 ` Igor Opaniuk
2024-04-04 11:46 ` Ilias Apalodimas
2024-04-04 10:15 ` Igor Opaniuk
2024-04-04 10:58 ` Igor Opaniuk
2024-04-04 8:13 ` [PATCH v4 3/5] cmd: optee_rpmb: build cmd for sandbox Igor Opaniuk
2024-04-04 8:13 ` [PATCH v4 4/5] test: py: add optee_rpmb tests Igor Opaniuk
2024-04-04 8:13 ` [PATCH v4 5/5] tee: remove common.h inclusion Igor Opaniuk
2024-04-04 8:28 ` Ilias Apalodimas
2024-04-04 8:20 ` [PATCH v4 0/5] TEE: minor cleanup Ilias Apalodimas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zg5ngbQinAX6bOjM@hera \
--to=ilias.apalodimas@linaro.org \
--cc=igor.opaniuk@gmail.com \
--cc=jens.wiklander@linaro.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox