* [PATCH] crypto: ecc - Streamline alloc_point and remove {alloc,free}_digits_space
@ 2025-12-18 21:27 Thorsten Blum
2026-01-05 17:08 ` Stefan Berger
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-12-18 21:27 UTC (permalink / raw)
To: Lukas Wunner, Ignat Korchagin, Stefan Berger, Herbert Xu,
David S. Miller
Cc: Thorsten Blum, linux-crypto, linux-kernel
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);
err_alloc_x:
kfree(p);
return NULL;
--
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] crypto: ecc - Streamline alloc_point and remove {alloc,free}_digits_space
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
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Berger @ 2026-01-05 17:08 UTC (permalink / raw)
To: Thorsten Blum, Lukas Wunner, Ignat Korchagin, Herbert Xu,
David S. Miller
Cc: linux-crypto, linux-kernel
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;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-05 17:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).