Skip to contentSkip to conversation

author field in module! macro should be a array

PATCH Applied Guilherme Giacomo Simoes 3 participants 7 messages Mar 9, 2025 – Mar 10, 2025

Subsystems (13)
lore
Share & tools
lore
#0 lore raw

v9 cover author field in module! macro should be a array

In the module! macro, the author field is currently of type String. Since modules can have multiple authors, this limitation prevents specifying more than one.

- Change the author field to Option<Vec<String>> to allow creating modules with multiple authors.

- rename the field from author to authors to make it explicit that it can refer to multiple authors.

- In modules that use the author field, update its value to an array of strings, and also rename it from author to authors.

- Change the checkpatch.pl to find poorly formatted arrays in the macro module!

---
v9 changes
- Improved english grammar.
---

Guilherme Giacomo Simoes (2):
rust: module: change author to an array
checkpatch: check format of Vec<String> in modules

 drivers/block/rnull.rs               |  2 +-
 drivers/net/phy/ax88796b_rust.rs     |  2 +-
 drivers/net/phy/qt2025.rs            |  2 +-
 rust/kernel/net/phy.rs               |  4 +-
 rust/kernel/pci.rs                   |  2 +-
 rust/kernel/platform.rs              |  2 +-
 rust/macros/lib.rs                   |  6 +--
 rust/macros/module.rs                | 12 ++---
 samples/rust/rust_driver_faux.rs     |  2 +-
 samples/rust/rust_driver_pci.rs      |  2 +-
 samples/rust/rust_driver_platform.rs |  2 +-
 samples/rust/rust_minimal.rs         |  2 +-
 samples/rust/rust_misc_device.rs     |  2 +-
 samples/rust/rust_print_main.rs      |  2 +-
 scripts/checkpatch.pl                | 67 ++++++++++++++++++++++++++++
 15 files changed, 90 insertions(+), 21 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v9 1/2 rust: module: change author to an array

In the module! macro, the author field is currently of type String. Since modules can have multiple authors, this limitation prevents specifying more than one.
Change the author field to Option<Vec<String>> to allow creating modules with multiple authors. Additionally, rename the field from author to authors to make it explicit that it can refer to multiple authors. In modules that use the author field, update its value to an array of strings, and also rename it from author to authors.

---
 drivers/block/rnull.rs               |  2 +-
 drivers/net/phy/ax88796b_rust.rs     |  2 +-
 drivers/net/phy/qt2025.rs            |  2 +-
 rust/kernel/net/phy.rs               |  4 ++--
 rust/kernel/pci.rs                   |  2 +-
 rust/kernel/platform.rs              |  2 +-
 rust/macros/lib.rs                   |  6 +++---
 rust/macros/module.rs                | 12 +++++++-----
 samples/rust/rust_driver_faux.rs     |  2 +-
 samples/rust/rust_driver_pci.rs      |  2 +-
 samples/rust/rust_driver_platform.rs |  2 +-
 samples/rust/rust_minimal.rs         |  2 +-
 samples/rust/rust_misc_device.rs     |  2 +-
 samples/rust/rust_print_main.rs      |  2 +-
 14 files changed, 23 insertions(+), 21 deletions(-)
drivers/block/rnull.rs +1 -1
index ddf3629d8894..d07e76ae2c13 100644
@@ -27,7 +27,7 @@
 module! {
     type: NullBlkModule,
     name: "rnull_mod",
-    author: "Andreas Hindborg",
+    authors: ["Andreas Hindborg"],
     description: "Rust implementation of the C null block driver",
     license: "GPL v2",
 }
drivers/net/phy/ax88796b_rust.rs +1 -1
index 8c7eb009d9fc..bc73ebccc2aa 100644
@@ -19,7 +19,7 @@
         DeviceId::new_with_driver::<PhyAX88796B>()
     ],
     name: "rust_asix_phy",
-    author: "FUJITA Tomonori <[email protected]>",
+    authors: ["FUJITA Tomonori <[email protected]>"],
     description: "Rust Asix PHYs driver",
     license: "GPL",
 }
drivers/net/phy/qt2025.rs +1 -1
index 1ab065798175..520daeb42089 100644
@@ -26,7 +26,7 @@
         phy::DeviceId::new_with_driver::<PhyQT2025>(),
     ],
     name: "qt2025_phy",
-    author: "FUJITA Tomonori <[email protected]>",
+    authors: ["FUJITA Tomonori <[email protected]>"],
     description: "AMCC QT2025 PHY driver",
     license: "GPL",
     firmware: ["qt2025-2.0.3.3.fw"],
rust/kernel/net/phy.rs +2 -2
index bb654a28dab3..a59469c785e3 100644
@@ -790,7 +790,7 @@ const fn as_int(&self) -> u32 {
 ///         DeviceId::new_with_driver::<PhySample>()
 ///     ],
 ///     name: "rust_sample_phy",
-///     author: "Rust for Linux Contributors",
+///     authors: ["Rust for Linux Contributors"],
 ///     description: "Rust sample PHYs driver",
 ///     license: "GPL",
 /// }
@@ -819,7 +819,7 @@ const fn as_int(&self) -> u32 {
 /// module! {
 ///     type: Module,
 ///     name: "rust_sample_phy",
-///     author: "Rust for Linux Contributors",
+///     authors: ["Rust for Linux Contributors"],
 ///     description: "Rust sample PHYs driver",
 ///     license: "GPL",
 /// }
rust/kernel/pci.rs +1 -1
index 4c98b5b9aa1e..f7b2743828ae 100644
@@ -103,7 +103,7 @@ extern "C" fn remove_callback(pdev: *mut bindings::pci_dev) {
 /// kernel::module_pci_driver! {
 ///     type: MyDriver,
 ///     name: "Module name",
-///     author: "Author name",
+///     authors: ["Author name"],
 ///     description: "Description",
 ///     license: "GPL v2",
 /// }
rust/kernel/platform.rs +1 -1
index 50e6b0421813..1297f5292ba9 100644
@@ -101,7 +101,7 @@ fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> {
 /// kernel::module_platform_driver! {
 ///     type: MyDriver,
 ///     name: "Module name",
-///     author: "Author name",
+///     authors: ["Author name"],
 ///     description: "Description",
 ///     license: "GPL v2",
 /// }
rust/macros/lib.rs +3 -3
index d61bc6a56425..7ce1cb891dfb 100644
@@ -36,7 +36,7 @@
 /// module!{
 ///     type: MyModule,
 ///     name: "my_kernel_module",
-///     author: "Rust for Linux Contributors",
+///     authors: ["Rust for Linux Contributors"],
 ///     description: "My very own kernel module!",
 ///     license: "GPL",
 ///     alias: ["alternate_module_name"],
@@ -69,7 +69,7 @@
 /// module!{
 ///     type: MyDeviceDriverModule,
 ///     name: "my_device_driver_module",
-///     author: "Rust for Linux Contributors",
+///     authors: ["Rust for Linux Contributors"],
 ///     description: "My device driver requires firmware",
 ///     license: "GPL",
 ///     firmware: ["my_device_firmware1.bin", "my_device_firmware2.bin"],
@@ -88,7 +88,7 @@
 /// # Supported argument types
 ///   - `type`: type which implements the [`Module`] trait (required).
 ///   - `name`: ASCII string literal of the name of the kernel module (required).
-///   - `author`: string literal of the author of the kernel module.
+///   - `authors`: array of ASCII string literals of the authors of the kernel module.
 ///   - `description`: string literal of the description of the kernel module.
 ///   - `license`: ASCII string literal of the license of the kernel module (required).
 ///   - `alias`: array of ASCII string literals of the alias names of the kernel module.
rust/macros/module.rs +7 -5
index cdf94f4982df..db16f0af0855 100644
@@ -94,7 +94,7 @@ struct ModuleInfo {
     type_: String,
     license: String,
     name: String,
-    author: Option<String>,
+    authors: Option<Vec<String>>,
     description: Option<String>,
     alias: Option<Vec<String>>,
     firmware: Option<Vec<String>>,
@@ -107,7 +107,7 @@ fn parse(it: &mut token_stream::IntoIter) -> Self {
         const EXPECTED_KEYS: &[&str] = &[
             "type",
             "name",
-            "author",
+            "authors",
             "description",
             "license",
             "alias",
@@ -135,7 +135,7 @@ fn parse(it: &mut token_stream::IntoIter) -> Self {
             match key.as_str() {
                 "type" => info.type_ = expect_ident(it),
                 "name" => info.name = expect_string_ascii(it),
-                "author" => info.author = Some(expect_string(it)),
+                "authors" => info.authors = Some(expect_string_array(it)),
                 "description" => info.description = Some(expect_string(it)),
                 "license" => info.license = expect_string_ascii(it),
                 "alias" => info.alias = Some(expect_string_array(it)),
@@ -183,8 +183,10 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
     let info = ModuleInfo::parse(&mut it);
 
     let mut modinfo = ModInfoBuilder::new(info.name.as_ref());
-    if let Some(author) = info.author {
-        modinfo.emit("author", &author);
+    if let Some(authors) = info.authors {
+        for author in authors {
+            modinfo.emit("authors", &author);
+        }
     }
     if let Some(description) = info.description {
         modinfo.emit("description", &description);
samples/rust/rust_driver_faux.rs +1 -1
index 048c6cb98b29..378bab4b587d 100644
@@ -7,7 +7,7 @@
 module! {
     type: SampleModule,
     name: "rust_faux_driver",
-    author: "Lyude Paul",
+    authors: ["Lyude Paul"],
     description: "Rust faux device sample",
     license: "GPL",
 }
samples/rust/rust_driver_pci.rs +1 -1
index 1fb6e44f3395..364a0660a743 100644
@@ -104,7 +104,7 @@ fn drop(&mut self) {
 kernel::module_pci_driver! {
     type: SampleDriver,
     name: "rust_driver_pci",
-    author: "Danilo Krummrich",
+    authors: ["Danilo Krummrich"],
     description: "Rust PCI driver",
     license: "GPL v2",
 }
samples/rust/rust_driver_platform.rs +1 -1
index 8120609e2940..f7a0f1b29d1d 100644
@@ -43,7 +43,7 @@ fn drop(&mut self) {
 kernel::module_platform_driver! {
     type: SampleDriver,
     name: "rust_driver_platform",
-    author: "Danilo Krummrich",
+    authors: ["Danilo Krummrich"],
     description: "Rust Platform driver",
     license: "GPL v2",
 }
samples/rust/rust_minimal.rs +1 -1
index 4aaf117bf8e3..1fc7a1be6b6d 100644
@@ -7,7 +7,7 @@
 module! {
     type: RustMinimal,
     name: "rust_minimal",
-    author: "Rust for Linux Contributors",
+    authors: ["Rust for Linux Contributors"],
     description: "Rust minimal sample",
     license: "GPL",
 }
samples/rust/rust_misc_device.rs +1 -1
index 40ad7266c225..d3785e7c0330 100644
@@ -116,7 +116,7 @@
 module! {
     type: RustMiscDeviceModule,
     name: "rust_misc_device",
-    author: "Lee Jones",
+    authors: ["Lee Jones"],
     description: "Rust misc device sample",
     license: "GPL",
 }
samples/rust/rust_print_main.rs +1 -1
index 7e8af5f176a3..8ea95e8c2f36 100644
@@ -8,7 +8,7 @@
 module! {
     type: RustPrint,
     name: "rust_print",
-    author: "Rust for Linux Contributors",
+    authors: ["Rust for Linux Contributors"],
     description: "Rust printing macros sample",
     license: "GPL",
 }
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH V9 1/2] rust: module: change author to an array

rust/macros/module.rs pub(crate) fn module(ts: TokenStream) -> TokenStream { · line 189

Quoted 7 lines · Guilherme Giacomo Simoes
rust/macros/module.rs +4 -2
-    if let Some(author) = info.author {
-        modinfo.emit("author", &author);
+    if let Some(authors) = info.authors {
+        for author in authors {
+            modinfo.emit("authors", &author);
+        }

I guess nobody actually tested this... :)

The modinfo key should not change -- we want to still use author, not authors, i.e. before this change:

    $ modinfo -k . -a samples/rust/rust_print.ko
    Rust for Linux Contributors

But after:

    $ modinfo -k . -a samples/rust/rust_print.ko

Anyway, I am considering applying this one with that fixed on my side, but also, to simplify conflict handling, it may be best to keep the old author field anyway working for a cycle or two (undocumented).

Guilherme: if I end up applying this, you can still send the second patch on its own, based on top of rust-next, i.e. just the checkpatch.pl one.

Cheers,
Miguel

Applied
#3 lore raw

Re: [PATCH V9 1/2] rust: module: change author to an array

In reply to Guilherme Giacomo Simoes
Quoted 10 lines · Guilherme Giacomo Simoes

In the module! macro, the author field is currently of type String. Since modules can have multiple authors, this limitation prevents specifying more than one.
Change the author field to Option<Vec<String>> to allow creating modules with multiple authors. Additionally, rename the field from author to authors to make it explicit that it can refer to multiple authors. In modules that use the author field, update its value to an array of strings, and also rename it from author to authors.

Quoted 6 lines

Applied to rust-next -- thanks everyone!

[ The modinfo key needs to still be author; otherwise, tooling
may not work properly, e.g.:

$ modinfo -k . -a samples/rust/rust_print.ko Rust for Linux Contributors

I have also kept the original author field (undocumented), so that we can drop it more easily in a kernel cycle or two.

- Miguel ]

[ Fixed modinfo key. Kept author field. Reworded message
accordingly. Updated my email. - Miguel ]

I didn't drop the Reviewed-by's -- the fix I did is a single letter change, but conceptually keeping the author field is a bigger change -- if someone disagrees, please just let me know and I will drop your tag.

Thanks!

Cheers,
Miguel

#4 lore raw

PATCH v9 2/2 checkpatch: check format of Vec<String> in modules

In reply to Guilherme Giacomo Simoes

Implement a check to ensure that the author, firmware, and alias fields of the module! macro are properly formatted.

* If the array contains more than one value, enforce vertical formatting.
* If the array contains only one value, it may be formatted on a single line

---
 scripts/checkpatch.pl | 67 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
scripts/checkpatch.pl +67 -0
index 7b28ad331742..dda89ffedd1e 100755
@@ -2775,6 +2775,12 @@ sub process {
 	$realcnt = 0;
 	$linenr = 0;
 	$fixlinenr = -1;
+
+	my %array_parse_module;
+	my $expected_spaces;
+	my $spaces;
+	my $herevet_space_add;
+
 	foreach my $line (@lines) {
 		$linenr++;
 		$fixlinenr++;
@@ -3567,6 +3573,67 @@ sub process {
 # ignore non-hunk lines and lines being removed
 		next if (!$hunk_line || $line =~ /^-/);
 
+# check if the field is about author, firmware or alias from module! macro and find malformed arrays
+		my $inline = 0;
+		my $key = "";
+		my $add_line = $line =~ /^\+/;
+
+		if ($line =~ /\b(authors|alias|firmware)\s*:\s*\[/) {
+			$inline = 1;
+			$array_parse_module{$1} = 1;
+		}
+
+		my @keys = keys %array_parse_module;
+		if (@keys) {
+			$key = $keys[0];
+		}
+
+		if (!$expected_spaces && (!$add_line && $key && !$inline)) {
+			if ($line =~ /^([\t ]+)(\s)/) {
+				$expected_spaces = $1;
+			}
+		}
+
+		if ($add_line && $key) {
+			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+
+			my $counter = () = $line =~ /"/g;
+			my $more_than_one = $counter > 2;
+			if ($more_than_one) {
+				WARN("ARRAY_MODULE_MACRO",
+				     "Prefer each array element on a separate line\n". $herevet);
+			} elsif ($inline && $line !~ /\]/ && $line !~ /,/ && $line =~ /"/) {
+				WARN("ARRAY_MODULE_MACRO",
+				     "Prefer to declare ] on the same line\n" . $herevet);
+			} elsif (!$inline && $line =~ /\]/ && $line =~ /\"/) {
+				WARN("ARRAY_MODULE_MACRO",
+				     "Prefer a new line after the last value and before ]\n" . $herevet);
+			} elsif ($inline && $line =~ /,/ && $line !~ /\]/) {
+				WARN("ARRAY_MODULE_MACRO",
+				     "Prefer a new line after [\n" . $herevet);
+			}
+
+			if ($line =~ /^\+\s*([\t ]+)(\S)/) {
+				$spaces = $1;
+				$herevet_space_add = $herevet;
+			}
+		}
+
+		if ($expected_spaces && $spaces) {
+			if (length($spaces) != length($expected_spaces)) {
+				WARN("ARRAY_MODULE_MACRO",
+					 "Prefer aligned parameters\n" . $herevet_space_add);
+			}
+
+			$spaces = undef;
+		}
+
+		#END OF ANALYZE FIELD
+		if ($line =~ /\]/) {
+			delete $array_parse_module{$key};
+			$expected_spaces = undef;
+		}
+
 #trailing whitespace
 		if ($line =~ /^\+.*\015/) {
 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
Signature · 1 line
2.34.1
maintainer
#5 lore raw

Re: [PATCH V9 2/2] checkpatch: check format of Vec<String> in modules

Quoted 7 lines · Guilherme Giacomo Simoes

Implement a check to ensure that the author, firmware, and alias fields of the module! macro are properly formatted.

* If the array contains more than one value, enforce vertical formatting.
* If the array contains only one value, it may be formatted on a single line

What happens if the patch contains more than one module?

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl sub process { · line 3581

Quoted 6 lines
scripts/checkpatch.pl +6 -0
+# check if the field is about author, firmware or alias from module! macro and find malformed arrays
+		my $inline = 0;
+		my $key = "";
+		my $add_line = $line =~ /^\+/;
+
+		if ($line =~ /\b(authors|alias|firmware)\s*:\s*\[/) {

?

scripts/checkpatch.pl sub process { · line 3623

Quoted 2 lines
scripts/checkpatch.pl +2 -0
+		if ($expected_spaces && $spaces) {
+			if (length($spaces) != length($expected_spaces)) {

spaces contains both spaces and tabs.
Why not test the strings rather than the length? Otherwise tab-space is the same length as space-tab.

scripts/checkpatch.pl

Quoted 2 lines
scripts/checkpatch.pl +2 -0
+				WARN("ARRAY_MODULE_MACRO",
+					 "Prefer aligned parameters\n" . $herevet_space_add);

Alignment to open parenthesis please.

Why is herevet_space_add more useful than herevet?

#6 lore raw

Re: [PATCH V9 2/2] checkpatch: check format of Vec<String> in modules

Quoted 1 line · Joe Perches

What happens if the patch contains more than one module?

Sincerely I do not was test this. I don't was think about when the patch contains more than one module, is a critical problem that went unnoticed by me. Thanks for noticing this.
I will make some tests for this and make some changes if neccessary.

Quoted 3 lines

spaces contains both spaces and tabs.
Why not test the strings rather than the length? Otherwise tab-space is the same length as space-tab.

You is right, we can test the string rather than length.

Quoted 1 line

Why is herevet_space_add more useful than herevet?

The $herevet_space_add store the $herevet for the added line. Otherwise, if the change is like:
authors: [
+ author_1
author_2
author_3
]
The $expected_spaces and $spaces will be filled in the "author_2" line. And the
content of $herevet will be " author_2" rather than "+ author_1".

How the rust-side patch already is merged in rust-next, I only will send a patch for this checkpatch.
I will make this changes that you suggested for me, and send a new patch.

Thanks,
Guilherme