[PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3

Jan Beulich posted 1 patch 5 months ago
Failed in applying to current master (apply log)
There is a newer version of this series
[PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Posted by Jan Beulich 5 months ago
The rule demands that all array elements be initialized (or dedicated
initializers be used). Introduce a small set of macros to allow doing so
without unduly affecting use sites (in particular in terms of how many
elements .matches[] actually has; right now there's no use of
DMI_MATCH4(), so we could even consider reducing the array size to 3).

Note that DMI_MATCH() needs adjustment because of the comma included in
its expansion, which - due to being unparenthesized - would otherwise
cause macro arguments in the "further replacement" step to be wrong.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
Of course a question is how many of these DMI table entries are in fact
no longer applicable (e.g. because of naming 32-bit-only systems).
Subsequently the table in dmi_scan.c itself may want cleaning up as
well, yet I guess the question of stale entries is even more relevant
there.

An alternative to using the compound literal approach might be to go
along the lines of

#define DMI_MATCH4(m1, m2, m3, m4) .matches = { [0] = m1, [1] = m2, [2] = m3, [3] = m4 }

I've chosen the other approach mainly because of being slightly shorter.

--- a/xen/arch/x86/genapic/bigsmp.c
+++ b/xen/arch/x86/genapic/bigsmp.c
@@ -19,11 +19,14 @@ static int __init cf_check force_bigsmp(
 
 
 static const struct dmi_system_id __initconstrel bigsmp_dmi_table[] = {
-	{ force_bigsmp, "UNISYS ES7000-ONE", {
-		DMI_MATCH(DMI_PRODUCT_NAME, "ES7000-ONE")
-	 }},
+	{
+	    .ident = "UNISYS ES7000-ONE",
+	    .callback = force_bigsmp,
+	    DMI_MATCH1(
+		DMI_MATCH(DMI_PRODUCT_NAME, "ES7000-ONE")),
+	},
 	
-	 { }
+	{ }
 };
 
 
--- a/xen/arch/x86/hvm/quirks.c
+++ b/xen/arch/x86/hvm/quirks.c
@@ -36,42 +36,37 @@ static int __init cf_check check_port80(
         {
             .callback = dmi_hvm_deny_port80,
             .ident    = "Compaq Presario V6000",
-            .matches  = {
+	    DMI_MATCH2(
                 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
-                DMI_MATCH(DMI_BOARD_NAME,   "30B7")
-            }
+                DMI_MATCH(DMI_BOARD_NAME,   "30B7")),
         },
         {
             .callback = dmi_hvm_deny_port80,
             .ident    = "HP Pavilion dv9000z",
-            .matches  = {
+	    DMI_MATCH2(
                 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
-                DMI_MATCH(DMI_BOARD_NAME,   "30B9")
-            }
+                DMI_MATCH(DMI_BOARD_NAME,   "30B9")),
         },
         {
             .callback = dmi_hvm_deny_port80,
             .ident    = "HP Pavilion dv6000",
-            .matches  = {
+	    DMI_MATCH2(
                 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
-                DMI_MATCH(DMI_BOARD_NAME,   "30B8")
-            }
+                DMI_MATCH(DMI_BOARD_NAME,   "30B8")),
         },
         {
             .callback = dmi_hvm_deny_port80,
             .ident    = "HP Pavilion tx1000",
-            .matches  = {
+	    DMI_MATCH2(
                 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
-                DMI_MATCH(DMI_BOARD_NAME,   "30BF")
-            }
+                DMI_MATCH(DMI_BOARD_NAME,   "30BF")),
         },
         {
             .callback = dmi_hvm_deny_port80,
             .ident    = "Presario F700",
-            .matches  = {
+	    DMI_MATCH2(
                 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
-                DMI_MATCH(DMI_BOARD_NAME,   "30D3")
-            }
+                DMI_MATCH(DMI_BOARD_NAME,   "30D3")),
         },
         { }
     };
--- a/xen/arch/x86/ioport_emulate.c
+++ b/xen/arch/x86/ioport_emulate.c
@@ -43,59 +43,51 @@ static const struct dmi_system_id __init
      */
     {
         .ident = "HP ProLiant DL3xx",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL3"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL3")),
     },
     {
         .ident = "HP ProLiant DL5xx",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL5"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL5")),
     },
     {
         .ident = "HP ProLiant DL7xx",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL7"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL7")),
     },
     {
         .ident = "HP ProLiant ML3xx",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant ML3"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant ML3")),
     },
     {
         .ident = "HP ProLiant ML5xx",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant ML5"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant ML5")),
     },
     {
         .ident = "HP ProLiant BL2xx",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL2"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL2")),
     },
     {
         .ident = "HP ProLiant BL4xx",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL4"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL4")),
     },
     {
         .ident = "HP ProLiant BL6xx",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL6"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL6")),
     },
     { }
 };
--- a/xen/arch/x86/shutdown.c
+++ b/xen/arch/x86/shutdown.c
@@ -187,348 +187,310 @@ static const struct dmi_system_id __init
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell E520",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Dell DM061"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Dell DM061")),
     },
     {    /* Handle problems with rebooting on Dell 1300's */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell PowerEdge 1300",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1300/"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1300/")),
     },
     {    /* Handle problems with rebooting on Dell 300's */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell PowerEdge 300",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 300/"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 300/")),
     },
     {    /* Handle problems with rebooting on Dell Optiplex 745's SFF */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell OptiPlex 745",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745")),
     },
     {    /* Handle problems with rebooting on Dell Optiplex 745's DFF */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell OptiPlex 745",
-        .matches = {
+        DMI_MATCH3(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
             DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"),
-            DMI_MATCH(DMI_BOARD_NAME, "0MM599"),
-        },
+            DMI_MATCH(DMI_BOARD_NAME, "0MM599")),
     },
     {    /* Handle problems with rebooting on Dell Optiplex 745 with 0KW626 */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell OptiPlex 745",
-        .matches = {
+        DMI_MATCH3(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
             DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"),
-            DMI_MATCH(DMI_BOARD_NAME, "0KW626"),
-        },
+            DMI_MATCH(DMI_BOARD_NAME, "0KW626")),
     },
     {    /* Handle problems with rebooting on Dell Optiplex 330 with 0KP561 */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell OptiPlex 330",
-        .matches = {
+        DMI_MATCH3(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
             DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 330"),
-            DMI_MATCH(DMI_BOARD_NAME, "0KP561"),
-        },
+            DMI_MATCH(DMI_BOARD_NAME, "0KP561")),
     },
     {    /* Handle problems with rebooting on Dell Optiplex 360 with 0T656F */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell OptiPlex 360",
-        .matches = {
+        DMI_MATCH3(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
             DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 360"),
-            DMI_MATCH(DMI_BOARD_NAME, "0T656F"),
-        },
+            DMI_MATCH(DMI_BOARD_NAME, "0T656F")),
     },
     {    /* Handle problems with rebooting on Dell OptiPlex 760 with 0G919G */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell OptiPlex 760",
-        .matches = {
+        DMI_MATCH3(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
             DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 760"),
-            DMI_MATCH(DMI_BOARD_NAME, "0G919G"),
-        },
+            DMI_MATCH(DMI_BOARD_NAME, "0G919G")),
     },
     {    /* Handle problems with rebooting on Dell 2400's */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell PowerEdge 2400",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2400"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2400")),
     },
     {    /* Handle problems with rebooting on Dell T5400's */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell Precision T5400",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T5400"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T5400")),
     },
     {    /* Handle problems with rebooting on Dell T7400's */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell Precision T7400",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T7400"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T7400")),
     },
     {    /* Handle problems with rebooting on HP laptops */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "HP Compaq Laptop",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq")),
     },
     {    /* Handle problems with rebooting on Dell XPS710 */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell XPS710",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Dell XPS710"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Dell XPS710")),
     },
     {    /* Handle problems with rebooting on Dell DXP061 */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Dell DXP061",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Dell DXP061"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Dell DXP061")),
     },
     {    /* Handle problems with rebooting on Sony VGN-Z540N */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Sony VGN-Z540N",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "VGN-Z540N"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "VGN-Z540N")),
     },
     {    /* Handle problems with rebooting on ASUS P4S800 */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "ASUS P4S800",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
-            DMI_MATCH(DMI_BOARD_NAME, "P4S800"),
-        },
+            DMI_MATCH(DMI_BOARD_NAME, "P4S800")),
     },
     {    /* Handle reboot issue on Acer Aspire one */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_KBD,
         .ident = "Acer Aspire One A110",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
-            DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "AOA110")),
     },
     {    /* Handle problems with rebooting on Apple MacBook5 */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Apple MacBook5",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5")),
     },
     {    /* Handle problems with rebooting on Apple MacBookPro5 */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Apple MacBookPro5",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5")),
     },
     {    /* Handle problems with rebooting on Apple Macmini3,1 */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Apple Macmini3,1",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Macmini3,1"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Macmini3,1")),
     },
     {    /* Handle problems with rebooting on the iMac9,1. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Apple iMac9,1",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "iMac9,1"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "iMac9,1")),
     },
     {    /* Handle problems with rebooting on the Latitude E6320. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell Latitude E6320",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6320"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6320")),
     },
     {    /* Handle problems with rebooting on the Latitude E5420. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell Latitude E5420",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5420"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5420")),
     },
     {       /* Handle problems with rebooting on the Latitude E6220. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell Latitude E6220",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6220"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6220")),
     },
     {    /* Handle problems with rebooting on the Latitude E6420. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell Latitude E6420",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6420"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6420")),
     },
     {    /* Handle problems with rebooting on the OptiPlex 990. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell OptiPlex 990",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 990"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 990")),
     },
     {    /* Handle problems with rebooting on the Precision M6600. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell OptiPlex 990",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Precision M6600"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Precision M6600")),
     },
     {    /* Handle problems with rebooting on the Latitude E6520. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell Latitude E6520",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6520"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6520")),
     },
     {       /* Handle problems with rebooting on the OptiPlex 790. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell OptiPlex 790",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 790"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 790")),
     },
     {    /* Handle problems with rebooting on the OptiPlex 990. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell OptiPlex 990",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 990"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 990")),
     },
     {    /* Handle problems with rebooting on the OptiPlex 390. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell OptiPlex 390",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 390"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 390")),
     },
     {    /* Handle problems with rebooting on Dell OptiPlex 9020. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_ACPI,
         .ident = "Dell OptiPlex 9020",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 9020"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 9020")),
     },
     {    /* Handle problems with rebooting on the Latitude E6320. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell Latitude E6320",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6320"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6320")),
     },
     {    /* Handle problems with rebooting on the Latitude E6420. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell Latitude E6420",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6420"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6420")),
     },
     {    /* Handle problems with rebooting on the Latitude E6520. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_CF9,
         .ident = "Dell Latitude E6520",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6520"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6520")),
     },
     {    /* Handle problems with rebooting on Dell PowerEdge R540. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_ACPI,
         .ident = "Dell PowerEdge R540",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R540"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R540")),
     },
     {    /* Handle problems with rebooting on Dell PowerEdge R740. */
         .callback = override_reboot,
         .driver_data = (void *)(long)BOOT_ACPI,
         .ident = "Dell PowerEdge R740",
-        .matches = {
+        DMI_MATCH2(
             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
-            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R740"),
-        },
+            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R740")),
     },
     { }
 };
--- a/xen/arch/x86/x86_64/mmconf-fam10h.c
+++ b/xen/arch/x86/x86_64/mmconf-fam10h.c
@@ -188,9 +188,8 @@ void fam10h_check_enable_mmcfg(void)
 static const struct dmi_system_id __initconstrel mmconf_dmi_table[] = {
 	{
 		.ident = "Sun Microsystems Machine",
-		.matches = {
-			DMI_MATCH(DMI_SYS_VENDOR, "Sun Microsystems"),
-		},
+		DMI_MATCH1(
+			DMI_MATCH(DMI_SYS_VENDOR, "Sun Microsystems")),
 	},
 	{}
 };
--- a/xen/include/xen/dmi.h
+++ b/xen/include/xen/dmi.h
@@ -30,7 +30,12 @@ struct dmi_system_id {
 	void *driver_data;
 };
 
-#define DMI_MATCH(a,b)	{ a, b }
+#define DMI_MATCH(a,b)	((struct dmi_strmatch){ a, b })
+
+#define DMI_MATCH4(m1, m2, m3, m4) .matches = { m1, m2, m3, m4 }
+#define DMI_MATCH3(m1, m2, m3) DMI_MATCH4(m1, m2, m3, DMI_MATCH(0, NULL))
+#define DMI_MATCH2(m1, m2)     DMI_MATCH3(m1, m2, DMI_MATCH(0, NULL))
+#define DMI_MATCH1(m1)         DMI_MATCH2(m1, DMI_MATCH(0, NULL))
 
 extern int dmi_check_system(const struct dmi_system_id *list);
 extern void dmi_scan_machine(void);
Re: [PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Posted by Jan Beulich 5 months ago
On 30.11.2023 08:55, Jan Beulich wrote:
> The rule demands that all array elements be initialized (or dedicated
> initializers be used). Introduce a small set of macros to allow doing so
> without unduly affecting use sites (in particular in terms of how many
> elements .matches[] actually has; right now there's no use of
> DMI_MATCH4(), so we could even consider reducing the array size to 3).
> 
> Note that DMI_MATCH() needs adjustment because of the comma included in
> its expansion, which - due to being unparenthesized - would otherwise
> cause macro arguments in the "further replacement" step to be wrong.

Sadly this doesn't work with older gcc (4.8.5 is what I had an issue with,
complaining "initializer element is not constant").

Jan
Re: [PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Posted by Nicola Vetrini 4 months, 3 weeks ago
On 2023-11-30 15:56, Jan Beulich wrote:
> On 30.11.2023 08:55, Jan Beulich wrote:
>> The rule demands that all array elements be initialized (or dedicated
>> initializers be used). Introduce a small set of macros to allow doing 
>> so
>> without unduly affecting use sites (in particular in terms of how many
>> elements .matches[] actually has; right now there's no use of
>> DMI_MATCH4(), so we could even consider reducing the array size to 3).
>> 
>> Note that DMI_MATCH() needs adjustment because of the comma included 
>> in
>> its expansion, which - due to being unparenthesized - would otherwise
>> cause macro arguments in the "further replacement" step to be wrong.
> 
> Sadly this doesn't work with older gcc (4.8.5 is what I had an issue 
> with,
> complaining "initializer element is not constant").
> 
> Jan

Hi,

I tried plugging the relevant code into godbolt.org to try gcc-4.8.5, 
but I'm not able to reproduce the error (see 
https://godbolt.org/z/cP88YeWhh). Can you please provide some more 
details on where the issue is?

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Posted by Jan Beulich 4 months, 3 weeks ago
On 04.12.2023 12:52, Nicola Vetrini wrote:
> On 2023-11-30 15:56, Jan Beulich wrote:
>> On 30.11.2023 08:55, Jan Beulich wrote:
>>> The rule demands that all array elements be initialized (or dedicated
>>> initializers be used). Introduce a small set of macros to allow doing 
>>> so
>>> without unduly affecting use sites (in particular in terms of how many
>>> elements .matches[] actually has; right now there's no use of
>>> DMI_MATCH4(), so we could even consider reducing the array size to 3).
>>>
>>> Note that DMI_MATCH() needs adjustment because of the comma included 
>>> in
>>> its expansion, which - due to being unparenthesized - would otherwise
>>> cause macro arguments in the "further replacement" step to be wrong.
>>
>> Sadly this doesn't work with older gcc (4.8.5 is what I had an issue 
>> with,
>> complaining "initializer element is not constant").
> 
> I tried plugging the relevant code into godbolt.org to try gcc-4.8.5, 
> but I'm not able to reproduce the error (see 
> https://godbolt.org/z/cP88YeWhh). Can you please provide some more 
> details on where the issue is?

It apparently doesn't like the compound literal as initializer. I need
to re-submit the adjusted patch, though.

Jan
Re: [PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Posted by Nicola Vetrini 5 months ago
On 2023-11-30 08:55, Jan Beulich wrote:
> The rule demands that all array elements be initialized (or dedicated
> initializers be used). Introduce a small set of macros to allow doing 
> so
> without unduly affecting use sites (in particular in terms of how many
> elements .matches[] actually has; right now there's no use of
> DMI_MATCH4(), so we could even consider reducing the array size to 3).
> 
> Note that DMI_MATCH() needs adjustment because of the comma included in
> its expansion, which - due to being unparenthesized - would otherwise
> cause macro arguments in the "further replacement" step to be wrong.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> Of course a question is how many of these DMI table entries are in fact
> no longer applicable (e.g. because of naming 32-bit-only systems).
> Subsequently the table in dmi_scan.c itself may want cleaning up as
> well, yet I guess the question of stale entries is even more relevant
> there.
> 
> An alternative to using the compound literal approach might be to go
> along the lines of
> 
> #define DMI_MATCH4(m1, m2, m3, m4) .matches = { [0] = m1, [1] = m2, [2] 
> = m3, [3] = m4 }
> 
> I've chosen the other approach mainly because of being slightly 
> shorter.
> 

 From a MISRA perspective this resolves all but one violation: the 
initialization of static array

ns16550_com[2] = { { 0 } };

in drivers/char/ns16550.c. This is a case where the explicit initializer 
looks unnecessary.

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Posted by Andrew Cooper 5 months ago
On 30/11/2023 12:00 pm, Nicola Vetrini wrote:
> On 2023-11-30 08:55, Jan Beulich wrote:
>> The rule demands that all array elements be initialized (or dedicated
>> initializers be used). Introduce a small set of macros to allow doing so
>> without unduly affecting use sites (in particular in terms of how many
>> elements .matches[] actually has; right now there's no use of
>> DMI_MATCH4(), so we could even consider reducing the array size to 3).
>>
>> Note that DMI_MATCH() needs adjustment because of the comma included in
>> its expansion, which - due to being unparenthesized - would otherwise
>> cause macro arguments in the "further replacement" step to be wrong.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>> ---
>> Of course a question is how many of these DMI table entries are in fact
>> no longer applicable (e.g. because of naming 32-bit-only systems).
>> Subsequently the table in dmi_scan.c itself may want cleaning up as
>> well, yet I guess the question of stale entries is even more relevant
>> there.
>>
>> An alternative to using the compound literal approach might be to go
>> along the lines of
>>
>> #define DMI_MATCH4(m1, m2, m3, m4) .matches = { [0] = m1, [1] = m2,
>> [2] = m3, [3] = m4 }
>>
>> I've chosen the other approach mainly because of being slightly shorter.
>>
>
> From a MISRA perspective this resolves all but one violation: the
> initialization of static array
>
> ns16550_com[2] = { { 0 } };
>
> in drivers/char/ns16550.c. This is a case where the explicit
> initializer looks unnecessary.
>


Yeah.  That should just be ={}; which ought to resolve the violation?

~Andrew

Re: [PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Posted by Nicola Vetrini 5 months ago
On 2023-11-30 13:03, Andrew Cooper wrote:
> On 30/11/2023 12:00 pm, Nicola Vetrini wrote:
>> On 2023-11-30 08:55, Jan Beulich wrote:
>>> The rule demands that all array elements be initialized (or dedicated
>>> initializers be used). Introduce a small set of macros to allow doing 
>>> so
>>> without unduly affecting use sites (in particular in terms of how 
>>> many
>>> elements .matches[] actually has; right now there's no use of
>>> DMI_MATCH4(), so we could even consider reducing the array size to 
>>> 3).
>>> 
>>> Note that DMI_MATCH() needs adjustment because of the comma included 
>>> in
>>> its expansion, which - due to being unparenthesized - would otherwise
>>> cause macro arguments in the "further replacement" step to be wrong.
>>> 
>>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>> ---
>>> Of course a question is how many of these DMI table entries are in 
>>> fact
>>> no longer applicable (e.g. because of naming 32-bit-only systems).
>>> Subsequently the table in dmi_scan.c itself may want cleaning up as
>>> well, yet I guess the question of stale entries is even more relevant
>>> there.
>>> 
>>> An alternative to using the compound literal approach might be to go
>>> along the lines of
>>> 
>>> #define DMI_MATCH4(m1, m2, m3, m4) .matches = { [0] = m1, [1] = m2,
>>> [2] = m3, [3] = m4 }
>>> 
>>> I've chosen the other approach mainly because of being slightly 
>>> shorter.
>>> 
>> 
>> From a MISRA perspective this resolves all but one violation: the
>> initialization of static array
>> 
>> ns16550_com[2] = { { 0 } };
>> 
>> in drivers/char/ns16550.c. This is a case where the explicit
>> initializer looks unnecessary.
>> 
> 
> 
> Yeah.  That should just be ={}; which ought to resolve the violation?
> 
> ~Andrew

Yes

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)

Re: [PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Posted by Nicola Vetrini 5 months ago
On 2023-11-30 08:55, Jan Beulich wrote:
> The rule demands that all array elements be initialized (or dedicated
> initializers be used). Introduce a small set of macros to allow doing 
> so
> without unduly affecting use sites (in particular in terms of how many
> elements .matches[] actually has; right now there's no use of
> DMI_MATCH4(), so we could even consider reducing the array size to 3).
> 
> Note that DMI_MATCH() needs adjustment because of the comma included in
> its expansion, which - due to being unparenthesized - would otherwise
> cause macro arguments in the "further replacement" step to be wrong.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> Of course a question is how many of these DMI table entries are in fact
> no longer applicable (e.g. because of naming 32-bit-only systems).
> Subsequently the table in dmi_scan.c itself may want cleaning up as
> well, yet I guess the question of stale entries is even more relevant
> there.
> 
> An alternative to using the compound literal approach might be to go
> along the lines of
> 
> #define DMI_MATCH4(m1, m2, m3, m4) .matches = { [0] = m1, [1] = m2, [2] 
> = m3, [3] = m4 }
> 
> I've chosen the other approach mainly because of being slightly 
> shorter.
> 

This looks good. Upon applying this patch I noticed that there's no 
diffstat, and it doesn't
apply cleanly with git-am.

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Posted by Andrew Cooper 5 months ago
On 30/11/2023 9:47 am, Nicola Vetrini wrote:
> On 2023-11-30 08:55, Jan Beulich wrote:
>> The rule demands that all array elements be initialized (or dedicated
>> initializers be used). Introduce a small set of macros to allow doing so
>> without unduly affecting use sites (in particular in terms of how many
>> elements .matches[] actually has; right now there's no use of
>> DMI_MATCH4(), so we could even consider reducing the array size to 3).
>>
>> Note that DMI_MATCH() needs adjustment because of the comma included in
>> its expansion, which - due to being unparenthesized - would otherwise
>> cause macro arguments in the "further replacement" step to be wrong.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>> ---
>> Of course a question is how many of these DMI table entries are in fact
>> no longer applicable (e.g. because of naming 32-bit-only systems).
>> Subsequently the table in dmi_scan.c itself may want cleaning up as
>> well, yet I guess the question of stale entries is even more relevant
>> there.
>>
>> An alternative to using the compound literal approach might be to go
>> along the lines of
>>
>> #define DMI_MATCH4(m1, m2, m3, m4) .matches = { [0] = m1, [1] = m2,
>> [2] = m3, [3] = m4 }
>>
>> I've chosen the other approach mainly because of being slightly shorter.
>>
>
> This looks good. Upon applying this patch I noticed that there's no
> diffstat, and it doesn't
> apply cleanly with git-am.
>

So I've had this git alias for more than a decade.

$ git help jan-am
'jan-am' is aliased to '!bash -c '(echo -en "From: Jan Beulich
<JBeulich@suse.com>\nSubject: " && cat "$1") | git am' -'


However, what you actually want to use these days is
https://b4.docs.kernel.org/en/latest/ which integrates with
https://lore.kernel.org/xen-devel/ and also does administrative things
like collecting acked-by/reviewed-by tags.

~Andrew
Re: [PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Posted by Nicola Vetrini 5 months ago
On 2023-11-30 11:27, Andrew Cooper wrote:
> On 30/11/2023 9:47 am, Nicola Vetrini wrote:
>> On 2023-11-30 08:55, Jan Beulich wrote:
>>> The rule demands that all array elements be initialized (or dedicated
>>> initializers be used). Introduce a small set of macros to allow doing 
>>> so
>>> without unduly affecting use sites (in particular in terms of how 
>>> many
>>> elements .matches[] actually has; right now there's no use of
>>> DMI_MATCH4(), so we could even consider reducing the array size to 
>>> 3).
>>> 
>>> Note that DMI_MATCH() needs adjustment because of the comma included 
>>> in
>>> its expansion, which - due to being unparenthesized - would otherwise
>>> cause macro arguments in the "further replacement" step to be wrong.
>>> 
>>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>> ---
>>> Of course a question is how many of these DMI table entries are in 
>>> fact
>>> no longer applicable (e.g. because of naming 32-bit-only systems).
>>> Subsequently the table in dmi_scan.c itself may want cleaning up as
>>> well, yet I guess the question of stale entries is even more relevant
>>> there.
>>> 
>>> An alternative to using the compound literal approach might be to go
>>> along the lines of
>>> 
>>> #define DMI_MATCH4(m1, m2, m3, m4) .matches = { [0] = m1, [1] = m2,
>>> [2] = m3, [3] = m4 }
>>> 
>>> I've chosen the other approach mainly because of being slightly 
>>> shorter.
>>> 
>> 
>> This looks good. Upon applying this patch I noticed that there's no
>> diffstat, and it doesn't
>> apply cleanly with git-am.
>> 
> 
> So I've had this git alias for more than a decade.
> 
> $ git help jan-am
> 'jan-am' is aliased to '!bash -c '(echo -en "From: Jan Beulich
> <JBeulich@suse.com>\nSubject: " && cat "$1") | git am' -'
> 
> 
> However, what you actually want to use these days is
> https://b4.docs.kernel.org/en/latest/ which integrates with
> https://lore.kernel.org/xen-devel/ and also does administrative things
> like collecting acked-by/reviewed-by tags.
> 
> ~Andrew

Thanks, I was able to apply the patch cleanly with this

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [PATCH] x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Posted by Jan Beulich 5 months ago
On 30.11.2023 10:47, Nicola Vetrini wrote:
> On 2023-11-30 08:55, Jan Beulich wrote:
>> The rule demands that all array elements be initialized (or dedicated
>> initializers be used). Introduce a small set of macros to allow doing 
>> so
>> without unduly affecting use sites (in particular in terms of how many
>> elements .matches[] actually has; right now there's no use of
>> DMI_MATCH4(), so we could even consider reducing the array size to 3).
>>
>> Note that DMI_MATCH() needs adjustment because of the comma included in
>> its expansion, which - due to being unparenthesized - would otherwise
>> cause macro arguments in the "further replacement" step to be wrong.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>> ---
>> Of course a question is how many of these DMI table entries are in fact
>> no longer applicable (e.g. because of naming 32-bit-only systems).
>> Subsequently the table in dmi_scan.c itself may want cleaning up as
>> well, yet I guess the question of stale entries is even more relevant
>> there.
>>
>> An alternative to using the compound literal approach might be to go
>> along the lines of
>>
>> #define DMI_MATCH4(m1, m2, m3, m4) .matches = { [0] = m1, [1] = m2, [2] 
>> = m3, [3] = m4 }
>>
>> I've chosen the other approach mainly because of being slightly 
>> shorter.
>>
> 
> This looks good. Upon applying this patch I noticed that there's no 
> diffstat,

That's down to me not using git for patch maintenance.

> and it doesn't apply cleanly with git-am.

I can't explain this. It certainly was all okay with patch --dry-run.

Jan