From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Sughosh Ganu <sughosh.ganu@linaro.org>
Cc: u-boot@lists.denx.de, Heinrich Schuchardt <xypron.glpk@gmx.de>,
Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH v6 5/7] cmd: rng: Use a statically allocated array for random bytes
Date: Wed, 6 Jul 2022 16:31:46 +0300 [thread overview]
Message-ID: <YsWOwn86pmM3JD67@hera> (raw)
In-Reply-To: <20220704133444.1110715-6-sughosh.ganu@linaro.org>
On Mon, Jul 04, 2022 at 07:04:42PM +0530, Sughosh Ganu wrote:
> Use a statically allocated buffer on stack instead of using malloc for
> reading the random bytes. Using a local array is faster than
> allocating heap memory on every initiation of the command.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> ---
> Changes since V5: None
>
> cmd/rng.c | 17 +++++++----------
> 1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/cmd/rng.c b/cmd/rng.c
> index 2ddf27545f..81a23964b8 100644
> --- a/cmd/rng.c
> +++ b/cmd/rng.c
> @@ -14,9 +14,9 @@
> static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> {
> size_t n;
> - struct udevice *dev;
> - void *buf;
> + u8 buf[64];
> int devnum;
> + struct udevice *dev;
> int ret = CMD_RET_SUCCESS;
>
> switch (argc) {
> @@ -41,11 +41,10 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> return CMD_RET_FAILURE;
> }
>
> - buf = malloc(n);
> - if (!buf) {
> - printf("Out of memory\n");
> - return CMD_RET_FAILURE;
> - }
> + if (!n)
> + return 0;
> +
> + n = min(n, sizeof(buf));
>
> if (dm_rng_read(dev, buf, n)) {
> printf("Reading RNG failed\n");
> @@ -54,15 +53,13 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, n);
> }
>
> - free(buf);
> -
> return ret;
> }
>
> #ifdef CONFIG_SYS_LONGHELP
> static char rng_help_text[] =
> "[dev [n]]\n"
> - " - print n random bytes read from dev\n";
> + " - print n random bytes(max 64) read from dev\n";
> #endif
>
> U_BOOT_CMD(
> --
> 2.25.1
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
next prev parent reply other threads:[~2022-07-06 13:31 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-04 13:34 [PATCH v6 0/7] tpm: rng: Move TPM RNG functionality to driver model Sughosh Ganu
2022-07-04 13:34 ` [PATCH v6 1/7] tpm: Export the TPM-version functions Sughosh Ganu
2022-07-06 8:59 ` Ilias Apalodimas
2022-07-04 13:34 ` [PATCH v6 2/7] tpm: rng: Add driver model interface for TPM RNG device Sughosh Ganu
2022-07-05 9:47 ` Simon Glass
2022-07-05 17:23 ` Sughosh Ganu
2022-07-12 10:58 ` Simon Glass
2022-07-06 13:26 ` Ilias Apalodimas
2022-07-04 13:34 ` [PATCH v6 3/7] tpm: Add the RNG child device Sughosh Ganu
2022-07-05 9:47 ` Simon Glass
2022-07-08 8:23 ` Ilias Apalodimas
2022-07-12 10:58 ` Simon Glass
2022-07-12 14:11 ` Rob Herring
2022-07-13 15:28 ` Simon Glass
2022-07-13 18:09 ` Tom Rini
2022-07-14 10:21 ` Simon Glass
2022-07-14 11:19 ` Tom Rini
2022-07-14 14:51 ` Simon Glass
2022-07-14 15:47 ` Ilias Apalodimas
2022-07-14 16:04 ` Tom Rini
2022-07-14 17:55 ` Rob Herring
2022-07-15 15:38 ` Simon Glass
2022-07-04 13:34 ` [PATCH v6 4/7] cmd: rng: Add support for selecting RNG device Sughosh Ganu
2022-07-04 13:34 ` [PATCH v6 5/7] cmd: rng: Use a statically allocated array for random bytes Sughosh Ganu
2022-07-05 9:47 ` Simon Glass
2022-07-06 13:31 ` Ilias Apalodimas [this message]
2022-07-04 13:34 ` [PATCH v6 6/7] doc: rng: Add documentation for the rng command Sughosh Ganu
2022-07-04 13:34 ` [PATCH v6 7/7] test: rng: Add a UT testcase " Sughosh Ganu
2022-07-06 13:32 ` Ilias Apalodimas
2022-07-05 9:47 ` [PATCH v6 0/7] tpm: rng: Move TPM RNG functionality to driver model Simon Glass
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=YsWOwn86pmM3JD67@hera \
--to=ilias.apalodimas@linaro.org \
--cc=sjg@chromium.org \
--cc=sughosh.ganu@linaro.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.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