drm/panic: use `div_ceil` to clean Clippy warning
Subsystems (3)
Miguel Ojeda
maintainerPATCH 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_ceilAnd 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
@@ -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 iin 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: &'bEncodedMsg <'b>, qrdata: &'amut [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
Miguel Ojeda
maintainerPATCH 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
@@ -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
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.
Signed-off-by Miguel Ojeda <[email protected]>
pinned in older LTSs).
Cheers,
Miguel
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_itemsThe 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.
Signed-off-by Miguel Ojeda <[email protected]>Fixes cb5164ac43d0 ("drm/panic: Add a QR code panic screen")Cc [email protected] # Needed in 6.12.y and 6.13.y only (Rust ispinned in older LTSs).
(cosmetic) Nit:
I think you could just:
Quoted 4 lines
Cheers,
Miguel
BR, Jarkko
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
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
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
Re: [PATCH 2/2] drm/panic: fix overindented list items in documentation
In reply to Miguel OjedaQuoted 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.
Signed-off-by Miguel Ojeda <[email protected]>
Re: [PATCH 2/2] drm/panic: fix overindented list items in documentation
In reply to Miguel OjedaQuoted 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
Signed-off-by Miguel Ojeda <[email protected]>--- drivers/gpu/drm/drm_panic_qr.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/drm_panic_qr.rs +6
-6@@ -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 ///
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_ceilAnd 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.Link https://godbolt.org/z/dPq6nGnv3 [2]Signed-off-by Miguel Ojeda <[email protected]>
Cc: [email protected] # Needed in 6.12.y and 6.13.y only (Rust is pinned in older LTSs).
Cheers,
Miguel
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_ceilAnd 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.Link https://godbolt.org/z/dPq6nGnv3 [2]Signed-off-by Miguel Ojeda <[email protected]>
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
Link https://godbolt.org/z/dPq6nGnv3 [2]Signed-off-by Miguel Ojeda <[email protected]>--- drivers/gpu/drm/drm_panic_qr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_panic_qr.rs +2
-2@@ -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 iin 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: &'bEncodedMsg <'b>, qrdata: &'amut [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
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
Link https://godbolt.org/z/dPq6nGnv3 [2]Signed-off-by Miguel Ojeda <[email protected]>--- drivers/gpu/drm/drm_panic_qr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_panic_qr.rs +2
-2@@ -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 iin 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: &'bEncodedMsg <'b>, qrdata: &'amut [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