public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: avoid unused import warning in `rusttest`
@ 2024-05-19 21:07 Miguel Ojeda
  2024-05-20  9:40 ` Alice Ryhl
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Miguel Ojeda @ 2024-05-19 21:07 UTC (permalink / raw)
  To: Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, rust-for-linux, linux-kernel,
	patches, Danilo Krummrich

When compiling for the `rusttest` target, the `core::ptr` import is
unused since its only use happens in the `reserve()` method which is
not compiled in that target:

    warning: unused import: `core::ptr`
    --> rust/kernel/alloc/vec_ext.rs:7:5
      |
    7 | use core::ptr;
      |     ^^^^^^^^^
      |
      = note: `#[warn(unused_imports)]` on by default

Thus clean it.

Fixes: 97ab3e8eec0c ("rust: alloc: fix dangling pointer in VecExt<T>::reserve()")
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
 rust/kernel/alloc/vec_ext.rs | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/alloc/vec_ext.rs b/rust/kernel/alloc/vec_ext.rs
index e9a81052728a..1297a4be32e8 100644
--- a/rust/kernel/alloc/vec_ext.rs
+++ b/rust/kernel/alloc/vec_ext.rs
@@ -4,7 +4,6 @@
 
 use super::{AllocError, Flags};
 use alloc::vec::Vec;
-use core::ptr;
 
 /// Extensions to [`Vec`].
 pub trait VecExt<T>: Sized {
@@ -141,7 +140,11 @@ fn reserve(&mut self, additional: usize, flags: Flags) -> Result<(), AllocError>
         // `krealloc_aligned`. A `Vec<T>`'s `ptr` value is not guaranteed to be NULL and might be
         // dangling after being created with `Vec::new`. Instead, we can rely on `Vec<T>`'s capacity
         // to be zero if no memory has been allocated yet.
-        let ptr = if cap == 0 { ptr::null_mut() } else { old_ptr };
+        let ptr = if cap == 0 {
+            core::ptr::null_mut()
+        } else {
+            old_ptr
+        };
 
         // SAFETY: `ptr` is valid because it's either NULL or comes from a previous call to
         // `krealloc_aligned`. We also verified that the type is not a ZST.

base-commit: 97ab3e8eec0ce79d9e265e6c9e4c480492180409
-- 
2.45.1


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

* Re: [PATCH] rust: avoid unused import warning in `rusttest`
  2024-05-19 21:07 [PATCH] rust: avoid unused import warning in `rusttest` Miguel Ojeda
@ 2024-05-20  9:40 ` Alice Ryhl
  2024-05-20 15:24 ` Danilo Krummrich
  2024-06-11 22:13 ` Miguel Ojeda
  2 siblings, 0 replies; 4+ messages in thread
From: Alice Ryhl @ 2024-05-20  9:40 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Wedson Almeida Filho, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	rust-for-linux, linux-kernel, patches, Danilo Krummrich

On Sun, May 19, 2024 at 11:07 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> When compiling for the `rusttest` target, the `core::ptr` import is
> unused since its only use happens in the `reserve()` method which is
> not compiled in that target:
>
>     warning: unused import: `core::ptr`
>     --> rust/kernel/alloc/vec_ext.rs:7:5
>       |
>     7 | use core::ptr;
>       |     ^^^^^^^^^
>       |
>       = note: `#[warn(unused_imports)]` on by default
>
> Thus clean it.
>
> Fixes: 97ab3e8eec0c ("rust: alloc: fix dangling pointer in VecExt<T>::reserve()")
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

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

* Re: [PATCH] rust: avoid unused import warning in `rusttest`
  2024-05-19 21:07 [PATCH] rust: avoid unused import warning in `rusttest` Miguel Ojeda
  2024-05-20  9:40 ` Alice Ryhl
@ 2024-05-20 15:24 ` Danilo Krummrich
  2024-06-11 22:13 ` Miguel Ojeda
  2 siblings, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2024-05-20 15:24 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Wedson Almeida Filho, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	rust-for-linux, linux-kernel, patches

On Sun, May 19, 2024 at 11:07:35PM +0200, Miguel Ojeda wrote:
> When compiling for the `rusttest` target, the `core::ptr` import is
> unused since its only use happens in the `reserve()` method which is
> not compiled in that target:
> 
>     warning: unused import: `core::ptr`
>     --> rust/kernel/alloc/vec_ext.rs:7:5
>       |
>     7 | use core::ptr;
>       |     ^^^^^^^^^
>       |
>       = note: `#[warn(unused_imports)]` on by default
> 
> Thus clean it.
> 
> Fixes: 97ab3e8eec0c ("rust: alloc: fix dangling pointer in VecExt<T>::reserve()")
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Reviewed-by: Danilo Krummrich <dakr@redhat.com>

> ---
>  rust/kernel/alloc/vec_ext.rs | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/rust/kernel/alloc/vec_ext.rs b/rust/kernel/alloc/vec_ext.rs
> index e9a81052728a..1297a4be32e8 100644
> --- a/rust/kernel/alloc/vec_ext.rs
> +++ b/rust/kernel/alloc/vec_ext.rs
> @@ -4,7 +4,6 @@
>  
>  use super::{AllocError, Flags};
>  use alloc::vec::Vec;
> -use core::ptr;
>  
>  /// Extensions to [`Vec`].
>  pub trait VecExt<T>: Sized {
> @@ -141,7 +140,11 @@ fn reserve(&mut self, additional: usize, flags: Flags) -> Result<(), AllocError>
>          // `krealloc_aligned`. A `Vec<T>`'s `ptr` value is not guaranteed to be NULL and might be
>          // dangling after being created with `Vec::new`. Instead, we can rely on `Vec<T>`'s capacity
>          // to be zero if no memory has been allocated yet.
> -        let ptr = if cap == 0 { ptr::null_mut() } else { old_ptr };
> +        let ptr = if cap == 0 {
> +            core::ptr::null_mut()
> +        } else {
> +            old_ptr
> +        };
>  
>          // SAFETY: `ptr` is valid because it's either NULL or comes from a previous call to
>          // `krealloc_aligned`. We also verified that the type is not a ZST.
> 
> base-commit: 97ab3e8eec0ce79d9e265e6c9e4c480492180409
> -- 
> 2.45.1
> 


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

* Re: [PATCH] rust: avoid unused import warning in `rusttest`
  2024-05-19 21:07 [PATCH] rust: avoid unused import warning in `rusttest` Miguel Ojeda
  2024-05-20  9:40 ` Alice Ryhl
  2024-05-20 15:24 ` Danilo Krummrich
@ 2024-06-11 22:13 ` Miguel Ojeda
  2 siblings, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2024-06-11 22:13 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Wedson Almeida Filho, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	rust-for-linux, linux-kernel, patches, Danilo Krummrich

On Sun, May 19, 2024 at 11:07 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> When compiling for the `rusttest` target, the `core::ptr` import is
> unused since its only use happens in the `reserve()` method which is
> not compiled in that target:
>
>     warning: unused import: `core::ptr`
>     --> rust/kernel/alloc/vec_ext.rs:7:5
>       |
>     7 | use core::ptr;
>       |     ^^^^^^^^^
>       |
>       = note: `#[warn(unused_imports)]` on by default
>
> Thus clean it.
>
> Fixes: 97ab3e8eec0c ("rust: alloc: fix dangling pointer in VecExt<T>::reserve()")
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Applied to `rust-fixes` -- thanks everyone!

Cheers,
Miguel

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

end of thread, other threads:[~2024-06-11 22:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-19 21:07 [PATCH] rust: avoid unused import warning in `rusttest` Miguel Ojeda
2024-05-20  9:40 ` Alice Ryhl
2024-05-20 15:24 ` Danilo Krummrich
2024-06-11 22:13 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox