From patchwork Thu Apr 15 14:47:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 421780 Delivered-To: patch@linaro.org Received: by 2002:a02:6a6f:0:0:0:0:0 with SMTP id m47csp547347jaf; Thu, 15 Apr 2021 07:54:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWGlX4+aGlzzg/7gk9zRhMgiiu+tHGmWA+2i2t5mqJGBl9d+78UZfGH424N3YzTqm3us6q X-Received: by 2002:a17:906:40da:: with SMTP id a26mr3810638ejk.513.1618498446100; Thu, 15 Apr 2021 07:54:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618498446; cv=none; d=google.com; s=arc-20160816; b=M0Rr2TvUUKH8VwrZMTEZD/kYDASDTUrcm9uorQSZZVWBYSWTBjXkFdCpe6i6ssgtin PtTlD8i0ay0FGQ7kz+Mn7y45UtEOdadGgdIM754dV2CGguI7KXXuXWRbE18g6BVkzW/A 5du/iTV6jjxHVARuO47cgqp2Et+Y0S6yzTqDriHLRJdTtfrmhq3EwFSQHu20YszNd4xa hIvx5ucaMH7d8kTVhZr/ORXKncfH43Udh8BtlKsMtm6fxBf9IfUyZtkF31NorXa1/qLd 82Zfpsu5lxa9H49q5Ko6X5B4Zi1E3VlTcgif9RFRPOlxxcDkk9fU8nRb+Gc84CtOc4l9 S+1g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eyaxKh5VSqFAzDreyR5TCIo1/uVTIaZLu3i9ntaShC4=; b=ZQk3XByqHYo0vThkhwRy0lC0DqyjvuBTdS7hiLJKFK1XQwcZjwSZA8ms/dVlICo72V AoeBm5nZPqGPLHScScUQCP42H2fZ/yR/K8/AKP1c1EXwbF3EPzP/u5PxJmMGIr6Pfbj1 LPMSLQtIrvicXcACRnT/Xr5rOvLswjUbWkBOiY2Rq0ucOwJApB69JI1ydhc8HJ++qugj oJsTsCa4OpcyJjzP8qpu9U8U4Hi8lwbBPwCG1xjvTM2bbqgpJyQolmnkb7/iEvIFsHB+ YA2pVW8nj/eu/YUY/rDNWu9K234LfQxS2enfNiMEbV3XvMot3XaDImCMlDUWkqpuAvtw 8WMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YUwNry29; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b12si2349646edd.19.2021.04.15.07.54.05; Thu, 15 Apr 2021 07:54:06 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=@linuxfoundation.org header.s=korg header.b=YUwNry29; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234116AbhDOOyV (ORCPT + 12 others); Thu, 15 Apr 2021 10:54:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:40358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233889AbhDOOwX (ORCPT ); Thu, 15 Apr 2021 10:52:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4E8D8613C1; Thu, 15 Apr 2021 14:51:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618498319; bh=NP6z82y8UYkzlwGvlhVl2v3BmtjsrN94IHTrZKg4lEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YUwNry29cRl6/JDtL7z2LQ6qWd6ZIVkhN7yThXI+/UYRZbpBwgYPpivcVoIpEnVR0 9VRxFh2v4VUrZYG7rcEMwL8vObFrU6u0nDFok/rH2YX3lqPJQ+dZWmYtCVVIrTOId2 Mit2W+FC6GcRjZJ2NCdzyqwktQIKZEgV5/tVc2QE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Liu Ying , Philipp Zabel , Sasha Levin Subject: [PATCH 4.9 43/47] drm/imx: imx-ldb: fix out of bounds array access warning Date: Thu, 15 Apr 2021 16:47:35 +0200 Message-Id: <20210415144414.833339007@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210415144413.487943796@linuxfoundation.org> References: <20210415144413.487943796@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Arnd Bergmann [ Upstream commit 33ce7f2f95cabb5834cf0906308a5cb6103976da ] 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 Reviewed-by: Liu Ying Signed-off-by: Philipp Zabel Signed-off-by: Sasha Levin --- drivers/gpu/drm/imx/imx-ldb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.30.2 diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c index 2df407b2b0da..3a9d06de81b4 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -212,6 +212,11 @@ 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__, mux); + return; + } + drm_panel_prepare(imx_ldb_ch->panel); if (dual) { @@ -270,6 +275,11 @@ 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__, mux); + return; + } + if (mode->clock > 170000) { dev_warn(ldb->dev, "%s: mode exceeds 170 MHz pixel clock\n", __func__);