Skip to contentSkip to conversation

virt: vmgenid: Add Null check for device

PATCH In review Chenyuan Yang 2 participants 2 messages Mar 13, 2025 – Mar 19, 2025 Random number driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virt: vmgenid: Add Null check for device

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().

---
 drivers/virt/vmgenid.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/virt/vmgenid.c +3 -0
index 66135eac3abf..0cfa2fbf0d44 100644
@@ -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"));
Signature · 1 line
2.34.1
#1 lore raw
Quoted 6 lines · Chenyuan Yang

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().

Is this causing a crash on some systems? What's happening here? "Not all devices" - which ones, and why?

Jason