From: Stefan Berger <stefanb@linux.ibm.com>
To: Thorsten Blum <thorsten.blum@linux.dev>,
Lukas Wunner <lukas@wunner.de>,
Ignat Korchagin <ignat@cloudflare.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: ecc - Streamline alloc_point and remove {alloc,free}_digits_space
Date: Mon, 5 Jan 2026 12:08:31 -0500 [thread overview]
Message-ID: <0c62719b-adef-4796-ae15-07467de478c8@linux.ibm.com> (raw)
In-Reply-To: <20251218212713.1616-2-thorsten.blum@linux.dev>
On 12/18/25 4:27 PM, Thorsten Blum wrote:
> Check 'ndigits' before allocating 'struct ecc_point' to return early if
> needed. Inline the code from and remove ecc_alloc_digits_space() and
> ecc_free_digits_space(), respectively.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> crypto/ecc.c | 27 +++++++++------------------
> 1 file changed, 9 insertions(+), 18 deletions(-)
>
> diff --git a/crypto/ecc.c b/crypto/ecc.c
> index 6cf9a945fc6c..9b8e4ba9719a 100644
> --- a/crypto/ecc.c
> +++ b/crypto/ecc.c
> @@ -90,33 +90,24 @@ void ecc_digits_from_bytes(const u8 *in, unsigned int nbytes,
> }
> EXPORT_SYMBOL(ecc_digits_from_bytes);
>
> -static u64 *ecc_alloc_digits_space(unsigned int ndigits)
> +struct ecc_point *ecc_alloc_point(unsigned int ndigits)
> {
> - size_t len = ndigits * sizeof(u64);
> + struct ecc_point *p;
> + size_t ndigits_sz;
>
> - if (!len)
> + if (!ndigits)
> return NULL;
>
> - return kmalloc(len, GFP_KERNEL);
> -}
> -
> -static void ecc_free_digits_space(u64 *space)
> -{
> - kfree_sensitive(space);
> -}
> -
> -struct ecc_point *ecc_alloc_point(unsigned int ndigits)
> -{
> - struct ecc_point *p = kmalloc(sizeof(*p), GFP_KERNEL);
> -
> + p = kmalloc(sizeof(*p), GFP_KERNEL);
> if (!p)
> return NULL;
>
> - p->x = ecc_alloc_digits_space(ndigits);
> + ndigits_sz = ndigits * sizeof(u64);
> + p->x = kmalloc(ndigits_sz, GFP_KERNEL);
> if (!p->x)
> goto err_alloc_x;
>
> - p->y = ecc_alloc_digits_space(ndigits);
> + p->y = kmalloc(ndigits_sz, GFP_KERNEL);
> if (!p->y)
> goto err_alloc_y;
>
> @@ -125,7 +116,7 @@ struct ecc_point *ecc_alloc_point(unsigned int ndigits)
> return p;
>
> err_alloc_y:
> - ecc_free_digits_space(p->x);
> + kfree_sensitive(p->x);
With no data in the buffer a kfree() should be sufficient.
> err_alloc_x:
> kfree(p);
> return NULL;
prev parent reply other threads:[~2026-01-05 17:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-18 21:27 [PATCH] crypto: ecc - Streamline alloc_point and remove {alloc,free}_digits_space Thorsten Blum
2026-01-05 17:08 ` Stefan Berger [this message]
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=0c62719b-adef-4796-ae15-07467de478c8@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=ignat@cloudflare.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=thorsten.blum@linux.dev \
/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