Re: [PATCH] ACPI: bus: Match first 9 bytes of device IDs

From: Alexander Graf
Date: Fri Feb 25 2022 - 12:10:28 EST


Hey Jason,

On 25.02.22 17:57, Jason A. Donenfeld wrote:
Hi Alex,

Thanks for this.

I tested this out with the vmgenid driver, and I found a bug in this v1:

On Fri, Feb 25, 2022 at 04:55:52PM +0100, Alexander Graf wrote:
- if (id->id[0] && !strcmp((char *)id->id, hwid->id))
+ if (id->id[0] && !strncmp((char *)id->id, hwid->id, ACPI_ID_LEN))
This only worked once I made that `ACPI_ID_LEN - 1`, because that length
includes the null terminator. The below patch works fine. If you adjust
that and send a quick v2 follow-up, I'm happy to ack it.

Regards,
Jason

--------8<--------------------------

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 07f604832fd6..f179ebf16f21 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -829,7 +829,7 @@ static bool __acpi_match_device(struct acpi_device *device,
/* First, check the ACPI/PNP IDs provided by the caller. */
if (acpi_ids) {
for (id = acpi_ids; id->id[0] || id->cls; id++) {
- if (id->id[0] && !strcmp((char *)id->id, hwid->id))
+ if (id->id[0] && !strncmp((char *)id->id, hwid->id, ACPI_ID_LEN - 1))
goto out_acpi_match;
if (id->cls && __acpi_match_device_cls(id, hwid))
goto out_acpi_match;
diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c
index b503c210c2d7..04751fc1d365 100644
--- a/drivers/virt/vmgenid.c
+++ b/drivers/virt/vmgenid.c
@@ -78,8 +78,7 @@ static void vmgenid_acpi_notify(struct acpi_device *device, u32 event)
}

static const struct acpi_device_id vmgenid_ids[] = {
- { "QEMUVGID", 0 }, /* QEMU */
- { "VMGENID", 0 }, /* Firecracker */
+ { "VM_GEN_C", 0 }, /* Truncated "VM_Gen_Counter" */


You have to make this "VM_GEN_CO". I now match the full 9 bytes - unlike the previous patch I sent :)


Alex





Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879