Skip to contentSkip to conversation

iommu/amd: Fix NULL dereference bug in match_hid_uid

PATCH RESEND In review Aaron Ma 2 participants 2 messages Mar 13, 2019 – Mar 15, 2019 IOMMU

lore
Share & tools
lore

Aaron Ma

author
#0 lore raw

PATCH RESEND 1/1 iommu/amd: Fix NULL dereference bug in match_hid_uid

Add a non-NULL check to fix potential NULL pointer dereference Cleanup code to call function once.

---
 drivers/iommu/amd_iommu.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/iommu/amd_iommu.c +7 -2
index 2a7b78bb98b4..dbda5b86f979 100644
@@ -140,9 +140,14 @@ static inline int match_hid_uid(struct device *dev,
 				struct acpihid_map_entry *entry)
 {
 	const char *hid, *uid;
+	struct acpi_device *adev = ACPI_COMPANION(dev);
 
-	hid = acpi_device_hid(ACPI_COMPANION(dev));
-	uid = acpi_device_uid(ACPI_COMPANION(dev));
+	if (!adev) {
+		return -ENODEV;
+	}
+
+	hid = acpi_device_hid(adev);
+	uid = acpi_device_uid(adev);
 
 	if (!hid || !(*hid))
 		return -ENODEV;
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 7 lines · Aaron Ma

Add a non-NULL check to fix potential NULL pointer dereference Cleanup code to call function once.

---
 drivers/iommu/amd_iommu.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Applied with cleaned-up coding style and a Fixes tag, thanks.