[PATCH] virt: vmgenid: Add Null check for device

Chenyuan Yang posted 1 patch 9 months, 1 week ago
drivers/virt/vmgenid.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] virt: vmgenid: Add Null check for device
Posted by Chenyuan Yang 9 months, 1 week ago
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@gmail.com>
---
 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
Re: [PATCH] virt: vmgenid: Add Null check for device
Posted by Jason A. Donenfeld 9 months ago
On Wed, Mar 12, 2025 at 11:26:00PM -0500, Chenyuan Yang wrote:
> 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