Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3021241pxu; Sun, 29 Nov 2020 12:14:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyObYRAGUm9Bv7XvUvfgN/PO+CwoCeWOnNR8g+oYc9m0o8uRxbF1DzbSdJZk4a4XADdsfHB X-Received: by 2002:a17:906:c0d1:: with SMTP id bn17mr18961778ejb.114.1606680846423; Sun, 29 Nov 2020 12:14:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606680846; cv=none; d=google.com; s=arc-20160816; b=uhW+I6VA3p/r+YHkR69Vye8+YxhdhY0eDzU3M/p1SCKZFHREW8bhO6MRromyRLpb/2 yMJc5GNQiGVMVN6VS3F+0vvVk3A6NRvn7RU0jPP5hsEm+cOUADclNTq4qTyP+UQw+e1E bcWPWahyY3j2R7CiPKyjMoZVMFBnoPsHeDcitnm7CnInk9JYGw9S+QmL8BEYURu7ntnL i299z+NGnm+jRFitpTvlvdUHHCWi/Qap41azKuO0/oCd2cA0Qa/iHaA/N6pcg5REcz2D wbJ5PFw4sxLMKZ7iWw1FjcR1J6atsVhE3PlfIAoIqSaIFn3B4O5ZIrtCilIKxyGbX4GP n24w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ojkhSGXowTOFmSHQWG2cqG6SKcvkuN71bNnipKEHJw0=; b=0lBQ+oBSsRZZTxqY9FRO5Du+j6l06mlzKrsVp3ZgbcZUNEc2w/yblL8jt4DDUiK9/Q lxKmVtyjPghMbtLRw61QLJgBcg7Q2qW/zKCd29I/fbHDoJ2Ao2sVAotk0qKUw1j+EJYw rnPhlwT/VEbJX991L/+UNyQPOE1Olg0YKX9H546K/xMa8ov5v05HXKhCHYP5Io26RkCL gG9cTzYQaD6Qo4wRAMClUja4SnUBTGZuI/U9MKSLC46B6YqslmSkagORJuOqH8VNVhKP URZFZopz+m6coxRcw0vJJEQr9neNBqR7C2TAg3mZxppqVl1rct1LVh/Ezg15C5fzFcY6 JjbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HaBHq0rm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id n2si10043164edi.362.2020.11.29.12.13.43; Sun, 29 Nov 2020 12:14:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HaBHq0rm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728142AbgK2UKN (ORCPT + 99 others); Sun, 29 Nov 2020 15:10:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:49054 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727695AbgK2UKM (ORCPT ); Sun, 29 Nov 2020 15:10:12 -0500 Received: from threadripper.lan (HSI-KBW-46-223-126-90.hsi.kabel-badenwuerttemberg.de [46.223.126.90]) (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 685F320756; Sun, 29 Nov 2020 20:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606680572; bh=rQ5NWEEEPU4g45U80zBfT28KT/fxWWNh4bB2Arjzahk=; h=From:To:Cc:Subject:Date:From; b=HaBHq0rmQ3UUakU8auzk6mvEnyoOY5gHkt7DdwdL+XdzKV4NuuddNb01IJWJSZQ7J RF7AkL64t8au1LQVxNjL5/nfsTs4eLh3WIfmKxRJZ66nNDHIxVPhiIDTA8E3g446/P TJjkOnrB9/JVN2YyxvcrYkxABSRqQaYcsRJbBcKY= From: Arnd Bergmann To: Anitha Chrisanthus , Edmund Dea , David Airlie , Daniel Vetter , Sam Ravnborg Cc: Arnd Bergmann , kernel test robot , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/kmb: fix array bounds warning Date: Sun, 29 Nov 2020 21:09:08 +0100 Message-Id: <20201129200927.1854104-1-arnd@kernel.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann gcc warns about an out-of-bounds access when the using nonzero values for 'plane_id' on kmb->plane_status: drivers/gpu/drm/kmb/kmb_plane.c: In function 'kmb_plane_atomic_disable': drivers/gpu/drm/kmb/kmb_plane.c:128:20: warning: array subscript 3 is above array bounds of 'struct layer_status[1]' [-Warray-bounds] 128 | kmb->plane_status[plane_id].ctrl = LCD_CTRL_GL2_ENABLE; | ~~~~~~~~~~~~~~~~~^~~~~~~~~~ drivers/gpu/drm/kmb/kmb_plane.c:125:20: warning: array subscript 2 is above array bounds of 'struct layer_status[1]' [-Warray-bounds] 125 | kmb->plane_status[plane_id].ctrl = LCD_CTRL_GL1_ENABLE; | ~~~~~~~~~~~~~~~~~^~~~~~~~~~ drivers/gpu/drm/kmb/kmb_plane.c:122:20: warning: array subscript 1 is above array bounds of 'struct layer_status[1]' [-Warray-bounds] 122 | kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL2_ENABLE; Having the array truncated to one entry seems intentional, so add a range check before indexing it to make it clearer what is going on and shut up the warning. I received the warning from the kernel test robot after a private patch that turns on Warray-bounds unconditionally. Fixes: 7f7b96a8a0a1 ("drm/kmb: Add support for KeemBay Display") Reported-by: kernel test robot Signed-off-by: Arnd Bergmann --- drivers/gpu/drm/kmb/kmb_plane.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/kmb/kmb_plane.c b/drivers/gpu/drm/kmb/kmb_plane.c index 8448d1edb553..be8eea3830c1 100644 --- a/drivers/gpu/drm/kmb/kmb_plane.c +++ b/drivers/gpu/drm/kmb/kmb_plane.c @@ -114,6 +114,9 @@ static void kmb_plane_atomic_disable(struct drm_plane *plane, kmb = to_kmb(plane->dev); + if (WARN_ON(plane_id >= KMB_MAX_PLANES)) + return; + switch (plane_id) { case LAYER_0: kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL1_ENABLE; -- 2.27.0