mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 04:18:39 +08:00
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/20240708224023.9312-2-thorsten.blum@toblux.com Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
4f5d4a1ba7
commit
e1fb7430fc
20
lib/bch.c
20
lib/bch.c
@ -479,11 +479,8 @@ static int solve_linear_system(struct bch_control *bch, unsigned int *rows,
|
|||||||
/* find suitable row for elimination */
|
/* find suitable row for elimination */
|
||||||
for (r = p; r < m; r++) {
|
for (r = p; r < m; r++) {
|
||||||
if (rows[r] & mask) {
|
if (rows[r] & mask) {
|
||||||
if (r != p) {
|
if (r != p)
|
||||||
tmp = rows[r];
|
swap(rows[r], rows[p]);
|
||||||
rows[r] = rows[p];
|
|
||||||
rows[p] = tmp;
|
|
||||||
}
|
|
||||||
rem = r+1;
|
rem = r+1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -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,
|
static struct gf_poly *gf_poly_gcd(struct bch_control *bch, struct gf_poly *a,
|
||||||
struct gf_poly *b)
|
struct gf_poly *b)
|
||||||
{
|
{
|
||||||
struct gf_poly *tmp;
|
|
||||||
|
|
||||||
dbg("gcd(%s,%s)=", gf_poly_str(a), gf_poly_str(b));
|
dbg("gcd(%s,%s)=", gf_poly_str(a), gf_poly_str(b));
|
||||||
|
|
||||||
if (a->deg < b->deg) {
|
if (a->deg < b->deg)
|
||||||
tmp = b;
|
swap(a, b);
|
||||||
b = a;
|
|
||||||
a = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (b->deg > 0) {
|
while (b->deg > 0) {
|
||||||
gf_poly_mod(bch, a, b, NULL);
|
gf_poly_mod(bch, a, b, NULL);
|
||||||
tmp = b;
|
swap(a, b);
|
||||||
b = a;
|
|
||||||
a = tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg("%s\n", gf_poly_str(a));
|
dbg("%s\n", gf_poly_str(a));
|
||||||
|
Loading…
Reference in New Issue
Block a user