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 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F349C43334 for ; Wed, 6 Jul 2022 13:31:57 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2EF2184549; Wed, 6 Jul 2022 15:31:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="rIK4G+3R"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BAFA68454B; Wed, 6 Jul 2022 15:31:52 +0200 (CEST) Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 53DCE84531 for ; Wed, 6 Jul 2022 15:31:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x32c.google.com with SMTP id be14-20020a05600c1e8e00b003a04a458c54so8982682wmb.3 for ; Wed, 06 Jul 2022 06:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=xOyE2TB6dmCKQcagfH5ZHOp00qZJPevh4NTqwwjN50s=; b=rIK4G+3R9FMYlbMdilivx7/8JvjIpuy6UVhgKVAPSqI4JY7azSkKyWsF2Mkmf94cBS OaizUy6naAMTJiyzJ9VQAwU5mmkAjbDpIbOh+iLOVDF58Ft1XUKtcm1pAHdonc5XdQf+ C1UymRdMITPiNhtq6m1rLJmId05JSXyUzVRDsmXy0J1rUIxn+qQpIMpWaU0UbjDLvQTn IArcoN09F3ik0nqg3jSPIXDbGHIeN2aaKPomjJwnM5ZqHow2YX8XFkJAugQxFGyy/WNL zk8WmMjFy2EyBbQ/3nFA6CYC8W4aYM6etn6UMvKZm3JfIU96tq9yLyXyNlEQdaK28gMn fPkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=xOyE2TB6dmCKQcagfH5ZHOp00qZJPevh4NTqwwjN50s=; b=iCfh8yibxZPKW5n4mILz0z/nA0dX2coZW9ZezPfyj0p1TSAmzlgxAp7rCkDPsEgIoM 30v7QwlMJmkcrSRTsInJH7WES4FBFqRYqa0vDAVuyBeYa5F3uA7LptsiX9c5IOcT0lQ8 zjkPYi+N5rfXmgo9a5vjcvFP3PyOKclTFJ5+a9tpTTcFsSsO5PWzbvL9pyThf3gj38Fe U7DFW/k8TWrB6uw3MJuxPBpXp3e1WQMLl2RcGiCnjYzTYrKG9z2gl30hD5I2OJukSDmc 4OQbJslSq7ob6dp7BiqCGoMxnYPwRDMysK7T9kYL7mzgRRpL0fbU4xW03Sa9ZtygastW Lx0Q== X-Gm-Message-State: AJIora/VbCUmALekDohL3jLDdVDyztxTllEhEuhl6987pHp1aQaqeKXg Ny4hT2O/KTAeZp+dkvRRH698SQ== X-Google-Smtp-Source: AGRyM1vo+w7WoFAAvMfoe67dYz3wV1s6l5ckUyYFv4s3tPU3tAeu9Lvp+IKF9fyKAsYiiBj0lyM/vw== X-Received: by 2002:a7b:ce04:0:b0:3a1:92e0:d889 with SMTP id m4-20020a7bce04000000b003a192e0d889mr25237789wmc.131.1657114309845; Wed, 06 Jul 2022 06:31:49 -0700 (PDT) Received: from hera ([46.103.15.185]) by smtp.gmail.com with ESMTPSA id bg39-20020a05600c3ca700b003a18de85a64sm18194591wmb.24.2022.07.06.06.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 06:31:49 -0700 (PDT) Date: Wed, 6 Jul 2022 16:31:46 +0300 From: Ilias Apalodimas To: Sughosh Ganu Cc: u-boot@lists.denx.de, Heinrich Schuchardt , Simon Glass , Tom Rini Subject: Re: [PATCH v6 5/7] cmd: rng: Use a statically allocated array for random bytes Message-ID: References: <20220704133444.1110715-1-sughosh.ganu@linaro.org> <20220704133444.1110715-6-sughosh.ganu@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220704133444.1110715-6-sughosh.ganu@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean 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 > --- > 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