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.

Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
Fixes: 2bf9a0a127 ('iommu/amd: Add iommu support for ACPI HID devices')
Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
Aaron Ma 2019-03-13 21:53:24 +08:00 committed by Joerg Roedel
parent d05e4c8600
commit bb6bccba39
1 changed files with 6 additions and 2 deletions

View 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;