Patchwork [RESEND] iommu/amd: Fix NULL dereference bug in match_hid_uid

login
register
mail settings
Submitter Aaron Ma
Date March 13, 2019, 1:53 p.m.
Message ID <1552485204-11381-1-git-send-email-aaron.ma@canonical.com>
Download mbox | patch
Permalink /patch/748923/
State New
Headers show

Comments

Aaron Ma - March 13, 2019, 1:53 p.m.
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>
---
 drivers/iommu/amd_iommu.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Joerg Roedel - March 15, 2019, 3:24 p.m.
On Wed, Mar 13, 2019 at 09:53:24PM +0800, Aaron Ma wrote:
> 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>
> ---
>  drivers/iommu/amd_iommu.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

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

Patch

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 2a7b78bb98b4..dbda5b86f979 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -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;