iommu/amd: Fix ivrs_acpihid cmdline parsing code
authorKim Phillips <kim.phillips@amd.com>
Mon, 19 Sep 2022 15:56:37 +0000 (10:56 -0500)
committerJoerg Roedel <jroedel@suse.de>
Sat, 19 Nov 2022 09:05:28 +0000 (10:05 +0100)
The second (UID) strcmp in acpi_dev_hid_uid_match considers
"0" and "00" different, which can prevent device registration.

Have the AMD IOMMU driver's ivrs_acpihid parsing code remove
any leading zeroes to make the UID strcmp succeed.  Now users
can safely specify "AMDxxxxx:00" or "AMDxxxxx:0" and expect
the same behaviour.

Fixes: ca3bf5d47cec ("iommu/amd: Introduces ivrs_acpihid kernel parameter")
Signed-off-by: Kim Phillips <kim.phillips@amd.com>
Cc: stable@vger.kernel.org
Cc: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
Cc: Joerg Roedel <jroedel@suse.de>
Link: https://lore.kernel.org/r/20220919155638.391481-1-kim.phillips@amd.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd/init.c

index 1a2d425bf5687fffb44e419502ae7b8025687278..d14da30b8706fae8a23a0df604ecdaf8227a420b 100644 (file)
@@ -3488,6 +3488,13 @@ static int __init parse_ivrs_acpihid(char *str)
                return 1;
        }
 
+       /*
+        * Ignore leading zeroes after ':', so e.g., AMDI0095:00
+        * will match AMDI0095:0 in the second strcmp in acpi_dev_hid_uid_match
+        */
+       while (*uid == '0' && *(uid + 1))
+               uid++;
+
        i = early_acpihid_map_size++;
        memcpy(early_acpihid_map[i].hid, hid, strlen(hid));
        memcpy(early_acpihid_map[i].uid, uid, strlen(uid));