[PATCH] virt: vmgenid: check ACPI companion before use

From: Jiale Yao

Date: Wed Oct 28 2026 - 01:15:35 EST


vmgenid_add() selects the ACPI path for every device without an OF node.
A platform device force-bound to the driver can have neither firmware
representation, leaving ACPI_COMPANION() NULL and causing a NULL pointer
dereference when vmgenid_add_acpi() evaluates ADDR.

Reject a missing ACPI companion before accessing its handle.

Fixes: e07606713a90 ("virt: vmgenid: change implementation to use a platform driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jiale Yao <yaojiale02@xxxxxxx>
---
drivers/virt/vmgenid.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c
index ce957f5b1c31..cbcbb36eb6c6 100644
--- a/drivers/virt/vmgenid.c
+++ b/drivers/virt/vmgenid.c
@@ -51,14 +51,18 @@ static void vmgenid_acpi_handler(acpi_handle __always_unused handle,

static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state)
{
- struct acpi_device *device = ACPI_COMPANION(dev);
struct acpi_buffer parsed = { ACPI_ALLOCATE_BUFFER };
+ struct acpi_device *device;
union acpi_object *obj;
phys_addr_t phys_addr;
acpi_status status;
void *virt_addr;
int ret = 0;

+ device = ACPI_COMPANION(dev);
+ if (!device)
+ return -ENODEV;
+
status = acpi_evaluate_object(device->handle, "ADDR", NULL, &parsed);
if (ACPI_FAILURE(status)) {
ACPI_EXCEPTION((AE_INFO, status, "Evaluating ADDR"));
--
2.34.1