Skip to contentSkip to conversation

lib/mpi: Add the return value check of kcalloc()

PATCH In review Zizhuang Deng 3 participants 3 messages Dec 30, 2021 – Jan 7, 2022 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/mpi: Add the return value check of kcalloc()

Add the return value check of kcalloc() to avoid potential NULL ptr dereference.

---
 lib/mpi/mpi-mod.c | 2 ++
 1 file changed, 2 insertions(+)
lib/mpi/mpi-mod.c +2 -0
index 47bc59edd4ff..54fcc01564d9 100644
@@ -40,6 +40,8 @@ mpi_barrett_t mpi_barrett_init(MPI m, int copy)
 
 	mpi_normalize(m);
 	ctx = kcalloc(1, sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return NULL;
 
 	if (copy) {
 		ctx->m = mpi_copy(m);
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Zizhuang Deng

Add the return value check of kcalloc() to avoid potential NULL ptr dereference.

---

Best regards,
Tianjia

Quoted 16 lines
  lib/mpi/mpi-mod.c | 2 ++
  1 file changed, 2 insertions(+)
lib/mpi/mpi-mod.c +2 -0
index 47bc59edd4ff..54fcc01564d9 100644
@@ -40,6 +40,8 @@ mpi_barrett_t mpi_barrett_init(MPI m, int copy)
 
  	mpi_normalize(m);
  	ctx = kcalloc(1, sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return NULL;
 
  	if (copy) {
  		ctx->m = mpi_copy(m);
maintainer
#2 lore raw
In reply to Zizhuang Deng
Quoted 7 lines · Zizhuang Deng

Add the return value check of kcalloc() to avoid potential NULL ptr dereference.

---
 lib/mpi/mpi-mod.c | 2 ++
 1 file changed, 2 insertions(+)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt