Skip to content

Commit

Permalink
lib/bch.c: use swap() to improve code
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
toblux authored and akpm00 committed Jul 12, 2024
1 parent 4f5d4a1 commit e1fb743
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions lib/bch.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,8 @@ static int solve_linear_system(struct bch_control *bch, unsigned int *rows,
/* find suitable row for elimination */
for (r = p; r < m; r++) {
if (rows[r] & mask) {
if (r != p) {
tmp = rows[r];
rows[r] = rows[p];
rows[p] = tmp;
}
if (r != p)
swap(rows[r], rows[p]);
rem = r+1;
break;
}
Expand Down Expand Up @@ -799,21 +796,14 @@ 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;
}
if (a->deg < b->deg)
swap(a, b);

while (b->deg > 0) {
gf_poly_mod(bch, a, b, NULL);
tmp = b;
b = a;
a = tmp;
swap(a, b);
}

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

0 comments on commit e1fb743

Please sign in to comment.