Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752931AbcKOQF1 (ORCPT ); Tue, 15 Nov 2016 11:05:27 -0500 Received: from mail-bn3nam01on0043.outbound.protection.outlook.com ([104.47.33.43]:2970 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750928AbcKOQFY (ORCPT ); Tue, 15 Nov 2016 11:05:24 -0500 From: "Deucher, Alexander" To: "'Colin King'" , "Koenig, Christian" , David Airlie , "Zhu, Rex" , "StDenis, Tom" , "Huang, Ray" , =?utf-8?B?TmlscyBXYWxsbcOpbml1cw==?= , Baoyou Xie , "dri-devel@lists.freedesktop.org" CC: "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] drm/amd/powerplay: check if table_info is NULL before dereferencing it Thread-Topic: [PATCH] drm/amd/powerplay: check if table_info is NULL before dereferencing it Thread-Index: AQHSPz9ynHmEUylN6k+BUa683WLSJ6DaLXJA Date: Tue, 15 Nov 2016 15:49:44 +0000 Message-ID: References: <20161115125435.6236-1-colin.king@canonical.com> In-Reply-To: <20161115125435.6236-1-colin.king@canonical.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Deucher@amd.com; x-originating-ip: [165.204.55.251] x-microsoft-exchange-diagnostics: 1;MWHPR12MB1341;7:JPhgG8eFLuHeD7pR7pySqSvySjIqKyo0hN2/0fDDEMsVCbkK7yEeMo8wOH74qts+S+SpqCD8JxmAqY26UxpmTd3E67plYZqsP2Qtw5Ver0lkk6bTQIL2XrwyV9xmwmI+2gRliLNO5WFN01/myN6le0Pz7XGtU78JCVOV/3IjSTDnr22hBqRaDVIVOAhU4/2FfhYE8qYCrvRNeYtnJGRTgk6lq7a3bA2/2FURgpmYj1QwukIk+0R00J61T6hJr/4sNwre87KrQOarrlEcGopLK9SB1WBsxCbqA/4DLuiSeAU6vyEpfdCVOmH3OJ9mhH9mFEPtoLmkXMDFRz1SanR+/zAsNOVkbTzY+DtiOc6qVGg=;20:D1HRcc2sh4wdnNcd1uaRkTmZSu4sQOE7qSfLbrc6K39m1YNyaHV13iQwlS8lPYU8JejVKwRayVDAMFaXrZ+sVzZFaYztxuZ6ly4TfPhrZJmR9NpTE4c47wOG5FNUladfIGyeDF4olNUPZkvui/S46wtqicUKI1l4RBymImCtBcVk0rtIrwUI1r6WnOxC88MA83zUYkcp5l8WNqNA8QoYANIhaw/OLa+yHdiHE9pfulgffSOgmyp7M/2/mhbz8o/T x-forefront-antispam-report: SFV:SKI;SCL:-1SFV:NSPM;SFS:(10009020)(6009001)(7916002)(189002)(199003)(13464003)(377454003)(9686002)(2900100001)(86362001)(102836003)(6116002)(77096005)(3846002)(66066001)(8676002)(229853002)(2501003)(76576001)(33656002)(7846002)(92566002)(2906002)(4326007)(2950100002)(305945005)(3280700002)(8936002)(7736002)(81166006)(81156014)(5660300001)(7696004)(74316002)(3660700001)(122556002)(99286002)(106116001)(105586002)(87936001)(106356001)(5001770100001)(97736004)(54356999)(76176999)(50986999)(68736007)(189998001)(101416001)(61793002)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR12MB1341;H:MWHPR12MB1694.namprd12.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; x-ms-office365-filtering-correlation-id: f9a39b40-0b30-4197-4d5f-08d40d6f056f x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:MWHPR12MB1341; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(217544274631240)(198206253151910); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6060326)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6061324);SRVR:MWHPR12MB1341;BCL:0;PCL:0;RULEID:;SRVR:MWHPR12MB1341; x-forefront-prvs: 012792EC17 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Nov 2016 15:49:44.5930 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1341 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id uAFG5Vqn029190 Content-Length: 2832 Lines: 76 > -----Original Message----- > From: Colin King [mailto:colin.king@canonical.com] > Sent: Tuesday, November 15, 2016 7:55 AM > To: Deucher, Alexander; Koenig, Christian; David Airlie; Zhu, Rex; StDenis, > Tom; Huang, Ray; Nils Wallménius; Baoyou Xie; dri- > devel@lists.freedesktop.org > Cc: linux-kernel@vger.kernel.org > Subject: [PATCH] drm/amd/powerplay: check if table_info is NULL before > dereferencing it > > From: Colin Ian King > > table_info is being dereferenced before a null check, which implies > a potential null pointer deference error. Fix this by moving the null > check of table_info to the start of smu7_get_evv_voltages to avoid > potential null pointer deferencing. > > Found with static analysis by CoverityScan, CID 1377752 > > Signed-off-by: Colin Ian King NACK, this effectively reverts the patch. This causes the function to exit early on asics where the table it NULL which is not what we want. Whether the table exists or not is dependent on the table version and the feature caps for the chip which are checked before the table is dereferenced. The NULL check in the top if clause is not strictly necessary and could be removed. Alex > --- > drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c > b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c > index 28e748d..6798067 100644 > --- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c > +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c > @@ -1473,6 +1473,8 @@ static int smu7_get_evv_voltages(struct pp_hwmgr > *hwmgr) > (struct phm_ppt_v1_information *)hwmgr->pptable; > struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = > NULL; > > + if (table_info == NULL) > + return -EINVAL; > > for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) { > vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i; > @@ -1483,8 +1485,6 @@ static int smu7_get_evv_voltages(struct pp_hwmgr > *hwmgr) > table_info- > >vddgfx_lookup_table, vv_id, &sclk)) { > if (phm_cap_enabled(hwmgr- > >platform_descriptor.platformCaps, > > PHM_PlatformCaps_ClockStretcher)) { > - if (table_info == NULL) > - return -EINVAL; > sclk_table = table_info- > >vdd_dep_on_sclk; > > for (j = 1; j < sclk_table->count; j++) { > @@ -1517,8 +1517,6 @@ static int smu7_get_evv_voltages(struct pp_hwmgr > *hwmgr) > table_info->vddc_lookup_table, > vv_id, &sclk)) { > if (phm_cap_enabled(hwmgr- > >platform_descriptor.platformCaps, > > PHM_PlatformCaps_ClockStretcher)) { > - if (table_info == NULL) > - return -EINVAL; > sclk_table = table_info- > >vdd_dep_on_sclk; > > for (j = 1; j < sclk_table->count; j++) { > -- > 2.10.2