From patchwork Tue Aug 22 20:30:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 9916141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 673D960381 for ; Tue, 22 Aug 2017 20:31:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C28728905 for ; Tue, 22 Aug 2017 20:31:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D3EF28922; Tue, 22 Aug 2017 20:31:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B62D928905 for ; Tue, 22 Aug 2017 20:31:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8910A6E454; Tue, 22 Aug 2017 20:31:01 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6FAA36E001; Tue, 22 Aug 2017 20:31:00 +0000 (UTC) Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v7MKUscJ032491 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Aug 2017 20:30:55 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v7MKUsLi022681 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Aug 2017 20:30:54 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v7MKUqbm030148; Tue, 22 Aug 2017 20:30:53 GMT Received: from mwanda (/41.202.241.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 22 Aug 2017 13:30:51 -0700 Date: Tue, 22 Aug 2017 23:30:34 +0300 From: Dan Carpenter To: Alex Deucher Subject: [PATCH 1/2] drm/radeon/ci: tidy up some limit checks Message-ID: <20170822203033.u7ltp2xjaqmoqrl4@mwanda> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170609 (1.8.3) X-Source-IP: userv0021.oracle.com [156.151.31.71] Cc: dri-devel@lists.freedesktop.org, kernel-janitors@vger.kernel.org, Christian =?iso-8859-1?Q?K=F6nig?= , amd-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is partly to silence a static checker warning: drivers/gpu/drm/amd/amdgpu/ci_dpm.c:4553 ci_set_mc_special_registers() error: buffer overflow 'table->mc_reg_address' 16 <= 16 The story is that it's valid to exit the loop with "j" less than or equal to SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE". That value for "j" gets saved as table->last. We're not allow to access "table->mc_reg_address[j]" when j == SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE because that's one past the end of the array. The tests for "if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE)" in ci_set_mc_special_registers() are always false because we start with j less than the array size and we increment it once so at most it can be equal. Then there is a bogus check in ci_register_patching_mc_seq() where it complains if "table->last >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE". The "table->last" value can't possibly be greater than the array size and it is allowed to be equal to it. So let's just remove that test entirely. Signed-off-by: Dan Carpenter --- Not tested. Please review this one carefully. diff --git a/drivers/gpu/drm/radeon/ci_dpm.c b/drivers/gpu/drm/radeon/ci_dpm.c index c97fbb2ab48b..d3136e020d5a 100644 --- a/drivers/gpu/drm/radeon/ci_dpm.c +++ b/drivers/gpu/drm/radeon/ci_dpm.c @@ -4342,10 +4342,10 @@ static int ci_set_mc_special_registers(struct radeon_device *rdev, table->mc_reg_table_entry[k].mc_data[j] |= 0x100; } j++; - if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) - return -EINVAL; if (!pi->mem_gddr5) { + if (j >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) + return -EINVAL; table->mc_reg_address[j].s1 = MC_PMG_AUTO_CMD >> 2; table->mc_reg_address[j].s0 = MC_PMG_AUTO_CMD >> 2; for (k = 0; k < table->num_entries; k++) { @@ -4521,8 +4521,6 @@ static int ci_register_patching_mc_seq(struct radeon_device *rdev, ((rdev->pdev->device == 0x67B0) || (rdev->pdev->device == 0x67B1))) { for (i = 0; i < table->last; i++) { - if (table->last >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) - return -EINVAL; switch(table->mc_reg_address[i].s1 >> 2) { case MC_SEQ_MISC1: for (k = 0; k < table->num_entries; k++) {