Skip to contentSkip to conversation

rust: macros: allow optional trailing comma in module!

PATCH In review Eunsoo Eun 6 participants 9 messages Jun 14, 2025 – Jun 21, 2025

Subsystems (3)
lore
Share & tools
lore

Eunsoo Eun

author
#0 lore raw

PATCH 1/2 rust: macros: allow optional trailing comma in module!

From: Eunsoo Eun <[email protected]>

Make the module! macro syntax more flexible by allowing an optional trailing comma after the last field. This makes it consistent with Rust’s general syntax patterns where trailing commas are allowed in structs, arrays, and other comma-separated lists.

For example, these are now all valid:

    module! {
        type: MyModule,
        name: "mymodule",
        license: "GPL"  // No trailing comma
    }

    module! {
        type: MyModule,
        name: "mymodule",
        license: "GPL",  // With trailing comma
    }

This change also allows optional trailing commas in array fields like authors, alias, and firmware:

    module! {
        type: MyModule,
        name: "mymodule",
        authors: ["Author 1", "Author 2"],  // No trailing comma
        license: "GPL"
    }

    module! {
        type: MyModule,
        name: "mymodule",
        authors: ["Author 1", "Author 2",], // With trailing comma
        license: "GPL"
    }
---
 rust/macros/concat_idents.rs |  9 ++++++++
 rust/macros/module.rs        | 42 ++++++++++++++++++++++++++++++------
 2 files changed, 45 insertions(+), 6 deletions(-)
rust/macros/concat_idents.rs +9 -0
index 7e4b450f3a50..c139e1658b4a 100644
@@ -17,6 +17,15 @@ pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
     let a = expect_ident(&mut it);
     assert_eq!(expect_punct(&mut it), ',');
     let b = expect_ident(&mut it);
+    
+    // Check for optional trailing comma
+    if let Some(TokenTree::Punct(punct)) = it.clone().next() {
+        if punct.as_char() == ',' {
+            // Consume the trailing comma
+            it.next();
+        }
+    }
+    
     assert!(it.next().is_none(), "only two idents can be concatenated");
     let res = Ident::new(&format!("{a}{b}"), b.span());
     TokenStream::from_iter([TokenTree::Ident(res)])
rust/macros/module.rs +36 -6

55 lines not on this page · raw message

Signature · 1 line
2.49.0
author
#1 lore raw

PATCH 1/2 spi: spi-pci1xxxx: Drop MSI-X usage as unsupported by DMA engine

From: Thangaraj Samynathan <[email protected]>

Removes MSI-X from the interrupt request path, as the DMA engine used by the SPI controller does not support MSI-X interrupts.

---
 drivers/spi/spi-pci1xxxx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-pci1xxxx.c +1 -1
index 9112d8a1a0c8..e27642c4dea4 100644
@@ -762,7 +762,7 @@ static int pci1xxxx_spi_probe(struct pci_dev *pdev, const struct pci_device_id *
 				return -EINVAL;
 
 			num_vector = pci_alloc_irq_vectors(pdev, 1, hw_inst_cnt,
-							   PCI_IRQ_ALL_TYPES);
+							   PCI_IRQ_INTX | PCI_IRQ_MSI);
 			if (num_vector < 0) {
 				dev_err(&pdev->dev, "Error allocating MSI vectors\n");
 				return num_vector;
Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH 1/2] spi: spi-pci1xxxx: Drop MSI-X usage as unsupported by DMA engine

Quoted 9 lines · Eunsoo Eun

From: Thangaraj Samynathan <[email protected]>

Removes MSI-X from the interrupt request path, as the DMA engine used by the SPI controller does not support MSI-X interrupts.

For some reason this came as a "1/2" patch in the same email thread as a Rust one, and that got things confusing. This patch looks spurious/bogus, i.e. it is already in mainline, and it is not authored nor signed by you, and it is not even numbered as "2/2".

Do you know what happened?

Thanks!

Cheers,
Miguel

#3 lore raw

Re: [PATCH 1/2] spi: spi-pci1xxxx: Drop MSI-X usage as unsupported by DMA engine

Hi Miguel,

Quoted 16 lines · Miguel Ojeda

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 10 lines · Eunsoo Eun

From: Thangaraj Samynathan <[email protected]>

Removes MSI-X from the interrupt request path, as the DMA engine used by
the SPI controller does not support MSI-X interrupts.

Link:
https://patch.msgid.link/[email protected]

Quoted 9 lines

For some reason this came as a "1/2" patch in the same email thread as
a Rust one, and that got things confusing. This patch looks spurious/bogus, i.e. it is already in mainline, and it is not authored
nor signed by you, and it is not even numbered as "2/2".

Do you know what happened?

Thanks for pointing it out. There was a mistake on my end during patch generation - the patch isn't part of a series, but it was mistakenly created with an incorrect header. Apologies for the confusion, and I'll make sure to avoid this in the future.

Thanks,
Thanngaraj Samynathan

Quoted 4 lines

Thanks!

Cheers,
Miguel

#4 lore raw

Re: [PATCH 1/2] spi: spi-pci1xxxx: Drop MSI-X usage as unsupported by DMA engine

Quoted 5 lines · On Thu, Jun 19, 2025 at 5:44 AM <[email protected]> wrote:

Thanks for pointing it out. There was a mistake on my end during patch generation - the patch isn't part of a series, but it was mistakenly created with an incorrect header. Apologies for the confusion, and I'll make sure to avoid this in the future.

You're welcome, and no worries! Email/Git can be tricky sometimes :)

Cheers,
Miguel

#5 lore raw
In reply to Eunsoo Eun
Quoted 51 lines · Eunsoo Eun

From: Eunsoo Eun <[email protected]>

Make the module! macro syntax more flexible by allowing an optional trailing comma after the last field. This makes it consistent with Rust’s general syntax patterns where trailing commas are allowed in structs, arrays, and other comma-separated lists.

For example, these are now all valid:

    module! {
        type: MyModule,
        name: "mymodule",
        license: "GPL"  // No trailing comma
    }

    module! {
        type: MyModule,
        name: "mymodule",
        license: "GPL",  // With trailing comma
    }

This change also allows optional trailing commas in array fields like authors, alias, and firmware:

    module! {
        type: MyModule,
        name: "mymodule",
        authors: ["Author 1", "Author 2"],  // No trailing comma
        license: "GPL"
    }

    module! {
        type: MyModule,
        name: "mymodule",
        authors: ["Author 1", "Author 2",], // With trailing comma
        license: "GPL"
    }
---
 rust/macros/concat_idents.rs |  9 ++++++++
 rust/macros/module.rs        | 42 ++++++++++++++++++++++++++++++------
 2 files changed, 45 insertions(+), 6 deletions(-)
rust/macros/concat_idents.rs +0 -0
index 7e4b450f3a50..c139e1658b4a 100644

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

Quoted 4 lines
rust/macros/concat_idents.rs +1 -0
@@ -17,6 +17,15 @@ pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
     let a = expect_ident(&mut it);
     assert_eq!(expect_punct(&mut it), ',');
     let b = expect_ident(&mut it);
+    

We have some whitespaces here ^

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

Quoted 8 lines
rust/macros/concat_idents.rs +8 -0
+    // Check for optional trailing comma
+    if let Some(TokenTree::Punct(punct)) = it.clone().next() {
+        if punct.as_char() == ',' {
+            // Consume the trailing comma
+            it.next();
+        }
+    }
+    

Whitespaces also here ^.

Maybe you can add a new helper function for this one?

Quoted 8 lines
rust/macros/concat_idents.rs +0 -0
     assert!(it.next().is_none(), "only two idents can be concatenated");
     let res = Ident::new(&format!("{a}{b}"), b.span());
     TokenStream::from_iter([TokenTree::Ident(res)])
rust/macros/module.rs +0 -0
index 2ddd2eeb2852..d37492457be5 100644

rust/macros/module.rs fn expect_string_array(it: &mut token_stream::IntoIter) -> Vec<String> { · line 18

Quoted 10 lines
rust/macros/module.rs +3 -4
@@ -13,10 +13,27 @@ fn expect_string_array(it: &mut token_stream::IntoIter) -> Vec<String> {
     while let Some(val) = try_string(&mut it) {
         assert!(val.is_ascii(), "Expected ASCII string");
         values.push(val);
-        match it.next() {
-            Some(TokenTree::Punct(punct)) => assert_eq!(punct.as_char(), ','),
-            None => break,
-            _ => panic!("Expected ',' or end of array"),
+
+        // Check for optional trailing comma
+        match it.clone().next() {

We might be able to do something like this here,
let next_token = it.clone().next();

   match next_token {
         ...

rust/macros/module.rs fn expect_string_array(it: &mut token_stream::IntoIter) -> Vec<String> { · line 26

Quoted 8 lines
rust/macros/module.rs +8 -0
+            Some(TokenTree::Punct(punct)) if punct.as_char() == ',' => {
+                // Consume the comma
+                it.next();
+                // Check if there's another string after the comma
+                if it.clone().next().is_none() {
+                    // Trailing comma at end of array is allowed
+                    break;
+                }

Lose this, and let it check naturally?

Quoted 38 lines
rust/macros/module.rs +25 -2
+            }
+            Some(TokenTree::Literal(_)) => {
+                // Next item is a string literal, comma was required
+                panic!("Expected ',' between array elements");
+            }
+            None => {
+                // End of array, no comma needed
+                break;
+            }
+            Some(_) => panic!("Expected ',' or end of array"),
         }
     }
     values
@@ -143,9 +160,22 @@ fn parse(it: &mut token_stream::IntoIter) -> Self {
                 _ => panic!("Unknown key \"{key}\". Valid keys are: {EXPECTED_KEYS:?}."),
             }
 
-            assert_eq!(expect_punct(it), ',');
-
             seen_keys.push(key);
+
+            // Check for optional trailing comma
+            match it.clone().next() {
+                Some(TokenTree::Punct(punct)) if punct.as_char() == ',' => {
+                    // Consume the comma
+                    it.next();
+                }
+                Some(TokenTree::Ident(_)) => {
+                    // Next item is an identifier, comma was required
+                    panic!("Expected ',' between module properties");
+                }
+                _ => {
+                    // End of input or closing brace, comma is optional
+                }
+            }
         }
 
         expect_end(it);
reviewer
#6 lore raw
In reply to Eunsoo Eun

I didn't get the second patch advertised in the subject, did something go wrong when sending the patch?

Quoted 51 lines · Eunsoo Eun

From: Eunsoo Eun <[email protected]>

Make the module! macro syntax more flexible by allowing an optional trailing comma after the last field. This makes it consistent with Rust’s general syntax patterns where trailing commas are allowed in structs, arrays, and other comma-separated lists.

For example, these are now all valid:

    module! {
        type: MyModule,
        name: "mymodule",
        license: "GPL"  // No trailing comma
    }

    module! {
        type: MyModule,
        name: "mymodule",
        license: "GPL",  // With trailing comma
    }

This change also allows optional trailing commas in array fields like authors, alias, and firmware:

    module! {
        type: MyModule,
        name: "mymodule",
        authors: ["Author 1", "Author 2"],  // No trailing comma
        license: "GPL"
    }

    module! {
        type: MyModule,
        name: "mymodule",
        authors: ["Author 1", "Author 2",], // With trailing comma
        license: "GPL"
    }
---
 rust/macros/concat_idents.rs |  9 ++++++++
 rust/macros/module.rs        | 42 ++++++++++++++++++++++++++++++------
 2 files changed, 45 insertions(+), 6 deletions(-)
rust/macros/concat_idents.rs +0 -0
index 7e4b450f3a50..c139e1658b4a 100644

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

Quoted 6 lines
rust/macros/concat_idents.rs +3 -0
@@ -17,6 +17,15 @@ pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
     let a = expect_ident(&mut it);
     assert_eq!(expect_punct(&mut it), ',');
     let b = expect_ident(&mut it);
+    
+    // Check for optional trailing comma
+    if let Some(TokenTree::Punct(punct)) = it.clone().next() {

Please avoid cloning the iterator, as that is inefficient. Instead use peekable() to create an iterator with a peek function.

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

Quoted 4 lines
rust/macros/concat_idents.rs +4 -0
+        if punct.as_char() == ',' {
+            // Consume the trailing comma
+            it.next();
+        }

This allows any kind of trailing token in concat_idents, but only a comma should be allowed.

Quoted 10 lines
rust/macros/concat_idents.rs +2 -0
+    }
+    
     assert!(it.next().is_none(), "only two idents can be concatenated");
     let res = Ident::new(&format!("{a}{b}"), b.span());
     TokenStream::from_iter([TokenTree::Ident(res)])
rust/macros/module.rs +0 -0
index 2ddd2eeb2852..d37492457be5 100644

rust/macros/module.rs fn expect_string_array(it: &mut token_stream::IntoIter) -> Vec<String> { · line 18

Quoted 10 lines
rust/macros/module.rs +3 -4
@@ -13,10 +13,27 @@ fn expect_string_array(it: &mut token_stream::IntoIter) -> Vec<String> {
     while let Some(val) = try_string(&mut it) {
         assert!(val.is_ascii(), "Expected ASCII string");
         values.push(val);
-        match it.next() {
-            Some(TokenTree::Punct(punct)) => assert_eq!(punct.as_char(), ','),
-            None => break,
-            _ => panic!("Expected ',' or end of array"),
+
+        // Check for optional trailing comma
+        match it.clone().next() {

Please avoid cloning the iterator, as that is inefficient. Instead use peekable() to create an iterator with a peek function.

Quoted 31 lines
rust/macros/module.rs +21 -2
+            Some(TokenTree::Punct(punct)) if punct.as_char() == ',' => {
+                // Consume the comma
+                it.next();
+                // Check if there's another string after the comma
+                if it.clone().next().is_none() {
+                    // Trailing comma at end of array is allowed
+                    break;
+                }
+            }
+            Some(TokenTree::Literal(_)) => {
+                // Next item is a string literal, comma was required
+                panic!("Expected ',' between array elements");
+            }
+            None => {
+                // End of array, no comma needed
+                break;
+            }
+            Some(_) => panic!("Expected ',' or end of array"),
         }
     }
     values
@@ -143,9 +160,22 @@ fn parse(it: &mut token_stream::IntoIter) -> Self {
                 _ => panic!("Unknown key \"{key}\". Valid keys are: {EXPECTED_KEYS:?}."),
             }
 
-            assert_eq!(expect_punct(it), ',');
-
             seen_keys.push(key);
+
+            // Check for optional trailing comma
+            match it.clone().next() {

rust/macros/module.rs fn parse(it: &mut token_stream::IntoIter) -> Self { · line 176

Quoted 10 lines
rust/macros/module.rs +10 -0
+                Some(TokenTree::Punct(punct)) if punct.as_char() == ',' => {
+                    // Consume the comma
+                    it.next();
+                }
+                Some(TokenTree::Ident(_)) => {
+                    // Next item is an identifier, comma was required
+                    panic!("Expected ',' between module properties");
+                }
+                _ => {
+                    // End of input or closing brace, comma is optional

This also could be a new opening group or other punctuation, which would be wrong.

---
Cheers,
Benno

Quoted 5 lines
rust/macros/module.rs +2 -0
+                }
+            }
         }
 
         expect_end(it);
maintainer
#8 lore raw
In reply to Eunsoo Eun
Quoted 8 lines · Eunsoo Eun

Make the module! macro syntax more flexible by allowing an optional trailing comma after the last field. This makes it consistent with Rust’s general syntax patterns where trailing commas are allowed in structs, arrays, and other comma-separated lists.

For example, these are now all valid:

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/2] rust: macros: allow optional trailing comma in module!
(no commit info)
[1/2] spi: spi-pci1xxxx: Drop MSI-X usage as unsupported by DMA engine

      commit: 9f0ad43b158d07bc7144d219ceabdea36e28e392

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark