Skip to contentSkip to conversation

KEYS: encrypted: Use designated initializers for match_table_t structs

PATCH In review Thorsten Blum 4 participants 7 messages Oct 9, 2025 – Oct 23, 2025

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

PATCH 1/1 KEYS: encrypted: Use designated initializers for match_table_t structs

Use designated initializers for 'key_format_tokens' and 'key_tokens' to allow struct fields to be reordered more easily and to improve readability.

---
 security/keys/encrypted-keys/encrypted.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
security/keys/encrypted-keys/encrypted.c +8 -8
index aef438d18da8..76a6dab2f4d2 100644
@@ -62,17 +62,17 @@ enum {
 };
 
 static const match_table_t key_format_tokens = {
-	{Opt_default, "default"},
-	{Opt_ecryptfs, "ecryptfs"},
-	{Opt_enc32, "enc32"},
-	{Opt_error, NULL}
+	{ .token = Opt_default, .pattern = "default"},
+	{ .token = Opt_ecryptfs, .pattern = "ecryptfs"},
+	{ .token = Opt_enc32, .pattern = "enc32"},
+	{ .token = Opt_error, .pattern = NULL}
 };
 
 static const match_table_t key_tokens = {
-	{Opt_new, "new"},
-	{Opt_load, "load"},
-	{Opt_update, "update"},
-	{Opt_err, NULL}
+	{ .token = Opt_new, .pattern = "new"},
+	{ .token = Opt_load, .pattern = "load"},
+	{ .token = Opt_update, .pattern = "update"},
+	{ .token = Opt_err, .pattern = NULL}
 };
 
 static bool user_decrypted_data = IS_ENABLED(CONFIG_USER_DECRYPTED_DATA);
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 2 lines · Thorsten Blum

Use designated initializers for 'key_format_tokens' and 'key_tokens' to allow struct fields to be reordered more easily

How does it improve that? The key,value pairs are surrounded by braces so we just cut and paste the lot anyway.

Quoted 1 line

and to improve readability.

I don't think I agree with this when looking through the code, especially because this is the way it's done for *every* option in the entire key subsystem. So firstly I really don't think it's helpful for only encrypted keys to be different from everything else and secondly when I read the code (as I often do to figure out what the options mean), the additional .token and .pattern just get in the way of what I'm looking for.

Regards,

James

#2 lore raw
Quoted 6 lines · James Bottomley
Quoted 2 lines · Thorsten Blum

Use designated initializers for 'key_format_tokens' and 'key_tokens' to allow struct fields to be reordered more easily

How does it improve that? The key,value pairs are surrounded by braces so we just cut and paste the lot anyway.

Using designated initializers (especially for global structs) allows the fields of struct match_token from linux/parser.h to be reordered or extended more easily, improving overall maintainability.

Quoted 9 lines
Quoted 1 line

and to improve readability.

I don't think I agree with this when looking through the code, especially because this is the way it's done for *every* option in the entire key subsystem. So firstly I really don't think it's helpful for only encrypted keys to be different from everything else and secondly when I read the code (as I often do to figure out what the options mean), the additional .token and .pattern just get in the way of what I'm looking for.

I just stumbled upon this and didn't check any other files.

I do think it helps with readability, especially for people unfamiliar with the code. With designated initializers, it's clear what each value represents without having to look up the definition of 'match_token' in linux/parser.h.

Thanks,
Thorsten

maintainer
#3 lore raw
Quoted 11 lines · Thorsten Blum
Quoted 6 lines · James Bottomley
Quoted 2 lines · Thorsten Blum

Use designated initializers for 'key_format_tokens' and 'key_tokens' to allow struct fields to be reordered more easily

How does it improve that?  The key,value pairs are surrounded by braces so we just cut and paste the lot anyway.

Using designated initializers (especially for global structs) allows the fields of struct match_token from linux/parser.h to be reordered or extended more easily, improving overall maintainability.

Why would we ever want to reorder them? The reason the ordering is {token, parser} string is because that's the nicest order to read them in.

Quoted 11 lines
Quoted 10 lines
Quoted 2 lines

and to improve readability.

I don't think I agree with this when looking through the code, especially because this is the way it's done for *every* option in the entire key subsystem.  So firstly I really don't think it's helpful for only encrypted keys to be different from everything else and secondly when I read the code (as I often do to figure out what the options mean), the additional .token and .pattern just get in the way of what I'm looking for.

Quoted 1 line

I just stumbled upon this and didn't check any other files.

jejb@lingrow:~/git/linux> git grep 'match_table_t'|wc -l 49

I'll leave it as an exercise to you to figure out how many use the style you're proposing.

There's definite advantage in uniformity and even if I accepted the readability argument, which I don't, it's too small a reason to churn nearly 50 files one at a time.

Regards,

James

maintainer
#5 lore raw
In reply to Thorsten Blum
Quoted 42 lines · Thorsten Blum

Use designated initializers for 'key_format_tokens' and 'key_tokens' to allow struct fields to be reordered more easily and to improve readability.

---
 security/keys/encrypted-keys/encrypted.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
security/keys/encrypted-keys/encrypted.c +8 -8
index aef438d18da8..76a6dab2f4d2 100644
@@ -62,17 +62,17 @@ enum {
 };
 
 static const match_table_t key_format_tokens = {
-	{Opt_default, "default"},
-	{Opt_ecryptfs, "ecryptfs"},
-	{Opt_enc32, "enc32"},
-	{Opt_error, NULL}
+	{ .token = Opt_default, .pattern = "default"},
+	{ .token = Opt_ecryptfs, .pattern = "ecryptfs"},
+	{ .token = Opt_enc32, .pattern = "enc32"},
+	{ .token = Opt_error, .pattern = NULL}
 };
 
 static const match_table_t key_tokens = {
-	{Opt_new, "new"},
-	{Opt_load, "load"},
-	{Opt_update, "update"},
-	{Opt_err, NULL}
+	{ .token = Opt_new, .pattern = "new"},
+	{ .token = Opt_load, .pattern = "load"},
+	{ .token = Opt_update, .pattern = "update"},
+	{ .token = Opt_err, .pattern = NULL}
 };
 
 static bool user_decrypted_data = IS_ENABLED(CONFIG_USER_DECRYPTED_DATA);
Signature · 1 line
2.51.0

For me this look like a "convert tuple alike initializations into struct alike initializations" type of change :-)

In a context the change would make sense. E.g., if an optional field was required.

BR, Jarkko

maintainer
#6 lore raw
Quoted 47 lines · Jarkko Sakkinen
Quoted 42 lines · Thorsten Blum

Use designated initializers for 'key_format_tokens' and 'key_tokens' to allow struct fields to be reordered more easily and to improve readability.

---
 security/keys/encrypted-keys/encrypted.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
security/keys/encrypted-keys/encrypted.c +8 -8
index aef438d18da8..76a6dab2f4d2 100644
@@ -62,17 +62,17 @@ enum {
 };
 
 static const match_table_t key_format_tokens = {
-	{Opt_default, "default"},
-	{Opt_ecryptfs, "ecryptfs"},
-	{Opt_enc32, "enc32"},
-	{Opt_error, NULL}
+	{ .token = Opt_default, .pattern = "default"},
+	{ .token = Opt_ecryptfs, .pattern = "ecryptfs"},
+	{ .token = Opt_enc32, .pattern = "enc32"},
+	{ .token = Opt_error, .pattern = NULL}
 };
 
 static const match_table_t key_tokens = {
-	{Opt_new, "new"},
-	{Opt_load, "load"},
-	{Opt_update, "update"},
-	{Opt_err, NULL}
+	{ .token = Opt_new, .pattern = "new"},
+	{ .token = Opt_load, .pattern = "load"},
+	{ .token = Opt_update, .pattern = "update"},
+	{ .token = Opt_err, .pattern = NULL}
 };
 
 static bool user_decrypted_data = IS_ENABLED(CONFIG_USER_DECRYPTED_DATA);
Signature · 1 line
2.51.0

For me this look like a "convert tuple alike initializations into struct alike initializations" type of change :-)

Quoted 2 lines

In a context the change would make sense. E.g., if an optional field was required.

If we had struct initializers I would equally nak "convert struct initializers to tuple initializers" type of change.

BR, Jarkko

#4 lore raw
In reply to James Bottomley
Quoted 9 lines · James Bottomley
Quoted 8 lines · Thorsten Blum
Quoted 6 lines · James Bottomley
Quoted 2 lines · Thorsten Blum

Use designated initializers for 'key_format_tokens' and 'key_tokens' to allow struct fields to be reordered more easily

How does it improve that?  The key,value pairs are surrounded by braces so we just cut and paste the lot anyway.

Quoted 7 lines
Quoted 3 lines

Using designated initializers (especially for global structs) allows the fields of struct match_token from linux/parser.h to be reordered or extended more easily, improving overall maintainability.

Why would we ever want to reorder them? The reason the ordering is {token, parser} string is because that's the nicest order to read them in.

I also join James regarding this. I find it fine as it is.

Consider also that there might be patches depending on this change that cannot be automatically ported to stable kernels. Then, extra work is required to find which dependencies are needed and backport them as well.

Thanks

Roberto

Quoted 26 lines
Quoted 11 lines
Quoted 9 lines
Quoted 1 line

and to improve readability.

I don't think I agree with this when looking through the code, especially because this is the way it's done for *every* option in the entire key subsystem.  So firstly I really don't think it's helpful for only encrypted keys to be different from everything else and secondly when I read the code (as I often do to figure out what the options mean), the additional .token and .pattern just get in the way of what I'm looking for.

I just stumbled upon this and didn't check any other files.

jejb@lingrow:~/git/linux> git grep 'match_table_t'|wc -l 49

I'll leave it as an exercise to you to figure out how many use the style you're proposing.

There's definite advantage in uniformity and even if I accepted the readability argument, which I don't, it's too small a reason to churn nearly 50 files one at a time.

Regards,

James