Skip to content

Commit 986c2e9

Browse files
ojedaJocelyn Falempe
authored andcommitted
drm/panic: use div_ceil to clean Clippy warning
Starting with the upcoming Rust 1.86.0 (to be released 2025-04-03), Clippy warns: error: manually reimplementing `div_ceil` --> drivers/gpu/drm/drm_panic_qr.rs:548:26 | 548 | let pad_offset = (offset + 7) / 8; | ^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `offset.div_ceil(8)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_div_ceil And similarly for `stride`. Thus apply the suggestion to both. The behavior (and thus codegen) is not exactly equivalent [1][2], since `div_ceil()` returns the right value for the values that currently would overflow. Link: rust-lang/rust-clippy#14333 [1] Link: https://godbolt.org/z/dPq6nGnv3 [2] Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Fixes: cb5164a ("drm/panic: Add a QR code panic screen") Cc: stable@vger.kernel.org # Needed in 6.12.y and 6.13.y only (Rust is pinned in older LTSs). Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com> Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250301231602.917580-1-ojeda@kernel.org
1 parent 9af152d commit 986c2e9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/gpu/drm/drm_panic_qr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ impl EncodedMsg<'_> {
545545
}
546546
self.push(&mut offset, (MODE_STOP, 4));
547547

548-
let pad_offset = (offset + 7) / 8;
548+
let pad_offset = offset.div_ceil(8);
549549
for i in pad_offset..self.version.max_data() {
550550
self.data[i] = PADDING[(i & 1) ^ (pad_offset & 1)];
551551
}
@@ -659,7 +659,7 @@ struct QrImage<'a> {
659659
impl QrImage<'_> {
660660
fn new<'a, 'b>(em: &'b EncodedMsg<'b>, qrdata: &'a mut [u8]) -> QrImage<'a> {
661661
let width = em.version.width();
662-
let stride = (width + 7) / 8;
662+
let stride = width.div_ceil(8);
663663
let data = qrdata;
664664

665665
let mut qr_image = QrImage {

0 commit comments

Comments
 (0)