From patchwork Sun Nov 29 20:09:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 334463 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp4076895ilb; Sun, 29 Nov 2020 12:09:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTsssNmtqrgzHma6Zbd/SHRaIc6iUUA7i76MG4d7NEyMQk/Rwfs+midReK7lW3VoFphTc3 X-Received: by 2002:a17:902:26:b029:d8:b213:3765 with SMTP id 35-20020a1709020026b02900d8b2133765mr15400670pla.82.1606680576719; Sun, 29 Nov 2020 12:09:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606680576; cv=none; d=google.com; s=arc-20160816; b=XvzdG1plp4pmQy+Uc7bqn8q+bFlXdGtX2nvfjq0jDn5xkUPqCpz9Yk14IHSho+r2jz pqmXG8bxezaXuKG2Hp/zHKOjq0IztzvBKVU1bH6sz8k6OFDBIQBkASY/De121Y2rUQAF Zb5KxDoh1HUiNOCFUvxxCsm+qQJdwC2aXzyk/b5Vyjhs2eLk7J4zgSnU32L7KRAnW9lD AThbSDDYjDg6ppFT33uOHVNhM4wP0QhrHjcRcHacHaFvKH46EyNmWvfKXL+yewhYHwDs H/ZiDlXUFggsYCveo0p/IQBKahCPop2Xd/y/98TtLLDF9yn6Uo70dJH16m5dDzBwPYkJ 9tEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :dkim-signature:delivered-to; bh=32w9yXAM1pmDKewGrMzAKD+OhndI6VdytpFFiUxp22I=; b=B9Aqf5VUuzPu7l72u7BBDL5mfGNqQHZydvKNn4F8BC2+m0Jv0IPS083keaxiRY/Qs9 dJlSMweQDEs7ie2zLdneRk7eKHIZhKRbDV7fErRSSwq/D+rZ5x6Bp0yeqmu0jed3xIo+ Uz64+fBxdnUUFZRfZkEoiTHKy0/aQ5+Fp+o1e4U4QLZc3UshZ3ObQFiaKcUkhWVV1fzW yxi6Wc0UhZJjoWv/udP6VycVnbKUwTC3Oh2j40i3sg0Xgud+a9uhDgMKNtJbCRlTRCof PwFxmLrZJJaJxl4Z1JXnE/kZ5gyeeE4MZEJfUZN04P2Bh3DNA3NJTzFnmLkkxJuvUQk9 92rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=default header.b=HaBHq0rm; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id d5si2690731pgf.195.2020.11.29.12.09.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 12:09:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=default header.b=HaBHq0rm; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 26628892ED; Sun, 29 Nov 2020 20:09:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5C96B892ED for ; Sun, 29 Nov 2020 20:09:32 +0000 (UTC) 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 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dri-devel@lists.freedesktop.org, kernel test robot , Arnd Bergmann , linux-kernel@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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(+) -- 2.27.0 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel Reviewed-by: Anitha Chrisanthus 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;