]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
iommu/amd: Fix NULL dereference bug in match_hid_uid
authorAaron Ma <aaron.ma@canonical.com>
Wed, 13 Mar 2019 13:53:24 +0000 (21:53 +0800)
committerJoerg Roedel <jroedel@suse.de>
Fri, 15 Mar 2019 15:22:05 +0000 (16:22 +0100)
Add a non-NULL check to fix potential NULL pointer dereference
Cleanup code to call function once.

Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
Fixes: 2bf9a0a12749b ('iommu/amd: Add iommu support for ACPI HID devices')
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd_iommu.c

index 6b0760dafb3e9c0ff53158676cdcd4e6f08e8ce2..b319e51c379bd664999e7d710c5e1240cc21a42d 100644 (file)
@@ -140,10 +140,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;