All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/mpi: use swap() to make code cleaner
@ 2021-11-18  6:16 cgel.zte
  0 siblings, 0 replies; 2+ messages in thread
From: cgel.zte @ 2021-11-18  6:16 UTC (permalink / raw)
  To: linux-kernel; +Cc: yao.jing2, Zeal Robot

From: Yao Jing <yao.jing2@zte.com.cn>

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
opencoding it.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Yao Jing <yao.jing2@zte.com.cn>
---
 lib/mpi/ec.c      | 6 ++----
 lib/mpi/mpi-pow.c | 9 ++-------
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/lib/mpi/ec.c b/lib/mpi/ec.c
index 40f5908e57a4..a2f5694425ee 100644
--- a/lib/mpi/ec.c
+++ b/lib/mpi/ec.c
@@ -1282,14 +1282,12 @@ void mpi_ec_mul_point(MPI_POINT result,
 		sum = &p2_;
 
 		for (j = nbits-1; j >= 0; j--) {
-			MPI_POINT t;
-
 			sw = mpi_test_bit(scalar, j);
 			point_swap_cond(q1, q2, sw, ctx);
 			montgomery_ladder(prd, sum, q1, q2, point->x, ctx);
 			point_swap_cond(prd, sum, sw, ctx);
-			t = q1;  q1 = prd;  prd = t;
-			t = q2;  q2 = sum;  sum = t;
+			swap(q1, prd);
+			swap(q2, sum);
 		}
 
 		mpi_clear(result->y);
diff --git a/lib/mpi/mpi-pow.c b/lib/mpi/mpi-pow.c
index 2fd7a46d55ec..67fbd4c2503d 100644
--- a/lib/mpi/mpi-pow.c
+++ b/lib/mpi/mpi-pow.c
@@ -176,7 +176,6 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)
 
 		for (;;) {
 			while (c) {
-				mpi_ptr_t tp;
 				mpi_size_t xsize;
 
 				/*if (mpihelp_mul_n(xp, rp, rp, rsize) < 0) goto enomem */
@@ -207,9 +206,7 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)
 					xsize = msize;
 				}
 
-				tp = rp;
-				rp = xp;
-				xp = tp;
+				swap(rp, xp);
 				rsize = xsize;
 
 				if ((mpi_limb_signed_t) e < 0) {
@@ -235,9 +232,7 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)
 						xsize = msize;
 					}
 
-					tp = rp;
-					rp = xp;
-					xp = tp;
+					swap(rp, xp);
 					rsize = xsize;
 				}
 				e <<= 1;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] lib/mpi: use swap() to make code cleaner
@ 2021-10-28  0:33 Yang Guang
  0 siblings, 0 replies; 2+ messages in thread
From: Yang Guang @ 2021-10-28  0:33 UTC (permalink / raw)
  Cc: Yang Guang, Zeal Robot, linux-kernel

Using swap() make it more readable.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
---
 lib/mpi/ec.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/mpi/ec.c b/lib/mpi/ec.c
index 40f5908e57a4..a2f5694425ee 100644
--- a/lib/mpi/ec.c
+++ b/lib/mpi/ec.c
@@ -1282,14 +1282,12 @@ void mpi_ec_mul_point(MPI_POINT result,
 		sum = &p2_;
 
 		for (j = nbits-1; j >= 0; j--) {
-			MPI_POINT t;
-
 			sw = mpi_test_bit(scalar, j);
 			point_swap_cond(q1, q2, sw, ctx);
 			montgomery_ladder(prd, sum, q1, q2, point->x, ctx);
 			point_swap_cond(prd, sum, sw, ctx);
-			t = q1;  q1 = prd;  prd = t;
-			t = q2;  q2 = sum;  sum = t;
+			swap(q1, prd);
+			swap(q2, sum);
 		}
 
 		mpi_clear(result->y);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-18  6:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18  6:16 [PATCH] lib/mpi: use swap() to make code cleaner cgel.zte
  -- strict thread matches above, loose matches on Subject: below --
2021-10-28  0:33 Yang Guang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.