From: Aaron Ma Date: Wed, 13 Mar 2019 13:53:24 +0000 (+0800) Subject: iommu/amd: Fix NULL dereference bug in match_hid_uid X-Git-Tag: v4.19.88~73 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aa1844c9137e7fae79b94ad87017167320419dee;p=thirdparty%2Fkernel%2Fstable.git iommu/amd: Fix NULL dereference bug in match_hid_uid [ Upstream commit bb6bccba390c7d743c1e4427de4ef284c8cc6869 ] Add a non-NULL check to fix potential NULL pointer dereference Cleanup code to call function once. Signed-off-by: Aaron Ma Fixes: 2bf9a0a12749b ('iommu/amd: Add iommu support for ACPI HID devices') Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 1f2ed44de2438..fe18804a50083 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -139,10 +139,14 @@ static struct lock_class_key reserved_rbtree_key; static inline int match_hid_uid(struct device *dev, struct acpihid_map_entry *entry) { + struct acpi_device *adev = ACPI_COMPANION(dev); const char *hid, *uid; - 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;