rust: clean and enable Clippy `doc_markdown` lint
Subsystems (10)
Miguel Ojeda
maintainercover rust: clean and enable Clippy `doc_markdown` lint
This is how it would look like -- I am not sure how many false positives we will get, so I marked the last commit as RFC and perhaps we just want this lint as an opt-in in e.g. W=2.
However, so far, we only got one ("KUnit"), plus a couple others that are in C side comments that were copied, and thus someone may want to keep them exactly in sync. So it seems pretty OK so far.
Another question is whether we want to commit to something like the global list in .clippy.toml.
Anyway, please take a look -- the other commits should probably be picked even if we do not enable the lint.
Thanks!
Miguel Ojeda (10):
drm/panic: add missing space
drm/panic: add missing Markdown code span
rust: alloc: add missing Markdown code spans
rust: alloc: add missing Markdown code span
rust: dma: add missing Markdown code span
rust: of: add missing Markdown code span
rust: pci: fix docs related to missing Markdown code spans
rust: platform: fix docs related to missing Markdown code spans
rust: task: add missing Markdown code spans and intra-doc links
rust: kbuild: enable doc_markdown Clippy lint
.clippy.toml | 4 ++++ Makefile | 1 + drivers/gpu/drm/drm_panic_qr.rs | 4 ++-- rust/kernel/alloc.rs | 4 ++-- rust/kernel/alloc/allocator_test.rs | 2 +- rust/kernel/dma.rs | 2 +- rust/kernel/of.rs | 2 +- rust/kernel/pci.rs | 15 +++++++++------ rust/kernel/platform.rs | 9 +++++---- rust/kernel/task.rs | 4 ++-- 10 files changed, 28 insertions(+), 19 deletions(-)
--
2.49.0
Miguel Ojeda
maintainerPATCH 1/10 drm/panic: add missing space
Add missing space in sentence.
This was found using the Clippy doc_markdown lint, which we may want to enable.
--- drivers/gpu/drm/drm_panic_qr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_panic_qr.rs +1 -1
@@ -5,7 +5,7 @@//! It is called from a panic handler, so it should't allocate memory and //! does all the work on the stack or on the provided buffers. For //! simplification, it only supports low error correction, and applies the -//! first mask (checkerboard). It will draw the smallest QRcode that can +//! first mask (checkerboard). It will draw the smallest QR code that can //! contain the string passed as parameter. To get the most compact //! QR code, the start of the URL is encoded as binary, and the //! compressed kmsg is encoded as numeric.
Signature · 1 line
2.49.0
Re: [PATCH 01/10] drm/panic: add missing space
Quoted 4 lines · Miguel Ojeda
Add missing space in sentence.
This was found using the Clippy
doc_markdownlint, which we may want to enable.
Thanks, it looks good to me.
Quoted 20 lines
Fixes cb5164ac43d0 ("drm/panic: Add a QR code panic screen")Signed-off-by Miguel Ojeda <[email protected]>--- drivers/gpu/drm/drm_panic_qr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_panic_qr.rs +1
-1@@ -5,7 +5,7 @@//! It is called from a panic handler, so it should't allocate memory and //! does all the work on the stack or on the provided buffers. For //! simplification, it only supports low error correction, and applies the -//! first mask (checkerboard). It will draw the smallest QRcode that can +//! first mask (checkerboard). It will draw the smallest QR code that can //! contain the string passed as parameter. To get the most compact //! QR code, the start of the URL is encoded as binary, and the //! compressed kmsg is encoded as numeric.
Miguel Ojeda
maintainerPATCH 2/10 drm/panic: add missing Markdown code span
In reply to Miguel OjedaAdd missing Markdown code span.
This was found using the Clippy doc_markdown lint, which we may want to enable.
--- drivers/gpu/drm/drm_panic_qr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_panic_qr.rs +1 -1
@@ -914,7 +914,7 @@ fn draw_all(&mut self, data: impl Iterator<Item = u8>) {/// will be encoded as binary segment, otherwise it will be encoded /// efficiently as a numeric segment, and appended to the URL. /// * `data_len`: Length of the data, that needs to be encoded, must be less -/// than data_size. +/// than `data_size`. /// * `data_size`: Size of data buffer, it should be at least 4071 bytes to hold /// a V40 QR code. It will then be overwritten with the QR code image. /// * `tmp`: A temporary buffer that the QR code encoder will use, to write the
Signature · 1 line
2.49.0
Re: [PATCH 02/10] drm/panic: add missing Markdown code span
Quoted 4 lines · Miguel Ojeda
Add missing Markdown code span.
This was found using the Clippy
doc_markdownlint, which we may want to enable.
Thanks, it looks good to me.
You want to take the whole series in the rust tree?
Otherwise I can push the patch 1-2 to drm-misc-next if needed.
Signature · 1 line
Jocelyn
Quoted 20 lines
Fixes cb5164ac43d0 ("drm/panic: Add a QR code panic screen")Signed-off-by Miguel Ojeda <[email protected]>--- drivers/gpu/drm/drm_panic_qr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_panic_qr.rs +1
-1@@ -914,7 +914,7 @@ fn draw_all(&mut self, data: impl Iterator<Item = u8>) {/// will be encoded as binary segment, otherwise it will be encoded /// efficiently as a numeric segment, and appended to the URL. /// * `data_len`: Length of the data, that needs to be encoded, must be less -/// than data_size. +/// than `data_size`. /// * `data_size`: Size of data buffer, it should be at least 4071 bytes to hold /// a V40 QR code. It will then be overwritten with the QR code image. /// * `tmp`: A temporary buffer that the QR code encoder will use, to write the
Re: [PATCH 02/10] drm/panic: add missing Markdown code span
Quoted 8 lines · Jocelyn Falempe
Thanks, it looks good to me.
Reviewed-by Jocelyn Falempe <[email protected]>You want to take the whole series in the rust tree?
Otherwise I can push the patch 1-2 to drm-misc-next if needed.
Please take them if possible, since others may want to take them through their tree anyway, plus it should have less conflicts if you change other bits, plus these are independent fixes anyway that can go in on their own whether or not the lint gets eventually enabled.
Thanks!
Cheers,
Miguel
Re: [PATCH 02/10] drm/panic: add missing Markdown code span
Quoted 6 lines · Miguel Ojeda
Quoted 5 lines · Jocelyn Falempe
Thanks, it looks good to me.
Reviewed-by Jocelyn Falempe <[email protected]>
Quoted 8 lines
Quoted 3 lines
You want to take the whole series in the rust tree?
Otherwise I can push the patch 1-2 to drm-misc-next if needed.
Please take them if possible, since others may want to take them through their tree anyway, plus it should have less conflicts if you change other bits, plus these are independent fixes anyway that can go in on their own whether or not the lint gets eventually enabled.
I just pushed 1-2 to drm-misc-next
Thanks,
Signature · 1 line
Jocelyn
Quoted 6 lines
Thanks!
Cheers,
Miguel
Miguel Ojeda
maintainerPATCH 3/10 rust: alloc: add missing Markdown code spans
In reply to Miguel OjedaAdd missing Markdown code spans.
This was found using the Clippy doc_markdown lint, which we may want to enable.
--- rust/kernel/alloc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
rust/kernel/alloc.rs +2 -2
@@ -94,10 +94,10 @@ pub mod flags {/// /// A lower watermark is applied to allow access to "atomic reserves". The current /// implementation doesn't support NMI and few other strict non-preemptive contexts (e.g. -/// raw_spin_lock). The same applies to [`GFP_NOWAIT`]. +/// `raw_spin_lock`). The same applies to [`GFP_NOWAIT`]. pub const GFP_ATOMIC :Flags =Flags (bindings::GFP_ATOMIC ); -/// Typical for kernel-internal allocations. The caller requires ZONE_NORMAL or a lower zone +/// Typical for kernel-internal allocations. The caller requires `ZONE_NORMAL` or a lower zone /// for direct access but can direct reclaim. pub const GFP_KERNEL :Flags =Flags (bindings::GFP_KERNEL );
Signature · 1 line
2.49.0
Miguel Ojeda
maintainerPATCH 4/10 rust: alloc: add missing Markdown code span
In reply to Miguel OjedaAdd missing Markdown code span.
This was found using the Clippy doc_markdown lint, which we may want to enable.
--- rust/kernel/alloc/allocator_test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/alloc/allocator_test.rs +1 -1
@@ -4,7 +4,7 @@//! of those types (e.g. `CString`) use kernel allocators for instantiation. //! //! In order to allow userspace test cases to make use of such types as well, implement the -//! `Cmalloc` allocator within the allocator_test module and type alias all kernel allocators to +//! `Cmalloc` allocator within the `allocator_test` module and type alias all kernel allocators to //! `Cmalloc`. The `Cmalloc` allocator uses libc's `realloc()` function as allocator backend. #![allow(missing_docs)]
Signature · 1 line
2.49.0
Miguel Ojeda
maintainerPATCH 5/10 rust: dma: add missing Markdown code span
In reply to Miguel OjedaAdd missing Markdown code span.
This was found using the Clippy doc_markdown lint, which we may want to enable.
--- rust/kernel/dma.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/dma.rs +1 -1
@@ -94,7 +94,7 @@ pub mod attrs {pub const DMA_ATTR_ALLOC_SINGLE_PAGES :Attrs =Attrs (bindings::DMA_ATTR_ALLOC_SINGLE_PAGES );/// This tells the DMA-mapping subsystem to suppress allocation failure reports (similarly to -/// __GFP_NOWARN). +/// `__GFP_NOWARN`). pub const DMA_ATTR_NO_WARN :Attrs =Attrs (bindings::DMA_ATTR_NO_WARN );/// Used to indicate that the buffer is fully accessible at an elevated privilege level (and
Signature · 1 line
2.49.0
Miguel Ojeda
maintainerPATCH 6/10 rust: of: add missing Markdown code span
In reply to Miguel OjedaAdd missing Markdown code span.
This was found using the Clippy doc_markdown lint, which we may want to enable.
--- rust/kernel/of.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/of.rs +1 -1
@@ -4,7 +4,7 @@use crate ::{bindings, device_id::RawDeviceId , prelude::*}; -/// IdTable type for OF drivers. +/// `IdTable` type for OF drivers. pub type IdTable <T > = &'staticdyn kernel::device_id::IdTable <DeviceId ,T >;/// An open firmware device id.
Signature · 1 line
2.49.0
Miguel Ojeda
maintainerPATCH 7/10 rust: pci: fix docs related to missing Markdown code spans
In reply to Miguel OjedaIn particular:
- Add missing Markdown code spans.
- Improve title for DeviceId, adding a link to the struct in the C side, rather than referring to bindings::.
- Convert TODO from documentation to a normal comment, and put code in block.
This was found using the Clippy doc_markdown lint, which we may want to enable.
--- rust/kernel/pci.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
rust/kernel/pci.rs +9 -6
@@ -115,7 +115,9 @@ macro_rules! module_pci_driver { }; } -/// Abstraction for bindings::pci_device_id. +/// Abstraction for the PCI device ID structure ([`pci_device_id`]). +/// +/// [`pci_device_id`]: https://docs.kernel.org/PCI/pci.html#c.pci_device_id #[repr(transparent)] #[derive( Clone , Copy )] pub struct DeviceId (bindings::pci_device_id );
@@ -170,7 +172,7 @@ fn index(&self) -> usize { } } -/// IdTable type for PCI +/// `IdTable` type for PCI. pub type IdTable <T > = &'staticdyn kernel::device_id::IdTable <DeviceId ,T >;/// Create a PCI `IdTable` with its alias for modpost.
@@ -221,10 +223,11 @@ macro_rules! pci_device_table {/// `Adapter` documentation for an example. pub trait Driver {/// The type holding information about each device id supported by the driver. -/// -/// TODO: Use associated_type_defaults once stabilized: -/// -/// type IdInfo: 'static = (); +// TODO: Use `associated_type_defaults` once stabilized: +// +// ``` +// type IdInfo: 'static = (); +// ``` type IdInfo : 'static;/// The table of device ids supported by the driver.
--
2.49.0
Re: [PATCH 07/10] rust: pci: fix docs related to missing Markdown code spans
rust/kernel/pci.rs macro_rules! module_pci_driver { · line 118
Quoted 10 lines · Miguel Ojeda
rust/kernel/pci.rs +1
-1@@ -115,7 +115,9 @@ macro_rules! module_pci_driver { }; } -/// Abstraction for bindings::pci_device_id. +/// Abstraction for the PCI device ID structure ([`pci_device_id`]).
Wouldn't "([struct pci_device_id])" make more sense?
---
Cheers,
Benno
Quoted 5 lines
rust/kernel/pci.rs +2
-0+/// +/// [`pci_device_id`]: https://docs.kernel.org/PCI/pci.html#c.pci_device_id #[repr(transparent)] #[derive( Clone , Copy )] pub struct DeviceId (bindings::pci_device_id );
Re: [PATCH 07/10] rust: pci: fix docs related to missing Markdown code spans
Quoted 2 lines · Benno Lossin
Wouldn't "([
struct pci_device_id])" make more sense?
Yeah, definitely, it should have the struct to be consistent with our usual style.
Cheers,
Miguel
Miguel Ojeda
maintainerPATCH 8/10 rust: platform: fix docs related to missing Markdown code spans
In reply to Miguel OjedaConvert TODO from documentation to a normal comment, and put code in block.
This was found using the Clippy doc_markdown lint, which we may want to enable.
--- rust/kernel/platform.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
rust/kernel/platform.rs +5 -4
@@ -147,10 +147,11 @@ macro_rules! module_platform_driver {///``` pub trait Driver {/// The type holding driver private data about each device id supported by the driver. -/// -/// TODO: Use associated_type_defaults once stabilized: -/// -/// type IdInfo: 'static = (); +// TODO: Use associated_type_defaults once stabilized: +// +// ``` +// type IdInfo: 'static = (); +// ``` type IdInfo : 'static;/// The table of OF device ids supported by the driver.
--
2.49.0
Miguel Ojeda
maintainerPATCH 9/10 rust: task: add missing Markdown code spans and intra-doc links
In reply to Miguel OjedaAdd missing Markdown code spans and also convert them into intra-doc links.
This was found using the Clippy doc_markdown lint, which we may want to enable.
--- rust/kernel/task.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
rust/kernel/task.rs +2 -2
@@ -156,10 +156,10 @@ fn deref(&self) -> &Self::Target { } } -/// Returns a PidNamespace reference for the currently executing task's/thread's pid namespace. +/// Returns a [`PidNamespace`] reference for the currently executing task's/thread's pid namespace. /// /// This function can be used to create an unbounded lifetime by e.g., storing the returned -/// PidNamespace in a global variable which would be a bug. So the recommended way to get the +/// [`PidNamespace`] in a global variable which would be a bug. So the recommended way to get the /// current task's/thread's pid namespace is to use the [`current_pid_ns`] macro because it is /// safe. ///
Signature · 1 line
2.49.0
Miguel Ojeda
maintainerRFC PATCH 10/10 rust: kbuild: enable `doc_markdown` Clippy lint
In reply to Miguel OjedaClippy supports the doc_markdown lint [1] since 2016 [2]:
Checks for the presence of _, :: or camel-case words outside ticks in documentation.
It is a very common note in Linux kernel reviews to mention that documentation is missing a Markdown code span, e.g.:
/// Length of the data must be less than data_size.
should have been:
/// Length of the data must be less than `data_size`.
This lint can identify some of those cases automatically for us.
It also caught for us other typos or mis-documentation, such as a missing code block.
Thus enable it, now that the tree is sufficiently clean.
Relatedly, it would be nice to have something similar [3] even for comments (not just documentation), as well as for possible intra-doc links (which should also have less false positives).
--- .clippy.toml | 4 ++++ Makefile | 1 + 2 files changed, 5 insertions(+)
.clippy.toml +4 -0
@@ -9,3 +9,7 @@ disallowed-macros = [ # it here, see: https://github.com/rust-lang/rust-clippy/issues/11303. { path = "kernel::dbg", reason = "the `dbg!` macro is intended as a debugging tool" }, ] + +doc-valid-idents = [ + "KUnit", +]
Makefile +1 -0
@@ -477,6 +477,7 @@ export rust_common_flags := --edition=2021 \ -Wrust_2018_idioms \ -Wunreachable_pub \ -Wclippy::all \ + -Wclippy::doc_markdown \ -Wclippy::ignored_unit_patterns \ -Wclippy::mut_mut \ -Wclippy::needless_bitwise_bool \
--
2.49.0
Quoted 3 lines · Miguel Ojeda
This is how it would look like -- I am not sure how many false positives we will get, so I marked the last commit as RFC and perhaps we just want this lint as an opt-in in e.g.
W=2.
I think we should try. If it's too much trouble, we can disable it again.
Quoted 6 lines
However, so far, we only got one ("KUnit"), plus a couple others that are in C side comments that were copied, and thus someone may want to keep them exactly in sync. So it seems pretty OK so far.
Another question is whether we want to commit to something like the global list in
.clippy.toml.
Not sure what you mean by this, but I think we need some way to disable it for some acronyms.
Quoted 2 lines
Anyway, please take a look -- the other commits should probably be picked even if we do not enable the lint.
For the entire series:
---
Cheers,
Benno
Quoted 28 lines
Thanks!
Miguel Ojeda (10):
drm/panic: add missing space
drm/panic: add missing Markdown code span
rust: alloc: add missing Markdown code spans
rust: alloc: add missing Markdown code span
rust: dma: add missing Markdown code span
rust: of: add missing Markdown code span
rust: pci: fix docs related to missing Markdown code spans
rust: platform: fix docs related to missing Markdown code spans
rust: task: add missing Markdown code spans and intra-doc links
rust: kbuild: enabledoc_markdownClippy lint.clippy.toml | 4 ++++ Makefile | 1 + drivers/gpu/drm/drm_panic_qr.rs | 4 ++-- rust/kernel/alloc.rs | 4 ++-- rust/kernel/alloc/allocator_test.rs | 2 +- rust/kernel/dma.rs | 2 +- rust/kernel/of.rs | 2 +- rust/kernel/pci.rs | 15 +++++++++------ rust/kernel/platform.rs | 9 +++++---- rust/kernel/task.rs | 4 ++-- 10 files changed, 28 insertions(+), 19 deletions(-)--
2.49.0
Quoted 3 lines · Benno Lossin
Not sure what you mean by this, but I think we need some way to disable it for some acronyms.
I meant that maintaining the list in that file (i.e. globally) could be a bit painful if we get a lot of terms, but I guess we can find workarounds for that if it gets bad.
Quoted 1 line
Reviewed-by Benno Lossin <[email protected]>
Thanks!
Cheers,
Miguel
Quoted 8 lines · Miguel Ojeda
Quoted 3 lines · Benno Lossin
Not sure what you mean by this, but I think we need some way to disable it for some acronyms.
I meant that maintaining the list in that file (i.e. globally) could be a bit painful if we get a lot of terms, but I guess we can find workarounds for that if it gets bad.
I think we can just see if it's a problem. If we keep each term on its own line, merging should be easy.
---
Cheers,
Benno
Quoted 8 lines · Miguel Ojeda
rust: alloc: add missing Markdown code spans
rust: alloc: add missing Markdown code span
rust: dma: add missing Markdown code span
rust: of: add missing Markdown code span
rust: pci: fix docs related to missing Markdown code spans
rust: platform: fix docs related to missing Markdown code spans
rust: task: add missing Markdown code spans and intra-doc links
Abdiel, Danilo, Rob, Saravana, Greg, Rafael: anything against me picking these ones up?
If you would like to pick them up through your respective trees, then that is great too.
Thanks!
Cheers,
Miguel
Quoted 10 lines · Miguel Ojeda
Quoted 8 lines · Miguel Ojeda
rust: alloc: add missing Markdown code spans
rust: alloc: add missing Markdown code span
rust: dma: add missing Markdown code span
rust: of: add missing Markdown code span
rust: pci: fix docs related to missing Markdown code spans
rust: platform: fix docs related to missing Markdown code spans
rust: task: add missing Markdown code spans and intra-doc links
Quoted 2 lines
Abdiel, Danilo, Rob, Saravana, Greg, Rafael: anything against me picking these ones up?
No objection from me for you to take these through the rust tree:
Quoted 10 lines · Miguel Ojeda
Quoted 8 lines · Miguel Ojeda
rust: alloc: add missing Markdown code spans
rust: alloc: add missing Markdown code span
rust: dma: add missing Markdown code span
rust: of: add missing Markdown code span
rust: pci: fix docs related to missing Markdown code spans
rust: platform: fix docs related to missing Markdown code spans
rust: task: add missing Markdown code spans and intra-doc links
Quoted 2 lines
Abdiel, Danilo, Rob, Saravana, Greg, Rafael: anything against me picking these ones up?
Miguel Ojeda
AppliedQuoted 7 lines · Miguel Ojeda
rust: alloc: add missing Markdown code spans
rust: alloc: add missing Markdown code span
rust: dma: add missing Markdown code span
rust: pci: fix docs related to missing Markdown code spans
rust: platform: fix docs related to missing Markdown code spans
rust: task: add missing Markdown code spans and intra-doc links
Applied to rust-next-- thanks everyone!
I picked the ones Acked by Greg and Danilo (thanks!), plus Jocelyn picked the drm/panic ones a while ago. So now only the of one is pending, but there are new cases coming, so I may send another version of the series to clean them and possibly enable the lint.
Cheers,
Miguel