Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Reed Riley <reed@riley.engineer>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

authored by

Reed Riley and committed by
Kent Overstreet
27663d77 36f0af4f

+6 -6
+1 -1
fs/bcachefs/sysfs.c
··· 288 288 prt_tab_rjust(out); 289 289 290 290 prt_human_readable_u64(out, nr_extents 291 - ? div_u64(sectors_uncompressed << 9, nr_extents) 291 + ? div64_u64(sectors_uncompressed << 9, nr_extents) 292 292 : 0); 293 293 prt_tab_rjust(out); 294 294 prt_newline(out);
+5 -5
fs/bcachefs/util.c
··· 64 64 *res = 1; 65 65 66 66 while (p--) { 67 - if (*res > div_u64(U64_MAX, n)) 67 + if (*res > div64_u64(U64_MAX, n)) 68 68 return -ERANGE; 69 69 *res *= n; 70 70 } ··· 140 140 141 141 parse_or_ret(cp, parse_unit_suffix(cp, &b)); 142 142 143 - if (v > div_u64(U64_MAX, b)) 143 + if (v > div64_u64(U64_MAX, b)) 144 144 return -ERANGE; 145 145 v *= b; 146 146 147 - if (f_n > div_u64(U64_MAX, b)) 147 + if (f_n > div64_u64(U64_MAX, b)) 148 148 return -ERANGE; 149 149 150 - f_n = div_u64(f_n * b, f_d); 150 + f_n = div64_u64(f_n * b, f_d); 151 151 if (v + f_n < v) 152 152 return -ERANGE; 153 153 v += f_n; ··· 477 477 bool is_last = eytzinger0_next(i, NR_QUANTILES) == -1; 478 478 479 479 u64 q = max(quantiles->entries[i].m, last_q); 480 - prt_printf(out, "%llu ", div_u64(q, u->nsecs)); 480 + prt_printf(out, "%llu ", div64_u64(q, u->nsecs)); 481 481 if (is_last) 482 482 prt_newline(out); 483 483 last_q = q;