Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp4565104pja; Thu, 21 Nov 2019 21:58:46 -0800 (PST) X-Google-Smtp-Source: APXvYqwE0CIeognZkYcgRQie1iF7iYNbH71hPef2zO+8lzEYnZTgjARwsUwv/tv9G+gTN3O5lVeF X-Received: by 2002:a17:906:3418:: with SMTP id c24mr19575367ejb.121.1574402326002; Thu, 21 Nov 2019 21:58:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574402325; cv=none; d=google.com; s=arc-20160816; b=w7fuhdLLe/F2v4KDWhxKxYK/co+fTm4GpvfQocESi+pN4CAC6yJiLkjENEmz9DRZXn imZJommrxSeGlyAE1IyayfWhL2yIq6jymBvmfs48CH3xx1EygAE4cvC2JOaJHxzEDfgh v2F6D3YlmFxmPpkltWs8FvQULnTyi/zEiCh5IoDFVzX2qGNXc6erMmWgwdnBNJUYZHSU MC3PWJTyCxiT5BqreFIf8DkZBM+aV+5VvNT6DN0f23vhUb1r7Fs1F6NK6RlP8YfAhkn9 +J1918itMC71sXjCPEPy+wxRmE7Ouox2N5HrIQ6D1bEQjvjnnZZfsyxpV67jNsZb6wgS zJeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8HMCxa6xLA/X5J+BkZzd4lZBPNuPCSAzg6Smyb1yz2Q=; b=kQmS78RA7uSdLwl5sPQ/I9wogquiW4wPxcU+VS4nsbMNOWAdkREa9RL0RI55+Ilp+P TyrMxx4PYyPLtCSkb6ZtFbOXSIGkQAN9R5ygPXXXfUU8S4WT3akA95qGLYA6AKg5o8ec WIq7pd7K0BhhMgXm8sFJ9d4ec9OQX9kJC+s2W1m7nirWlzpsdgD4drHnU4xF8PlDvwb4 zg6qIB3aYdNUbrKO2xA5x7FTIpP4fHMN4D8KsHBWuoC4oVpv2zhzD+mKm+RdXrqpQUW6 D6lsAIolPbC/uY2xokzMIzjpfi61RMGHzmSQJsolhnMaop0JJPxoOdzfElyQtOgwKIFm RmBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wfcE+SYG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9si3584717ejb.380.2019.11.21.21.58.18; Thu, 21 Nov 2019 21:58:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wfcE+SYG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728804AbfKVFxN (ORCPT + 99 others); Fri, 22 Nov 2019 00:53:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:59086 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728779AbfKVFxG (ORCPT ); Fri, 22 Nov 2019 00:53:06 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0597E2084B; Fri, 22 Nov 2019 05:53:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574401985; bh=vTnqRBhSJThxK31D6vHxdhMGVr8Vgn7F/eGcARVmDAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wfcE+SYGXsak2mRNeEa1tKTBcTXEh37aioE2GYcxIqy6HcQZ2D9LrdH65vUx/xNFl MPob3ERQiwb9UfAEpVcRMNnLSOsmaHxqH5noFQPsxeff18tT2o2JYGr+LlYCXuG8sM iGsTkqAMIjt9vgdvk4uwM9uryT66N+vMo/Ji2WZE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Aaron Ma , Joerg Roedel , Sasha Levin , iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 4.19 204/219] iommu/amd: Fix NULL dereference bug in match_hid_uid Date: Fri, 22 Nov 2019 00:48:55 -0500 Message-Id: <20191122054911.1750-196-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122054911.1750-1-sashal@kernel.org> References: <20191122054911.1750-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aaron Ma [ 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 --- drivers/iommu/amd_iommu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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; -- 2.20.1