mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] lib/bch:using swap() instead of tmp variable
@ 2021-11-09  6:32 Yihao Han
  2021-11-10 11:32 ` kernel test robot
  0 siblings, 1 reply; 3+ messages in thread
From: Yihao Han @ 2021-11-09  6:32 UTC (permalink / raw)
  To: Yihao Han, Randy Dunlap, Andrew Morton, Bhaskar Chowdhury, linux-kernel
  Cc: kernel

swap() was used instead of the tmp variable to swap values

Signed-off-by: Yihao Han <hanyihao@vivo.com>
---
 lib/bch.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/lib/bch.c b/lib/bch.c
index c8095f30f254..1c4ddb2d845c 100644
--- a/lib/bch.c
+++ b/lib/bch.c
@@ -500,7 +500,7 @@ static int solve_linear_system(struct bch_control *bch, unsigned int *rows,
 			       unsigned int *sol, int nsol)
 {
 	const int m = GF_M(bch);
-	unsigned int tmp, mask;
+	unsigned int mask;
 	int rem, c, r, p, k, param[BCH_MAX_M];
 
 	k = 0;
@@ -514,9 +514,7 @@ static int solve_linear_system(struct bch_control *bch, unsigned int *rows,
 		for (r = p; r < m; r++) {
 			if (rows[r] & mask) {
 				if (r != p) {
-					tmp = rows[r];
-					rows[r] = rows[p];
-					rows[p] = tmp;
+					swap(rows[r], rows[p]);
 				}
 				rem = r+1;
 				break;
@@ -833,21 +831,15 @@ static void gf_poly_div(struct bch_control *bch, struct gf_poly *a,
 static struct gf_poly *gf_poly_gcd(struct bch_control *bch, struct gf_poly *a,
 				   struct gf_poly *b)
 {
-	struct gf_poly *tmp;
-
 	dbg("gcd(%s,%s)=", gf_poly_str(a), gf_poly_str(b));
 
 	if (a->deg < b->deg) {
-		tmp = b;
-		b = a;
-		a = tmp;
+		swap(b, a);
 	}
 
 	while (b->deg > 0) {
 		gf_poly_mod(bch, a, b, NULL);
-		tmp = b;
-		b = a;
-		a = tmp;
+		swap(b, a);
 	}
 
 	dbg("%s\n", gf_poly_str(a));
-- 
2.17.1


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

* Re: [PATCH] lib/bch:using swap() instead of tmp variable
  2021-11-09  6:32 [PATCH] lib/bch:using swap() instead of tmp variable Yihao Han
@ 2021-11-10 11:32 ` kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2021-11-10 11:32 UTC (permalink / raw)
  To: Yihao Han, Randy Dunlap, Andrew Morton, Bhaskar Chowdhury, linux-kernel
  Cc: kbuild-all, Linux Memory Management List, kernel

[-- Attachment #1: Type: text/plain, Size: 6956 bytes --]

Hi Yihao,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.15 next-20211110]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Yihao-Han/lib-bch-using-swap-instead-of-tmp-variable/20211109-143502
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git d2f38a3c6507b2520101f9a3807ed98f1bdc545a
config: arc-allyesconfig (attached as .config)
compiler: arceb-elf-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/67120a42a5dc4e4a08d998ae4dc41d9bf31946b5
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Yihao-Han/lib-bch-using-swap-instead-of-tmp-variable/20211109-143502
        git checkout 67120a42a5dc4e4a08d998ae4dc41d9bf31946b5
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   lib/bch.c: In function 'solve_linear_system':
>> lib/bch.c:525:25: error: 'tmp' undeclared (first use in this function); did you mean 'tm'?
     525 |                         tmp = rows[p];
         |                         ^~~
         |                         tm
   lib/bch.c:525:25: note: each undeclared identifier is reported only once for each function it appears in


vim +525 lib/bch.c

437aa565e265677 Ivan Djelic 2011-03-11  494  
437aa565e265677 Ivan Djelic 2011-03-11  495  /*
437aa565e265677 Ivan Djelic 2011-03-11  496   * solve a m x m linear system in GF(2) with an expected number of solutions,
437aa565e265677 Ivan Djelic 2011-03-11  497   * and return the number of found solutions
437aa565e265677 Ivan Djelic 2011-03-11  498   */
437aa565e265677 Ivan Djelic 2011-03-11  499  static int solve_linear_system(struct bch_control *bch, unsigned int *rows,
437aa565e265677 Ivan Djelic 2011-03-11  500  			       unsigned int *sol, int nsol)
437aa565e265677 Ivan Djelic 2011-03-11  501  {
437aa565e265677 Ivan Djelic 2011-03-11  502  	const int m = GF_M(bch);
67120a42a5dc4e4 Yihao Han   2021-11-08  503  	unsigned int mask;
02361bc7788852f Kees Cook   2018-05-31  504  	int rem, c, r, p, k, param[BCH_MAX_M];
437aa565e265677 Ivan Djelic 2011-03-11  505  
437aa565e265677 Ivan Djelic 2011-03-11  506  	k = 0;
437aa565e265677 Ivan Djelic 2011-03-11  507  	mask = 1 << m;
437aa565e265677 Ivan Djelic 2011-03-11  508  
437aa565e265677 Ivan Djelic 2011-03-11  509  	/* Gaussian elimination */
437aa565e265677 Ivan Djelic 2011-03-11  510  	for (c = 0; c < m; c++) {
437aa565e265677 Ivan Djelic 2011-03-11  511  		rem = 0;
437aa565e265677 Ivan Djelic 2011-03-11  512  		p = c-k;
437aa565e265677 Ivan Djelic 2011-03-11  513  		/* find suitable row for elimination */
437aa565e265677 Ivan Djelic 2011-03-11  514  		for (r = p; r < m; r++) {
437aa565e265677 Ivan Djelic 2011-03-11  515  			if (rows[r] & mask) {
437aa565e265677 Ivan Djelic 2011-03-11  516  				if (r != p) {
67120a42a5dc4e4 Yihao Han   2021-11-08  517  					swap(rows[r], rows[p]);
437aa565e265677 Ivan Djelic 2011-03-11  518  				}
437aa565e265677 Ivan Djelic 2011-03-11  519  				rem = r+1;
437aa565e265677 Ivan Djelic 2011-03-11  520  				break;
437aa565e265677 Ivan Djelic 2011-03-11  521  			}
437aa565e265677 Ivan Djelic 2011-03-11  522  		}
437aa565e265677 Ivan Djelic 2011-03-11  523  		if (rem) {
437aa565e265677 Ivan Djelic 2011-03-11  524  			/* perform elimination on remaining rows */
437aa565e265677 Ivan Djelic 2011-03-11 @525  			tmp = rows[p];
437aa565e265677 Ivan Djelic 2011-03-11  526  			for (r = rem; r < m; r++) {
437aa565e265677 Ivan Djelic 2011-03-11  527  				if (rows[r] & mask)
437aa565e265677 Ivan Djelic 2011-03-11  528  					rows[r] ^= tmp;
437aa565e265677 Ivan Djelic 2011-03-11  529  			}
437aa565e265677 Ivan Djelic 2011-03-11  530  		} else {
437aa565e265677 Ivan Djelic 2011-03-11  531  			/* elimination not needed, store defective row index */
437aa565e265677 Ivan Djelic 2011-03-11  532  			param[k++] = c;
437aa565e265677 Ivan Djelic 2011-03-11  533  		}
437aa565e265677 Ivan Djelic 2011-03-11  534  		mask >>= 1;
437aa565e265677 Ivan Djelic 2011-03-11  535  	}
437aa565e265677 Ivan Djelic 2011-03-11  536  	/* rewrite system, inserting fake parameter rows */
437aa565e265677 Ivan Djelic 2011-03-11  537  	if (k > 0) {
437aa565e265677 Ivan Djelic 2011-03-11  538  		p = k;
437aa565e265677 Ivan Djelic 2011-03-11  539  		for (r = m-1; r >= 0; r--) {
437aa565e265677 Ivan Djelic 2011-03-11  540  			if ((r > m-1-k) && rows[r])
437aa565e265677 Ivan Djelic 2011-03-11  541  				/* system has no solution */
437aa565e265677 Ivan Djelic 2011-03-11  542  				return 0;
437aa565e265677 Ivan Djelic 2011-03-11  543  
437aa565e265677 Ivan Djelic 2011-03-11  544  			rows[r] = (p && (r == param[p-1])) ?
437aa565e265677 Ivan Djelic 2011-03-11  545  				p--, 1u << (m-r) : rows[r-p];
437aa565e265677 Ivan Djelic 2011-03-11  546  		}
437aa565e265677 Ivan Djelic 2011-03-11  547  	}
437aa565e265677 Ivan Djelic 2011-03-11  548  
437aa565e265677 Ivan Djelic 2011-03-11  549  	if (nsol != (1 << k))
437aa565e265677 Ivan Djelic 2011-03-11  550  		/* unexpected number of solutions */
437aa565e265677 Ivan Djelic 2011-03-11  551  		return 0;
437aa565e265677 Ivan Djelic 2011-03-11  552  
437aa565e265677 Ivan Djelic 2011-03-11  553  	for (p = 0; p < nsol; p++) {
437aa565e265677 Ivan Djelic 2011-03-11  554  		/* set parameters for p-th solution */
437aa565e265677 Ivan Djelic 2011-03-11  555  		for (c = 0; c < k; c++)
437aa565e265677 Ivan Djelic 2011-03-11  556  			rows[param[c]] = (rows[param[c]] & ~1)|((p >> c) & 1);
437aa565e265677 Ivan Djelic 2011-03-11  557  
437aa565e265677 Ivan Djelic 2011-03-11  558  		/* compute unique solution */
437aa565e265677 Ivan Djelic 2011-03-11  559  		tmp = 0;
437aa565e265677 Ivan Djelic 2011-03-11  560  		for (r = m-1; r >= 0; r--) {
437aa565e265677 Ivan Djelic 2011-03-11  561  			mask = rows[r] & (tmp|1);
437aa565e265677 Ivan Djelic 2011-03-11  562  			tmp |= parity(mask) << (m-r);
437aa565e265677 Ivan Djelic 2011-03-11  563  		}
437aa565e265677 Ivan Djelic 2011-03-11  564  		sol[p] = tmp >> 1;
437aa565e265677 Ivan Djelic 2011-03-11  565  	}
437aa565e265677 Ivan Djelic 2011-03-11  566  	return nsol;
437aa565e265677 Ivan Djelic 2011-03-11  567  }
437aa565e265677 Ivan Djelic 2011-03-11  568  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 70007 bytes --]

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

* [PATCH] lib/bch:using swap() instead of tmp variable
@ 2021-11-09  6:18 Yihao Han
  0 siblings, 0 replies; 3+ messages in thread
From: Yihao Han @ 2021-11-09  6:18 UTC (permalink / raw)
  To: Yihao Han, Bhaskar Chowdhury, Randy Dunlap, Andrew Morton, linux-kernel
  Cc: kernel

swap() was used instead of the tmp variable to swap values

Signed-off-by: Yihao Han <hanyihao@vivo.com>
---
 lib/bch.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/lib/bch.c b/lib/bch.c
index c8095f30f254..0d6a2942ad20 100644
--- a/lib/bch.c
+++ b/lib/bch.c
@@ -500,7 +500,7 @@ static int solve_linear_system(struct bch_control *bch, unsigned int *rows,
 			       unsigned int *sol, int nsol)
 {
 	const int m = GF_M(bch);
-	unsigned int tmp, mask;
+	unsigned int mask;
 	int rem, c, r, p, k, param[BCH_MAX_M];
 
 	k = 0;
@@ -514,9 +514,7 @@ static int solve_linear_system(struct bch_control *bch, unsigned int *rows,
 		for (r = p; r < m; r++) {
 			if (rows[r] & mask) {
 				if (r != p) {
-					tmp = rows[r];
-					rows[r] = rows[p];
-					rows[p] = tmp;
+					swap(rows[r],rows[p]);
 				}
 				rem = r+1;
 				break;
@@ -833,21 +831,15 @@ static void gf_poly_div(struct bch_control *bch, struct gf_poly *a,
 static struct gf_poly *gf_poly_gcd(struct bch_control *bch, struct gf_poly *a,
 				   struct gf_poly *b)
 {
-	struct gf_poly *tmp;
-
 	dbg("gcd(%s,%s)=", gf_poly_str(a), gf_poly_str(b));
 
 	if (a->deg < b->deg) {
-		tmp = b;
-		b = a;
-		a = tmp;
+		swap(b,a);
 	}
 
 	while (b->deg > 0) {
 		gf_poly_mod(bch, a, b, NULL);
-		tmp = b;
-		b = a;
-		a = tmp;
+		swap(b,a);
 	}
 
 	dbg("%s\n", gf_poly_str(a));
-- 
2.17.1


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

end of thread, other threads:[~2021-11-10 11:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09  6:32 [PATCH] lib/bch:using swap() instead of tmp variable Yihao Han
2021-11-10 11:32 ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2021-11-09  6:18 Yihao Han

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®