Commit 27663d77 authored by Reed Riley's avatar Reed Riley Committed by Kent Overstreet

bcachefs: Replace div_u64 with div64_u64 where second param is u64

Bcachefs often uses this function to divide by nanosecond times - which
can easily cause problems when cast to u32.  For example, `cat
/sys/fs/bcachefs/*/internal/rebalance_status` would return invalid data
in the `duration waited` field because dividing by the number of
nanoseconds in a minute requires the divisor parameter to be u64.
Signed-off-by: default avatarReed Riley <reed@riley.engineer>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 36f0af4f
...@@ -288,7 +288,7 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c ...@@ -288,7 +288,7 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c
prt_tab_rjust(out); prt_tab_rjust(out);
prt_human_readable_u64(out, nr_extents prt_human_readable_u64(out, nr_extents
? div_u64(sectors_uncompressed << 9, nr_extents) ? div64_u64(sectors_uncompressed << 9, nr_extents)
: 0); : 0);
prt_tab_rjust(out); prt_tab_rjust(out);
prt_newline(out); prt_newline(out);
......
...@@ -64,7 +64,7 @@ static int bch2_pow(u64 n, u64 p, u64 *res) ...@@ -64,7 +64,7 @@ static int bch2_pow(u64 n, u64 p, u64 *res)
*res = 1; *res = 1;
while (p--) { while (p--) {
if (*res > div_u64(U64_MAX, n)) if (*res > div64_u64(U64_MAX, n))
return -ERANGE; return -ERANGE;
*res *= n; *res *= n;
} }
...@@ -140,14 +140,14 @@ static int __bch2_strtou64_h(const char *cp, u64 *res) ...@@ -140,14 +140,14 @@ static int __bch2_strtou64_h(const char *cp, u64 *res)
parse_or_ret(cp, parse_unit_suffix(cp, &b)); parse_or_ret(cp, parse_unit_suffix(cp, &b));
if (v > div_u64(U64_MAX, b)) if (v > div64_u64(U64_MAX, b))
return -ERANGE; return -ERANGE;
v *= b; v *= b;
if (f_n > div_u64(U64_MAX, b)) if (f_n > div64_u64(U64_MAX, b))
return -ERANGE; return -ERANGE;
f_n = div_u64(f_n * b, f_d); f_n = div64_u64(f_n * b, f_d);
if (v + f_n < v) if (v + f_n < v)
return -ERANGE; return -ERANGE;
v += f_n; v += f_n;
...@@ -477,7 +477,7 @@ void bch2_time_stats_to_text(struct printbuf *out, struct bch2_time_stats *stats ...@@ -477,7 +477,7 @@ void bch2_time_stats_to_text(struct printbuf *out, struct bch2_time_stats *stats
bool is_last = eytzinger0_next(i, NR_QUANTILES) == -1; bool is_last = eytzinger0_next(i, NR_QUANTILES) == -1;
u64 q = max(quantiles->entries[i].m, last_q); u64 q = max(quantiles->entries[i].m, last_q);
prt_printf(out, "%llu ", div_u64(q, u->nsecs)); prt_printf(out, "%llu ", div64_u64(q, u->nsecs));
if (is_last) if (is_last)
prt_newline(out); prt_newline(out);
last_q = q; last_q = q;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment