[PATCH] virt: vmgenid: Add Null check for device
From: Chenyuan Yang
Date: Thu Mar 13 2025 - 00:26:11 EST
Not all devices have an ACPI companion fwnode, so device might be NULL.
This is similar to the commit cd2fd6eab480
("platform/x86: int3472: Check for adev == NULL").
Add a check for device not being set and return -ENODEV in that case to
avoid a possible NULL pointer deref in vmgenid_add_acpi().
Signed-off-by: Chenyuan Yang <chenyuan0y@xxxxxxxxx>
---
drivers/virt/vmgenid.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c
index 66135eac3abf..0cfa2fbf0d44 100644
--- a/drivers/virt/vmgenid.c
+++ b/drivers/virt/vmgenid.c
@@ -59,6 +59,9 @@ static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state)
void *virt_addr;
int ret = 0;
+ 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