From patchwork Tue Aug 22 20:36:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 9916171 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 BF81060381 for ; Tue, 22 Aug 2017 20:38:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B062728901 for ; Tue, 22 Aug 2017 20:38:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A48F528926; Tue, 22 Aug 2017 20:38:12 +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 1AD4628901 for ; Tue, 22 Aug 2017 20:38:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8DBB689E8C; Tue, 22 Aug 2017 20:38:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from userp1040.oracle.com (userp1040.oracle.com [156.151.31.81]) by gabe.freedesktop.org (Postfix) with ESMTPS id A64F189E8C; Tue, 22 Aug 2017 20:38:04 +0000 (UTC) Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v7MKbxxP014935 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Aug 2017 20:37:59 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v7MKbx07013863 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Aug 2017 20:37:59 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v7MKbwAm028543; Tue, 22 Aug 2017 20:37:58 GMT Received: from mwanda (/41.202.241.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 22 Aug 2017 13:37:56 -0700 Date: Tue, 22 Aug 2017 23:36:52 +0300 From: Dan Carpenter To: Alex Deucher Subject: [PATCH 2/2] drm/amdgpu/ci: tidy up some limit checks Message-ID: <20170822203652.oofm6lcyht7naiv5@mwanda> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170822203033.u7ltp2xjaqmoqrl4@mwanda> 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, amd-gfx@lists.freedesktop.org, Eric Huang , Ken Wang , Rex Zhu , Christian =?iso-8859-1?Q?K=F6nig?= 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/amd/amdgpu/ci_dpm.c b/drivers/gpu/drm/amd/amdgpu/ci_dpm.c index cb508a211b2f..c885388bdc3c 100644 --- a/drivers/gpu/drm/amd/amdgpu/ci_dpm.c +++ b/drivers/gpu/drm/amd/amdgpu/ci_dpm.c @@ -4546,10 +4546,10 @@ static int ci_set_mc_special_registers(struct amdgpu_device *adev, table->mc_reg_table_entry[k].mc_data[j] |= 0x100; } j++; - if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) - return -EINVAL; if (adev->mc.vram_type != AMDGPU_VRAM_TYPE_GDDR5) { + if (j >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) + return -EINVAL; table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD; table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD; for (k = 0; k < table->num_entries; k++) { @@ -4725,8 +4725,6 @@ static int ci_register_patching_mc_seq(struct amdgpu_device *adev, ((adev->pdev->device == 0x67B0) || (adev->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) { case mmMC_SEQ_MISC1: for (k = 0; k < table->num_entries; k++) {