From patchwork Wed Mar 24 12:17:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 407802 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp356865jai; Wed, 24 Mar 2021 05:18:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt3MkeJcGnEI8GlaUXLZ/LotNIODW+2qX/4tbz33OBA7zMjY4MLUHBUOFJzNndQEioiSyW X-Received: by 2002:a17:902:b602:b029:e6:cabb:10b9 with SMTP id b2-20020a170902b602b02900e6cabb10b9mr3304145pls.47.1616588323133; Wed, 24 Mar 2021 05:18:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616588323; cv=none; d=google.com; s=arc-20160816; b=HJUJ2VjDeOkx6vhV/LjnKWvJOxfHi6ennR1swoFZUTd4IaJDFk8oBXI+ZfR/NNG6LU 71xStibJjsdgiW3pb/3+kFY5OlHcfeQ7vXASTLWPqIwsTIyLPO+O2kj7Uz+Qbhbv2RvG l0UWgvb489sragHGx9cCQ7zY8mvEbDM6YHR4rLZgyh5gupk6hF3hHUAQzI5aij9K7Sp7 Cp1ANZFdRPhac8kNBP5w1K/oqT3CSZFVc8wQuQd0so7LQlqo2K1XqD8mLktV2tvFWBTv i8lsLCdRyQMiRVyYAJI8X9DAlQW1rLVVt8RLBz4BIaLfAz91DqoCfJZirvTpHJOzulZq fWug== 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=9KYLm66RaV58MaphgFEJ1nQJaV2+MJqMcFz6DSKHS1A=; b=tMavmdVDQDErkaLKMAdfQk+NQkonQcvSCcJJA9o2qQfkkm/RCRZrnDTEoj6K6CmKej w2axbSjetOTLF/WmX76x8IOIvFY5lHWKEW+ooZac4pkCMwyhpYd1AkcNaqfn9CpOkEYr 4k9w6cBZZis1IXFCQcOdYsPT+NgCA77SZGbHNh89MbxnlixJxOZo7Qr69GfcVvR2ul91 QmkocLxOWW4IYwmtmaPPFDpv8WPAqVCZ8cHeaS9abA0DlICWjhrxfy5+VC6q9BSGfqSY rcSnYxEoVyYbNoex+8cghI9reNh1UNzfBHpX40+sB7KVxr5bsdSJevh3hqw0+HEIC6lf vpMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=gDP58QSw; 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 x12si1994305plb.358.2021.03.24.05.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 05:18:43 -0700 (PDT) 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=k20201202 header.b=gDP58QSw; 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 5890389E0E; Wed, 24 Mar 2021 12:18:41 +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 6C17089E0E for ; Wed, 24 Mar 2021 12:18:40 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id BCDD361A05; Wed, 24 Mar 2021 12:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616588318; bh=NbapMJTLgnN/hTMuqni8rldYG3iXiZwynRdZVPVSR3g=; h=From:To:Cc:Subject:Date:From; b=gDP58QSwtXffFOGt/cM15NaJiFb9eUeJH6dcmR7F7nEnjkeJDCpSHwo+m2kfrg5XR bRWV03IrQhy6kV7czeIzP2wFQ03EL4GGIzo/wcnyQVA4sdMsC4T6duwBGIVKgfL8Wl t/lPPfviNpQGo0twQRrJwCKBC6PhHvNZ/Vl0vA1bTeWQo6FNvUypNqbFbJl9Tf3rWQ hqlw4dQiFpyEHKlR0meAzJNYZlcgZ+/2iitl6pPKGbYCOGYCxyWDOeHcJP9r+qggAV vK9CubHtwy6ORV+UigJlaj+A77+ZoePMDDXbyl3LoCPilo19lAZ2ed33xT+Z5dTofI jNe0YoloU30LQ== From: Arnd Bergmann To: Philipp Zabel , David Airlie , Daniel Vetter Subject: [PATCH] [v2] drm/imx: imx-ldb: fix out of bounds array access warning Date: Wed, 24 Mar 2021 13:17:59 +0100 Message-Id: <20210324121832.3714570-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 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: Arnd Bergmann , Liu Ying , Shawn Guo , Sascha Hauer , Marco Felsch , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, NXP Linux Team , Pengutronix Kernel Team , Joe Perches , linux-arm-kernel@lists.infradead.org, Laurent Pinchart Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Arnd Bergmann When CONFIG_OF is disabled, building with 'make W=1' produces warnings about out of bounds array access: drivers/gpu/drm/imx/imx-ldb.c: In function 'imx_ldb_set_clock.constprop': drivers/gpu/drm/imx/imx-ldb.c:186:8: error: array subscript -22 is below array bounds of 'struct clk *[4]' [-Werror=array-bounds] Add an error check before the index is used, which helps with the warning, as well as any possible other error condition that may be triggered at runtime. The warning could be fixed by adding a Kconfig depedency on CONFIG_OF, but Liu Ying points out that the driver may hit the out-of-bounds problem at runtime anyway. Signed-off-by: Arnd Bergmann --- v2: fix subject line expand patch description print mux number check upper bound as well --- drivers/gpu/drm/imx/imx-ldb.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.29.2 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel Reported-by: kernel test robot diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c index dbfe39e2f7f6..40310327fa76 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -197,6 +197,12 @@ static void imx_ldb_encoder_enable(struct drm_encoder *encoder) int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); + if (mux < 0 || mux >= ARRAY_SIZE(ldb->clk_sel)) { + dev_warn(ldb->dev, "%s: invalid mux %d\n", + __func__, ERR_PTR(mux)); + return; + } + drm_panel_prepare(imx_ldb_ch->panel); if (dual) { @@ -255,6 +261,12 @@ imx_ldb_encoder_atomic_mode_set(struct drm_encoder *encoder, int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); u32 bus_format = imx_ldb_ch->bus_format; + if (mux < 0 || mux >= ARRAY_SIZE(ldb->clk_sel)) { + dev_warn(ldb->dev, "%s: invalid mux %d\n", + __func__, ERR_PTR(mux)); + return; + } + if (mode->clock > 170000) { dev_warn(ldb->dev, "%s: mode exceeds 170 MHz pixel clock\n", __func__);