Skip to contentSkip to conversation

drm/panic: use `div_ceil` to clean Clippy warning

PATCH In review Miguel Ojeda 5 participants 13 messages Mar 1, 2025 – Mar 10, 2025

Subsystems (3)
lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH 1/2 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.

---
 drivers/gpu/drm/drm_panic_qr.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_panic_qr.rs +2 -2
index bcf248f69252..8bb5e52d75cc 100644
@@ -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

Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH 2/2 drm/panic: fix overindented list items in documentation

Starting with the upcoming Rust 1.86.0 (to be released 2025-04-03), Clippy warns:

error: doc list item overindented
--> drivers/gpu/drm/drm_panic_qr.rs:914:5
|
914 | /// will be encoded as binary segment, otherwise it will be encoded
| ^^^ help: try using ` ` (2 spaces)
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_overindented_list_items

The overindentation is slightly hard to notice, since all the items start with a backquote that makes it look OK, but it is there.

Thus fix it.

---
 drivers/gpu/drm/drm_panic_qr.rs | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_panic_qr.rs +6 -6
index 8bb5e52d75cc..6903e2010cb9 100644
@@ -911,16 +911,16 @@ fn draw_all(&mut self, data: impl Iterator<Item = u8>) {
 ///
 /// * `url`: The base URL of the QR code. It will be encoded as Binary segment.
 /// * `data`: A pointer to the binary data, to be encoded. if URL is NULL, it
-///    will be encoded as binary segment, otherwise it will be encoded
-///    efficiently as a numeric segment, and appended to the URL.
+///   will be encoded as binary segment, otherwise it will be encoded
+///   efficiently as a numeric segment, and appended to the URL.
 /// * `data_len`: Length of the data, that needs to be encoded, must be less
-///    than data_size.
+///   than data_size.
 /// * `data_size`: Size of data buffer, it should be at least 4071 bytes to hold
-///    a V40 QR code. It will then be overwritten with the QR code image.
+///   a V40 QR code. It will then be overwritten with the QR code image.
 /// * `tmp`: A temporary buffer that the QR code encoder will use, to write the
-///    segments and ECC.
+///   segments and ECC.
 /// * `tmp_size`: Size of the temporary buffer, it must be at least 3706 bytes
-///    long for V40.
+///   long for V40.
 ///
 /// # Safety
 ///
Signature · 1 line
2.48.1
#2 lore raw

Re: [PATCH 2/2] drm/panic: fix overindented list items in documentation

Quoted 12 lines · Miguel Ojeda

Starting with the upcoming Rust 1.86.0 (to be released 2025-04-03), Clippy warns:

error: doc list item overindented
--> drivers/gpu/drm/drm_panic_qr.rs:914:5
|
914 | /// will be encoded as binary segment, otherwise it will be encoded
| ^^^ help: try using ` ` (2 spaces)
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_overindented_list_items

Quoted 6 lines

The overindentation is slightly hard to notice, since all the items start with a backquote that makes it look OK, but it is there.

Thus fix it.

Fixes cb5164ac43d0 ("drm/panic: Add a QR code panic screen")
Cc [email protected] # Needed in 6.12.y and 6.13.y only (Rust is

pinned in older LTSs).

Cheers,
Miguel

#3 lore raw

Re: [PATCH 2/2] drm/panic: fix overindented list items in documentation

Quoted 16 lines · Miguel Ojeda
Quoted 15 lines · Miguel Ojeda

Starting with the upcoming Rust 1.86.0 (to be released 2025-04-03), Clippy warns:

error: doc list item overindented
--> drivers/gpu/drm/drm_panic_qr.rs:914:5
|
914 | /// will be encoded as binary segment, otherwise it will be encoded
| ^^^ help: try using ` ` (2 spaces)
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_overindented_list_items

The overindentation is slightly hard to notice, since all the items start with a backquote that makes it look OK, but it is there.

Quoted 7 lines
Quoted 3 lines

Thus fix it.

Fixes cb5164ac43d0 ("drm/panic: Add a QR code panic screen")
Cc [email protected] # Needed in 6.12.y and 6.13.y only (Rust is

pinned in older LTSs).

(cosmetic) Nit:

I think you could just:

Cc [email protected] # v6.12+
Quoted 4 lines

Cheers,
Miguel

BR, Jarkko

#4 lore raw

Re: [PATCH 2/2] drm/panic: fix overindented list items in documentation

Quoted 6 lines · Jarkko Sakkinen

(cosmetic) Nit:

I think you could just:

Cc [email protected] # v6.12+

Thanks Jarkko -- I did something similar in the past, but sometimes patches got backported too much because they could be applied.

Normally they don't hurt, but I try to be more explicit nowadays so that the stable team can decide, and thus I copy-paste that line for changes that are related to new compiler cleanups and similar.

Cheers,
Miguel

#5 lore raw

Re: [PATCH 2/2] drm/panic: fix overindented list items in documentation

Quoted 6 lines · Miguel Ojeda
Quoted 5 lines · Jarkko Sakkinen

(cosmetic) Nit:

I think you could just:

Quoted 8 lines
Quoted 1 line
Cc [email protected] # v6.12+

Thanks Jarkko -- I did something similar in the past, but sometimes patches got backported too much because they could be applied.

Normally they don't hurt, but I try to be more explicit nowadays so that the stable team can decide, and thus I copy-paste that line for changes that are related to new compiler cleanups and similar.

Ah, ok, I guessed that you might have some backing idea on what you put :-) Thanks for the explanation.

Quoted 4 lines

Cheers,
Miguel

BR, Jarkko

#6 lore raw

Re: [PATCH 2/2] drm/panic: fix overindented list items in documentation

Quoted 3 lines · Jarkko Sakkinen

Ah, ok, I guessed that you might have some backing idea on what you put :-) Thanks for the explanation.

You're welcome!

Cheers,
Miguel

reviewer Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] drm/panic: fix overindented list items in documentation

In reply to Miguel Ojeda
Quoted 12 lines · Miguel Ojeda

Starting with the upcoming Rust 1.86.0 (to be released 2025-04-03), Clippy warns:

error: doc list item overindented
--> drivers/gpu/drm/drm_panic_qr.rs:914:5
|
914 | /// will be encoded as binary segment, otherwise it will be encoded
| ^^^ help: try using ` ` (2 spaces)
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_overindented_list_items

Quoted 6 lines

The overindentation is slightly hard to notice, since all the items start with a backquote that makes it look OK, but it is there.

Thus fix it.

Reviewed-by on v1 2/2
#8 lore raw

Re: [PATCH 2/2] drm/panic: fix overindented list items in documentation

In reply to Miguel Ojeda
Quoted 11 lines · Miguel Ojeda

Starting with the upcoming Rust 1.86.0 (to be released 2025-04-03), Clippy warns:

error: doc list item overindented
--> drivers/gpu/drm/drm_panic_qr.rs:914:5
|
914 | /// will be encoded as binary segment, otherwise it will be encoded
| ^^^ help: try using ` ` (2 spaces)
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_overindented_list_items

Quoted 4 lines

The overindentation is slightly hard to notice, since all the items start with a backquote that makes it look OK, but it is there.

Thus fix it.

Thanks, it looks good to me.

Quoted 33 lines
---
  drivers/gpu/drm/drm_panic_qr.rs | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_panic_qr.rs +6 -6
index 8bb5e52d75cc..6903e2010cb9 100644
@@ -911,16 +911,16 @@ fn draw_all(&mut self, data: impl Iterator<Item = u8>) {
  ///
  /// * `url`: The base URL of the QR code. It will be encoded as Binary segment.
  /// * `data`: A pointer to the binary data, to be encoded. if URL is NULL, it
-///    will be encoded as binary segment, otherwise it will be encoded
-///    efficiently as a numeric segment, and appended to the URL.
+///   will be encoded as binary segment, otherwise it will be encoded
+///   efficiently as a numeric segment, and appended to the URL.
  /// * `data_len`: Length of the data, that needs to be encoded, must be less
-///    than data_size.
+///   than data_size.
  /// * `data_size`: Size of data buffer, it should be at least 4071 bytes to hold
-///    a V40 QR code. It will then be overwritten with the QR code image.
+///   a V40 QR code. It will then be overwritten with the QR code image.
  /// * `tmp`: A temporary buffer that the QR code encoder will use, to write the
-///    segments and ECC.
+///   segments and ECC.
  /// * `tmp_size`: Size of the temporary buffer, it must be at least 3706 bytes
-///    long for V40.
+///   long for V40.
  ///
  /// # Safety
  ///
#9 lore raw
In reply to Miguel Ojeda
Quoted 14 lines · Miguel Ojeda

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.

Quoted 7 lines

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.

Cc: [email protected] # Needed in 6.12.y and 6.13.y only (Rust is pinned in older LTSs).

Cheers,
Miguel

reviewer Reviewed-by on v1 1/2
#10 lore raw
In reply to Miguel Ojeda
Quoted 14 lines · Miguel Ojeda

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.

Quoted 7 lines

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.

Reviewed-by on v1 1/2
#11 lore raw
In reply to Miguel Ojeda
Quoted 11 lines · Miguel Ojeda

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
Quoted 5 lines

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.

Thanks, so that's the DIV_ROUND_UP equivalent I was looking for.

Quoted 32 lines
---
  drivers/gpu/drm/drm_panic_qr.rs | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_panic_qr.rs +2 -2
index bcf248f69252..8bb5e52d75cc 100644
@@ -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

#12 lore raw
In reply to Miguel Ojeda
Quoted 11 lines · Miguel Ojeda

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
Quoted 5 lines

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.

I pushed both patches to drm-misc-fixes, with the "Cc" tag added.

Thanks a lot for your contributions.

Signature · 1 line
Jocelyn
Quoted 32 lines
---
  drivers/gpu/drm/drm_panic_qr.rs | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_panic_qr.rs +2 -2
index bcf248f69252..8bb5e52d75cc 100644
@@ -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