Skip to contentSkip to conversation

checkpatch: Prefer DEFINE_TYPES() over type_init / type_register_static

PATCH In review Philippe Mathieu-Daudé 3 participants 3 messages May 24, 2023 – May 25, 2023 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: Prefer DEFINE_TYPES() over type_init / type_register_static

When multiple QOM types are registered in the same file, it is clearer and simpler to use the the DEFINE_TYPES() macro.

Add a rule to checkpatch.pl to suggest using DEFINE_TYPES() instead of type_init() / type_register_static().

---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -0
index eeaec436eb..db8029635c 100755
@@ -2877,6 +2877,12 @@ sub process {
 		if ($line =~ /^module_init\s*\(/) {
 			ERROR("please use block_init(), type_init() etc. instead of module_init()\n" . $herecurr);
 		}
+
+# recommend DEFINE_TYPES() over type_init()/type_register_static()
+		if ($line =~ /\b(type_init|type_register_static)\(/) {
+			WARN("consider using DEFINE_TYPES() in preference to type_init()\n" . $herecurr);
+		}
+
 # check for various ops structs, ensure they are const.
 		my $struct_ops = qr{AIOCBInfo|
 				BdrvActionOps|
Signature · 1 line
2.38.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé

When multiple QOM types are registered in the same file, it is clearer and simpler to use the the DEFINE_TYPES() macro.

Add a rule to checkpatch.pl to suggest using DEFINE_TYPES() instead of type_init() / type_register_static().

---
  scripts/checkpatch.pl | 6 ++++++
  1 file changed, 6 insertions(+)

r~

Reviewed-by on v1 1/1
#2 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 6 lines · Philippe Mathieu-Daudé

When multiple QOM types are registered in the same file, it is clearer and simpler to use the the DEFINE_TYPES() macro.

Add a rule to checkpatch.pl to suggest using DEFINE_TYPES() instead of type_init() / type_register_static().

Nice!

Quoted 3 lines

---

Quoted 20 lines
  scripts/checkpatch.pl | 6 ++++++
  1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -0
index eeaec436eb..db8029635c 100755
@@ -2877,6 +2877,12 @@ sub process {
  		if ($line =~ /^module_init\s*\(/) {
  			ERROR("please use block_init(), type_init() etc. instead of module_init()\n" . $herecurr);
  		}
+
+# recommend DEFINE_TYPES() over type_init()/type_register_static()
+		if ($line =~ /\b(type_init|type_register_static)\(/) {
+			WARN("consider using DEFINE_TYPES() in preference to type_init()\n" . $herecurr);
+		}
+
  # check for various ops structs, ensure they are const.
  		my $struct_ops = qr{AIOCBInfo|
  				BdrvActionOps|