-
Notifications
You must be signed in to change notification settings - Fork 434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The #[must_use]
annotation is missing on Lock::try_lock
#1133
Comments
I'm new to the kernel development and rust also. Can I take this one? |
Of course, please go ahead! |
The `Lock::try_lock` function returns an `Option<Guard<...>>`, but it currently does not issue a warning if the return value is unused. This could result in the lock being unlocked immediately, which is unsafe and unintended. This patch adds a `#[must_use]` annotation to `Lock::try_lock` to prevent this. Suggested-by: Alice Ryhl <[email protected]> Link: Rust-for-Linux#1133 Signed-off-by: Jason Devers <[email protected]>
@BorisChenCZY apologizes for not seeing this before submitting the patch, i'm also new to kernel development and would enjoy working on this with you. i can try to cc you on the current mailing list thread for this patch if you're not already on the mailing list? |
The `Lock::try_lock` function returns an `Option<Guard<...>>`, but it currently does not issue a warning if the return value is unused. To avoid potential bugs, the `#[must_use]` annotation is added to ensure proper usage. Suggested-by: Alice Ryhl <[email protected]> Link: Rust-for-Linux#1133 Signed-off-by: Jason Devers <[email protected]>
The `Lock::try_lock` function returns an `Option<Guard<...>>`, but it currently does not issue a warning if the return value is unused. To avoid potential bugs, the `#[must_use]` annotation is added to ensure proper usage. Note that `T` is `#[must_use]` but `Option<T>` is not. For more context, see: rust-lang/rust#71368. Suggested-by: Alice Ryhl <[email protected]> Link: Rust-for-Linux#1133 Signed-off-by: Jason Devers <[email protected]>
That would be great. Thanks
Regards,
Boris
…On Mon, Dec 9, 2024 at 3:52 AM hz2 ***@***.***> wrote:
@BorisChenCZY <https://github.com/BorisChenCZY> apologizes for not seeing
this before submitting the patch, i'm also new to kernel development and
would enjoy working on this with you.
i can try to cc you on the current mailing list thread for this patch if
you're not already on the mailing list?
—
Reply to this email directly, view it on GitHub
<#1133 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEZG25VXLZRUXE4JDMYDBJT2ESPRPAVCNFSM6AAAAABTAAZMFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMRWGM2TCNRXGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@BorisChenCZY cc'd you into the email chain for the patch, also can find the in the archive |
The `Lock::try_lock` function returns an `Option<Guard<...>>`, but it currently does not issue a warning if the return value is unused. To avoid potential bugs, the `#[must_use]` annotation is added to ensure proper usage. Note that `T` is `#[must_use]` but `Option<T>` is not. For more context, see: rust-lang/rust#71368. Suggested-by: Alice Ryhl <[email protected]> Link: Rust-for-Linux#1133 Signed-off-by: Jason Devers <[email protected]>
The `Lock::try_lock` function returns an `Option<Guard<...>>`, but it currently does not issue a warning if the return value is unused. To avoid potential bugs, the `#[must_use]` annotation is added to ensure proper usage. Note that `T` is `#[must_use]` but `Option<T>` is not. For more context, see: rust-lang/rust#71368. Suggested-by: Alice Ryhl <[email protected]> Link: Rust-for-Linux#1133 Signed-off-by: Jason Devers <[email protected]>
The `Lock::try_lock` function returns an `Option<Guard<...>>`, but it currently does not issue a warning if the return value is unused. To avoid potential bugs, the `#[must_use]` annotation is added to ensure proper usage. Note that `T` is `#[must_use]` but `Option<T>` is not. For more context, see: rust-lang/rust#71368. Suggested-by: Alice Ryhl <[email protected]> Link: Rust-for-Linux#1133 Signed-off-by: Jason Devers <[email protected]>
The
Guard
type for locks is marked with a#[must_use]
annotation like this:linux/rust/kernel/sync/lock.rs
Lines 162 to 163 in 40384c8
This means that trying to use
Lock::lock
without using the return value will result in a warning. However, this warning does not happen withLock::try_lock
, since it returns anOption<Guard<...>>
and theOption
type is not#[must_use]
.linux/rust/kernel/sync/lock.rs
Lines 147 to 154 in 40384c8
To fix this, add a
#[must_use]
annotation toLock::try_lock
directly.This requires submitting a proper patch to the LKML and the Rust for Linux mailing list. Please recall to test your changes (including generating the documentation if changed, running the Rust doctests if changed, etc.), to use a proper title for the commit, to sign your commit under the Developer's Certificate of Origin and to add a
Suggested-by: tag
and aLink:
tag to this issue. Please see https://rust-for-linux.com/contributing for details.Please take this issue only if you are new to the kernel development process and you would like to use it as a test to submit your first patch to the kernel. Please do not take it if you do not plan to make other contributions to the kernel.
The text was updated successfully, but these errors were encountered: