[PATCH 1/2] drm/panic: use `div_ceil` to clean Clippy warning
Jocelyn Falempe
jfalempe at redhat.com
Mon Mar 3 09:40:59 UTC 2025
On 02/03/2025 00:16, Miguel Ojeda wrote:
> 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.
Thanks, so that's the DIV_ROUND_UP equivalent I was looking for.
Reviewed-by: Jocelyn Falempe <jfalempe at redhat.com>
>
> Link: https://github.com/rust-lang/rust-clippy/issues/14333 [1]
> Link: https://godbolt.org/z/dPq6nGnv3 [2]
> Signed-off-by: Miguel Ojeda <ojeda at 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
More information about the dri-devel
mailing list