Skip to content

Commit e1fb743

Browse files
tobluxakpm00
authored andcommitted
lib/bch.c: use swap() to improve code
Use the swap() macro to simplify the functions solve_linear_system() and gf_poly_gcd() and improve their readability. Remove the local variable tmp. Fixes the following three Coccinelle/coccicheck warnings reported by swap.cocci: WARNING opportunity for swap() WARNING opportunity for swap() WARNING opportunity for swap() Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Thorsten Blum <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 4f5d4a1 commit e1fb743

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

lib/bch.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,8 @@ static int solve_linear_system(struct bch_control *bch, unsigned int *rows,
479479
/* find suitable row for elimination */
480480
for (r = p; r < m; r++) {
481481
if (rows[r] & mask) {
482-
if (r != p) {
483-
tmp = rows[r];
484-
rows[r] = rows[p];
485-
rows[p] = tmp;
486-
}
482+
if (r != p)
483+
swap(rows[r], rows[p]);
487484
rem = r+1;
488485
break;
489486
}
@@ -799,21 +796,14 @@ static void gf_poly_div(struct bch_control *bch, struct gf_poly *a,
799796
static struct gf_poly *gf_poly_gcd(struct bch_control *bch, struct gf_poly *a,
800797
struct gf_poly *b)
801798
{
802-
struct gf_poly *tmp;
803-
804799
dbg("gcd(%s,%s)=", gf_poly_str(a), gf_poly_str(b));
805800

806-
if (a->deg < b->deg) {
807-
tmp = b;
808-
b = a;
809-
a = tmp;
810-
}
801+
if (a->deg < b->deg)
802+
swap(a, b);
811803

812804
while (b->deg > 0) {
813805
gf_poly_mod(bch, a, b, NULL);
814-
tmp = b;
815-
b = a;
816-
a = tmp;
806+
swap(a, b);
817807
}
818808

819809
dbg("%s\n", gf_poly_str(a));

0 commit comments

Comments
 (0)