All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/panic: use `div_ceil` to clean Clippy warning
@ 2025-03-01 23:16 Miguel Ojeda
  2025-03-01 23:16 ` [PATCH 2/2] drm/panic: fix overindented list items in documentation Miguel Ojeda
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Miguel Ojeda @ 2025-03-01 23:16 UTC (permalink / raw)
  To: Jocelyn Falempe, Thomas Böhler, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Miguel Ojeda, Alex Gaynor
  Cc: dri-devel, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	rust-for-linux, linux-kernel, patches

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: https://github.com/rust-lang/rust-clippy/issues/14333 [1]
Link: https://godbolt.org/z/dPq6nGnv3 [2]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
 drivers/gpu/drm/drm_panic_qr.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_panic_qr.rs b/drivers/gpu/drm/drm_panic_qr.rs
index bcf248f69252..8bb5e52d75cc 100644
--- a/drivers/gpu/drm/drm_panic_qr.rs
+++ b/drivers/gpu/drm/drm_panic_qr.rs
@@ -545,7 +545,7 @@ fn add_segments(&mut self, segments: &[&Segment<'_>]) {
         }
         self.push(&mut offset, (MODE_STOP, 4));
 
-        let pad_offset = (offset + 7) / 8;
+        let pad_offset = offset.div_ceil(8);
         for i in pad_offset..self.version.max_data() {
             self.data[i] = PADDING[(i & 1) ^ (pad_offset & 1)];
         }
@@ -659,7 +659,7 @@ struct QrImage<'a> {
 impl QrImage<'_> {
     fn new<'a, 'b>(em: &'b EncodedMsg<'b>, qrdata: &'a mut [u8]) -> QrImage<'a> {
         let width = em.version.width();
-        let stride = (width + 7) / 8;
+        let stride = width.div_ceil(8);
         let data = qrdata;
 
         let mut qr_image = QrImage {

base-commit: d082ecbc71e9e0bf49883ee4afd435a77a5101b6
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-03-10  7:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-01 23:16 [PATCH 1/2] drm/panic: use `div_ceil` to clean Clippy warning Miguel Ojeda
2025-03-01 23:16 ` [PATCH 2/2] drm/panic: fix overindented list items in documentation Miguel Ojeda
2025-03-02  6:54   ` Miguel Ojeda
2025-03-02 16:50     ` Jarkko Sakkinen
2025-03-02 17:45       ` Miguel Ojeda
2025-03-02 18:31         ` Jarkko Sakkinen
2025-03-02 19:52           ` Miguel Ojeda
2025-03-03  8:04   ` Alice Ryhl
2025-03-03  9:41   ` Jocelyn Falempe
2025-03-02  6:54 ` [PATCH 1/2] drm/panic: use `div_ceil` to clean Clippy warning Miguel Ojeda
2025-03-03  8:05 ` Alice Ryhl
2025-03-03  9:40 ` Jocelyn Falempe
2025-03-10  7:49 ` Jocelyn Falempe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.