Skip to contentSkip to conversation

crypto: lib/mpi: delete unnecessary condition

PATCH In review Dan Carpenter 3 participants 3 messages Jul 4, 2024 – Jul 12, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: lib/mpi: delete unnecessary condition

We checked that "nlimbs" is non-zero in the outside if statement so delete the duplicate check here.

---
 lib/crypto/mpi/mpi-bit.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
lib/crypto/mpi/mpi-bit.c +4 -6
index 070ba784c9f1..e08fc202ea5c 100644
@@ -212,12 +212,10 @@ void mpi_rshift(MPI x, MPI a, unsigned int n)
 			return;
 		}
 
-		if (nlimbs) {
-			for (i = 0; i < x->nlimbs - nlimbs; i++)
-				x->d[i] = x->d[i+nlimbs];
-			x->d[i] = 0;
-			x->nlimbs -= nlimbs;
-		}
+		for (i = 0; i < x->nlimbs - nlimbs; i++)
+			x->d[i] = x->d[i+nlimbs];
+		x->d[i] = 0;
+		x->nlimbs -= nlimbs;
 
 		if (x->nlimbs && nbits)
 			mpihelp_rshift(x->d, x->d, x->nlimbs, nbits);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 5 lines · Dan Carpenter

We checked that "nlimbs" is non-zero in the outside if statement so delete the duplicate check here.

---

Quoted 14 lines
  lib/crypto/mpi/mpi-bit.c | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
lib/crypto/mpi/mpi-bit.c +0 -3
index 070ba784c9f1..e08fc202ea5c 100644
@@ -212,12 +212,10 @@ void mpi_rshift(MPI x, MPI a, unsigned int n)
  			return;
  		}
 
-		if (nlimbs) {
-			for (i = 0; i < x->nlimbs - nlimbs; i++)
-				x->d[i] = x->d[i+nlimbs];

lib/crypto/mpi/mpi-bit.c void mpi_rshift(MPI x, MPI a, unsigned int n) · line 221

Quoted 10 lines
lib/crypto/mpi/mpi-bit.c +4 -3
-			x->d[i] = 0;
-			x->nlimbs -= nlimbs;
-		}
+		for (i = 0; i < x->nlimbs - nlimbs; i++)
+			x->d[i] = x->d[i+nlimbs];
+		x->d[i] = 0;
+		x->nlimbs -= nlimbs;
 
  		if (x->nlimbs && nbits)
  			mpihelp_rshift(x->d, x->d, x->nlimbs, nbits);

Cheers,

Tianjia

maintainer
#2 lore raw
In reply to Dan Carpenter
Quoted 7 lines · Dan Carpenter

We checked that "nlimbs" is non-zero in the outside if statement so delete the duplicate check here.

---
 lib/crypto/mpi/mpi-bit.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

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