Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1302674rwi; Mon, 10 Oct 2022 14:24:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4qFbVuFZeHWUNwJwTJudP7P6xJ4k6RIyR6li58kg7fpGkAuIB6k0Ps1ZsGJLmTNIAJHaiA X-Received: by 2002:a17:907:60cb:b0:785:4ec0:551f with SMTP id hv11-20020a17090760cb00b007854ec0551fmr16109716ejc.179.1665437051827; Mon, 10 Oct 2022 14:24:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665437051; cv=none; d=google.com; s=arc-20160816; b=US61dzyLngq2hCeagddTOBb0a8c2W9PhtyxXHy9sfouk3/V8/n3NbhhJi2tdXlwfCx dwl+pne7bygTfckJ5zNDAOjZ1kprR3kRvDHgvSGp/Nw5vSD3aYX9yKvoK5yPeh688nf4 y10mzm2ndi+10McMsccC+VJkKpINnpzkMPrxi5Gyr+dOIZH//2bibOk+494FCtEgf1kV nQJdtxvzZxuRPwnY9iuvcqxx20yeUKEeUY1L3Zel16ejQX9ReBBFbnxxxFteV04QVeq3 hz6dwpV8TUTIuyPElcwDt97zk+/hw4Uqr0Qkm3Cr/jbEmGhKcHKl6nLfv2vJKY4fsjTZ Pg3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zQo9CpEQOxd8V/Gnq9d1IqgBFMZ32QQpuKIj7r7NKWU=; b=krf5rar+aMkg6TpM5AfLYv8sFFwhygTzO0KlT6bHBdrjdSXmJ5QiWUYOWEXy8MipWb eHqHidMgr3GE5BU7ttnxvPlKXWXrgB9m9TjMx/1hgifTmK55Q48AC4mMaugB3djlx6ov ltAzkb5X7l4j4ljzPSjZXsQGLk9WMC5oRZ5a0xxotZieEHybmFcoLT0+v6PEP25AgPgc nQblJV2LBB8+3wZ6EzrnR2Rk9UMULLX4u+S6gUHad6rAsce0OWDJIgO/V2M241JL7uL5 +Nu6zJZSd9lCA388tTl424nh7Onlgv1rHc9YhSQesuFoWoLPXTvUnzVdZAP4gq7Sx9Iv ywHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dSUXLhcR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020aa7d910000000b00459779478absi7864441edr.186.2022.10.10.14.23.46; Mon, 10 Oct 2022 14:24:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dSUXLhcR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230256AbiJJUTv (ORCPT + 99 others); Mon, 10 Oct 2022 16:19:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbiJJUSx (ORCPT ); Mon, 10 Oct 2022 16:18:53 -0400 Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F8547B2A5 for ; Mon, 10 Oct 2022 13:16:19 -0700 (PDT) Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-132af5e5543so13647825fac.8 for ; Mon, 10 Oct 2022 13:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=zQo9CpEQOxd8V/Gnq9d1IqgBFMZ32QQpuKIj7r7NKWU=; b=dSUXLhcRKIZVH3q5lAX9w1Sjipi2FBkD3S3AJw8zTLfOJybtcjQoPR1iTC7PLnVVuf TpaUyfjZ7mwW/0WOfIdM/KQYj8DsRzcXOQWCRdFRAsaNjYx4LhHo9LGEr2BXQo9SVB4c Vew7ExS55SDBCIQcUathisVLmkU5xfdBBZyByYFc59O2NtR/SFG3pELPoMILT7pHFkP2 E5c7mWZIDNSQj6OojMGL1tRz9EcOy82oNgC8XMaGSYGz3UFFBzowfv9SRchUaD5xIi+J a5C4WmW5YAgqfam8iTjrfr7Zo6nPUor/YeKLZNRQvYWrPKTGKKqDY7E8tqE0SXPrLUJI FZGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zQo9CpEQOxd8V/Gnq9d1IqgBFMZ32QQpuKIj7r7NKWU=; b=Dn4gOqu/zUrFX5hXASI9QklNeVzljXyzVWuzav0ORWXRsS9SCR0g2ZbEkVHP+T4pFU 0dwP3czMJXp1BKU7Eu9Oq7vZAi7UBMJevB4+m1Evtb7Br1OyuGJnHDMDDU9uOs7gZCga ZRhbE6qKXjFO8HHQmbNpqpHW7PvLY1byfrRuv4Z40JU9AIOfHwDo/5ZOiPuSgAisa258 ZAGobqU2ZQTw/0fKstZc0TeFTaojwOf/271Ondlpg8fWaPk69AoJaL0Di+4s8295PFCL LyZ77utciUwPY4vWrRZTsAj/VHFsYdWtJzh2vv91Vgnr1OW5Hd2evyb7mutkPQpdJzWp xFzw== X-Gm-Message-State: ACrzQf1jIrrBjSRKeFX6tPiIhM0sSmsqCQ4bKeX8i7JgQHRhKRhnd3iV LfpJ9ykb+9ReG9aCdt06N6yK9hUBbT6vs+jV7dg= X-Received: by 2002:a05:6870:40c8:b0:136:4389:1375 with SMTP id l8-20020a05687040c800b0013643891375mr7561495oal.46.1665432977966; Mon, 10 Oct 2022 13:16:17 -0700 (PDT) MIME-Version: 1.0 References: <20221010060512.3064524-1-linux@roeck-us.net> In-Reply-To: <20221010060512.3064524-1-linux@roeck-us.net> From: Alex Deucher Date: Mon, 10 Oct 2022 16:16:06 -0400 Message-ID: Subject: Re: [PATCH] drm/amd/display: fix array-bounds error in dc_stream_remove_writeback() [take 2] To: Guenter Roeck Cc: amd-gfx@lists.freedesktop.org, regressions@lists.linux.dev, Leo Li , Xinhui.Pan@amd.com, Rodrigo Siqueira , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Aurabindo Pillai , Hamza Mahfooz , Alex Deucher , =?UTF-8?Q?Christian_K=C3=B6nig?= Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Applied. Thanks. Alex On Mon, Oct 10, 2022 at 2:05 AM Guenter Roeck wrote: > > Commit 5d8c3e836fc2 ("drm/amd/display: fix array-bounds error in > dc_stream_remove_writeback()") tried to fix an array bounds error seen > with gcc 12.0. Unfortunately, that results in another array bounds error, > seen with older versions of gcc. > > Building csky:allmodconfig ... failed > -------------- > Error log: > drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc_stream.c: > In function 'dc_stream_remove_writeback': > drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc_stream.c:527:83: > error: array subscript 1 is above array bounds of 'struct dc_writeback_info[1]' [-Werror=array-bounds] > 527 | stream->writeback_info[j] = stream->writeback_info[i]; > | ~~~~~~~~~~~~~~~~~~~~~~^~~ > In file included from drivers/gpu/drm/amd/amdgpu/../display/dc/dc.h:1269, > from drivers/gpu/drm/amd/amdgpu/../display/dc/inc/core_types.h:29, > from drivers/gpu/drm/amd/amdgpu/../display/dc/basics/dc_common.h:29, > from drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc_stream.c:27: > drivers/gpu/drm/amd/amdgpu/../display/dc/dc_stream.h:241:34: note: while referencing 'writeback_info' > 241 | struct dc_writeback_info writeback_info[MAX_DWB_PIPES]; > > We could check both i and j for overflow to fix the problem. That would, > however, be not make much sense since it is known and provable that j <= i. > Also, the check introduced with commit 5d8c3e836fc2 does not really add > value since it checks if j < MAX_DWB_PIPES. Since it is known that j <= i, > it would make more sense to check if i < MAX_DWB_PIPES. Unfortunately, that > does not help to solve the problem observed here: gcc still complains. > > To solve the problem, replace the subsequent check for 'i != j' with > 'j < i'. This is identical to the original check since we know that j <= i, > and it makes all versions of gcc happy. Drop the check introduced with > commit 5d8c3e836fc2 since it is not really useful and does not solve the > problem. > > Cc: Aurabindo Pillai > Cc: Hamza Mahfooz > Fixes: 5d8c3e836fc2 ("drm/amd/display: fix array-bounds error in dc_stream_remove_writeback()") > Signed-off-by: Guenter Roeck > --- > drivers/gpu/drm/amd/display/dc/core/dc_stream.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c > index ae13887756bf..9f568d618cd0 100644 > --- a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c > +++ b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c > @@ -520,9 +520,9 @@ bool dc_stream_remove_writeback(struct dc *dc, > } > > /* remove writeback info for disabled writeback pipes from stream */ > - for (i = 0, j = 0; i < stream->num_wb_info && j < MAX_DWB_PIPES; i++) { > + for (i = 0, j = 0; i < stream->num_wb_info; i++) { > if (stream->writeback_info[i].wb_enabled) { > - if (i != j) > + if (j < i) > /* trim the array */ > stream->writeback_info[j] = stream->writeback_info[i]; > j++; > -- > 2.36.2 >