mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jonas Rebmann <jre@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 "open list:BAREBOX" <barebox@lists.infradead.org>
Cc: Lukas Wunner <lukas@wunner.de>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>,
	 Jonas Rebmann <jre@pengutronix.de>,
	Thorsten Blum <thorsten.blum@linux.dev>,
	 Herbert Xu <herbert@gondor.apana.org.au>
Subject: [PATCH 4/4] crypto: ecc - Streamline alloc_point and remove {alloc,free}_digits_space
Date: Mon, 18 May 2026 09:56:16 +0200	[thread overview]
Message-ID: <20260518-barebox-port-ecc-v1-4-25509bd37030@pengutronix.de> (raw)
In-Reply-To: <20260518-barebox-port-ecc-v1-0-25509bd37030@pengutronix.de>

From: Thorsten Blum <thorsten.blum@linux.dev>

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>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from linux commit c66e0a273f223fe38b8b72c034857622b0651482)
Reported-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
 crypto/ecc.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/crypto/ecc.c b/crypto/ecc.c
index a228ae1a66..b6abdbee67 100644
--- a/crypto/ecc.c
+++ b/crypto/ecc.c
@@ -1,4 +1,4 @@
-// SPDX-Comment: Origin-URL: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/crypto/ecc.c?id=b16510a530d1e6ab9683f04f8fb34f2e0f538275
+// SPDX-Comment: Origin-URL: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/crypto/ecc.c?id=d6ea871d73abbb6a1e00e71ed5762e394d06cb2b
 /*
  * Copyright (c) 2013, 2014 Kenneth MacKay. All rights reserved.
  * Copyright (c) 2019 Vitaly Chikunov <vt@altlinux.org>
@@ -78,33 +78,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;
 
@@ -113,7 +104,7 @@ struct ecc_point *ecc_alloc_point(unsigned int ndigits)
 	return p;
 
 err_alloc_y:
-	ecc_free_digits_space(p->x);
+	kfree(p->x);
 err_alloc_x:
 	kfree(p);
 	return NULL;

-- 
2.54.0.129.g3edf2eeba9




  parent reply	other threads:[~2026-05-18  8:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-18  7:56 [PATCH 0/4] crypto: Port ecc.c fixes from kernel Jonas Rebmann
2026-05-18  7:56 ` [PATCH 1/4] crypto: ecc: Add Origin-URL to document kernel revision Jonas Rebmann
2026-05-18  7:56 ` [PATCH 2/4] crypto: ecc - Fix off-by-one missing to clear most significant digit Jonas Rebmann
2026-05-18  7:56 ` [PATCH 3/4] crypto: ecdsa - Harden against integer overflows in DIV_ROUND_UP() Jonas Rebmann
2026-05-18  7:56 ` Jonas Rebmann [this message]
2026-05-18 13:25 ` [PATCH 0/4] crypto: Port ecc.c fixes from kernel Sascha Hauer

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=20260518-barebox-port-ecc-v1-4-25509bd37030@pengutronix.de \
    --to=jre@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=lukas@wunner.de \
    --cc=s.hauer@pengutronix.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