Skip to content
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

Fix macro referencing core and kernel crates #1150

Open
y86-dev opened this issue Mar 24, 2025 · 11 comments
Open

Fix macro referencing core and kernel crates #1150

y86-dev opened this issue Mar 24, 2025 · 11 comments
Assignees
Labels
easy Expected to be an easy issue to resolve. good first issue Good for newcomers • lib Related to the `rust/` library.

Comments

@y86-dev
Copy link
Member

y86-dev commented Mar 24, 2025

When macros refer to items from the core or kernel crate, they should do so by using absolute paths ::core::... and ::kernel::.... That is because a user of the macro can declare their own module named core or kernel, which the macro will then pick up. Some of our macros currently don't follow this rule. One such instance is in the static_assert! macro. Please search for other such instances and fix them.


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 a Link: tag to this issue. Please see https://docs.kernel.org/process/submitting-patches.html and 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.

@y86-dev y86-dev added good first issue Good for newcomers easy Expected to be an easy issue to resolve. labels Mar 24, 2025
@ojeda ojeda added the • lib Related to the `rust/` library. label Mar 24, 2025
@y86-dev
Copy link
Member Author

y86-dev commented Mar 24, 2025

We also might want to have a clippy lint for this, I quickly tried to find one, but didn't.

@ojeda
Copy link
Member

ojeda commented Mar 24, 2025

Sounds like a good idea -- in general it would be nice to do that for all crates (or at least non-leaf ones) that we are aware, i.e. I don't think we will want modules named the same way as crates -- it can get confusing fast.

@y86-dev
Copy link
Member Author

y86-dev commented Mar 24, 2025

Yeah, I was thinking that the clippy lint would report any non-absolute path inside of a macro.

@ipv6forever
Copy link

Hello @y86-dev I would like to work on the issue

@KunWuChan
Copy link

KunWuChan commented Mar 26, 2025

The 'static_assert!' is changing in 1.
And when compile with 'make ARCH=arm64 LLVM=1 CLIPPY=1 -j8', It didn't report any non-absolute path log.
Is here any thing wrong? @y86-dev

@y86-dev
Copy link
Member Author

y86-dev commented Mar 26, 2025

No, clippy doesn't yet warn about this, see rust-lang/rust-clippy#14472

ipv6forever added a commit to ipv6forever/linux that referenced this issue Mar 26, 2025
To prevent issues where user-defined modules named `core` or `kernel`
could be picked up instead of the standard ones, update macros to use
absolute paths, `::core::...` and `::kernel::...`, for core and kernel
references.

Suggested-by: y86-dev <y86-dev@protonmail.com>
Closes: Rust-for-Linux#1150
Signed-off-by: Igor Korotin <igor.korotin@yahoo.com>
@KunWuChan
Copy link

No, clippy doesn't yet warn about this, see rust-lang/rust-clippy#14472

Ok, I'll try to work on that.

@KunWuChan
Copy link

Hello @y86-dev I would like to work on the issue

Hey, @ipv6forever you should send the patch to email-list rather than github. "sign your commit under the Developer's Certificate of Origin and to add a Suggested-by: tag, and a Link: tag to this issue. "
Please see https://docs.kernel.org/process/submitting-patches.html and https://rust-for-linux.com/contributing for details.

@ipv6forever
Copy link

ipv6forever commented Mar 26, 2025

Hi @KunWuChan.
Yep, I know. I'll do it a few hours later. For now I've just pushed my changes to the github to be able to pull them on the other machine.
Thanks.

ipv6forever added a commit to ipv6forever/linux that referenced this issue Mar 28, 2025
Update macros to always use absolute paths for crates `core` and `kernel`.
This guarantees that macros will not pick up user-defined crates `core`
or `kernel` by accident.

Changes since v1:
- Fixed paths in auto-generated code.

Suggested-by: Benno Lossin <benno.lossin@proton.me>
Closes: Rust-for-Linux#1150
Signed-off-by: Igor Korotin <igor.korotin@yahoo.com>
@ipv6forever
Copy link

Hello @y86-dev

I don't get what I did wrong, but I don't see one of the letters I have sent in LKML, though I see both in my e-mail.
I'm so confused about all the procedure of patch pushing. Sorry if I screw something.

@y86-dev
Copy link
Member Author

y86-dev commented Mar 28, 2025

Not sure what you are referring to, I see both of your mails on the list. Though they are in response to my mail and not as their own thread. I'll reply with more details there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy Expected to be an easy issue to resolve. good first issue Good for newcomers • lib Related to the `rust/` library.
Development

No branches or pull requests

4 participants