* [PATCH] rust: list: Use "List::is_empty()" to perform checking when possible
@ 2025-03-10 7:38 I Hsin Cheng
2025-05-21 15:23 ` Miguel Ojeda
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: I Hsin Cheng @ 2025-03-10 7:38 UTC (permalink / raw)
To: ojeda
Cc: alex.gaynor, boqun.feng, gary, bjorn3_gh, benno.lossin,
a.hindborg, aliceryhl, tmgross, rust-for-linux, linux-kernel,
skhan, linux-kernel-mentees, jserv, I Hsin Cheng
"List::is_empty()" provides a straight forward convention to check
whether a given "List" is empty or not. There're numerous places in the
current implementation still use "self.first.is_null()" to perform the
equivalent check, replace them with "List::is_empty()".
Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
---
rust/kernel/list.rs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs
index fb93330f4af4..8f3919bd3f99 100644
--- a/rust/kernel/list.rs
+++ b/rust/kernel/list.rs
@@ -259,7 +259,7 @@ pub fn push_back(&mut self, item: ListArc<T, ID>) {
// SAFETY: We have not yet called `post_remove`, so `list_links` is still valid.
let item = unsafe { ListLinks::fields(list_links) };
- if self.first.is_null() {
+ if self.is_empty() {
self.first = item;
// SAFETY: The caller just gave us ownership of these fields.
// INVARIANT: A linked list with one item should be cyclic.
@@ -299,7 +299,7 @@ pub fn push_front(&mut self, item: ListArc<T, ID>) {
// SAFETY: We have not yet called `post_remove`, so `list_links` is still valid.
let item = unsafe { ListLinks::fields(list_links) };
- if self.first.is_null() {
+ if self.is_empty() {
// SAFETY: The caller just gave us ownership of these fields.
// INVARIANT: A linked list with one item should be cyclic.
unsafe {
@@ -325,7 +325,7 @@ pub fn push_front(&mut self, item: ListArc<T, ID>) {
/// Removes the last item from this list.
pub fn pop_back(&mut self) -> Option<ListArc<T, ID>> {
- if self.first.is_null() {
+ if self.is_empty() {
return None;
}
@@ -337,7 +337,7 @@ pub fn pop_back(&mut self) -> Option<ListArc<T, ID>> {
/// Removes the first item from this list.
pub fn pop_front(&mut self) -> Option<ListArc<T, ID>> {
- if self.first.is_null() {
+ if self.is_empty() {
return None;
}
@@ -493,7 +493,7 @@ pub fn push_all_back(&mut self, other: &mut List<T, ID>) {
///
/// If the list is empty, this returns `None`.
pub fn cursor_front(&mut self) -> Option<Cursor<'_, T, ID>> {
- if self.first.is_null() {
+ if self.is_empty() {
None
} else {
Some(Cursor {
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] rust: list: Use "List::is_empty()" to perform checking when possible
2025-03-10 7:38 [PATCH] rust: list: Use "List::is_empty()" to perform checking when possible I Hsin Cheng
@ 2025-05-21 15:23 ` Miguel Ojeda
2025-05-22 9:47 ` Miguel Ojeda
2025-05-22 9:52 ` Benno Lossin
2 siblings, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2025-05-21 15:23 UTC (permalink / raw)
To: richard120310, aliceryhl
Cc: a.hindborg, alex.gaynor, benno.lossin, bjorn3_gh, boqun.feng,
gary, jserv, linux-kernel-mentees, linux-kernel, ojeda,
rust-for-linux, skhan, tmgross
On Mon, 10 Mar 2025 15:38:52 +0800 I Hsin Cheng <richard120310@gmail.com> wrote:
>
> "List::is_empty()" provides a straight forward convention to check
> whether a given "List" is empty or not. There're numerous places in the
> current implementation still use "self.first.is_null()" to perform the
> equivalent check, replace them with "List::is_empty()".
>
> Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
There are a couple cases that still apply here (i.e. after the cursor
between elements change), so I will pick it up.
By the way, for some reason, your email did not reach my inbox.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rust: list: Use "List::is_empty()" to perform checking when possible
2025-03-10 7:38 [PATCH] rust: list: Use "List::is_empty()" to perform checking when possible I Hsin Cheng
2025-05-21 15:23 ` Miguel Ojeda
@ 2025-05-22 9:47 ` Miguel Ojeda
2025-05-22 9:52 ` Benno Lossin
2 siblings, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2025-05-22 9:47 UTC (permalink / raw)
To: richard120310
Cc: a.hindborg, alex.gaynor, aliceryhl, benno.lossin, bjorn3_gh,
boqun.feng, gary, jserv, linux-kernel-mentees, linux-kernel,
ojeda, rust-for-linux, skhan, tmgross
On Mon, 10 Mar 2025 15:38:52 +0800 I Hsin Cheng <richard120310@gmail.com> wrote:
>
> "List::is_empty()" provides a straight forward convention to check
> whether a given "List" is empty or not. There're numerous places in the
> current implementation still use "self.first.is_null()" to perform the
> equivalent check, replace them with "List::is_empty()".
>
> Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
Applied to `rust-next` -- thanks!
[ Rebased dropping the cases that do not apply anymore. - Miguel ]
Cheers,
Miguel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rust: list: Use "List::is_empty()" to perform checking when possible
2025-03-10 7:38 [PATCH] rust: list: Use "List::is_empty()" to perform checking when possible I Hsin Cheng
2025-05-21 15:23 ` Miguel Ojeda
2025-05-22 9:47 ` Miguel Ojeda
@ 2025-05-22 9:52 ` Benno Lossin
2025-05-22 10:01 ` Miguel Ojeda
2 siblings, 1 reply; 5+ messages in thread
From: Benno Lossin @ 2025-05-22 9:52 UTC (permalink / raw)
To: I Hsin Cheng, ojeda
Cc: alex.gaynor, boqun.feng, gary, bjorn3_gh, benno.lossin,
a.hindborg, aliceryhl, tmgross, rust-for-linux, linux-kernel,
skhan, linux-kernel-mentees, jserv
On Mon Mar 10, 2025 at 8:38 AM CET, I Hsin Cheng wrote:
> "List::is_empty()" provides a straight forward convention to check
> whether a given "List" is empty or not. There're numerous places in the
> current implementation still use "self.first.is_null()" to perform the
> equivalent check, replace them with "List::is_empty()".
>
> Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
> ---
> rust/kernel/list.rs | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
Reviewed-by: Benno Lossin <lossin@kernel.org>
---
Cheers,
Benno
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rust: list: Use "List::is_empty()" to perform checking when possible
2025-05-22 9:52 ` Benno Lossin
@ 2025-05-22 10:01 ` Miguel Ojeda
0 siblings, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2025-05-22 10:01 UTC (permalink / raw)
To: Benno Lossin
Cc: I Hsin Cheng, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh,
benno.lossin, a.hindborg, aliceryhl, tmgross, rust-for-linux,
linux-kernel, skhan, linux-kernel-mentees, jserv
On Thu, May 22, 2025 at 11:53 AM Benno Lossin <lossin@kernel.org> wrote:
>
> Reviewed-by: Benno Lossin <lossin@kernel.org>
Added :)
Cheers,
Miguel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-22 10:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-10 7:38 [PATCH] rust: list: Use "List::is_empty()" to perform checking when possible I Hsin Cheng
2025-05-21 15:23 ` Miguel Ojeda
2025-05-22 9:47 ` Miguel Ojeda
2025-05-22 9:52 ` Benno Lossin
2025-05-22 10:01 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).