From patchwork Thu Apr 15 14:47:29 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: 421778 Delivered-To: patch@linaro.org Received: by 2002:a02:6a6f:0:0:0:0:0 with SMTP id m47csp545027jaf; Thu, 15 Apr 2021 07:51:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE5MM1O0N/pWAE+zAJX13wmcmzMcITDdIpP1WtjPdQDqtLvf9ra6XQ0jEbctdS5H49B1SR X-Received: by 2002:a05:6a00:238d:b029:249:cc83:c23a with SMTP id f13-20020a056a00238db0290249cc83c23amr3508670pfc.19.1618498262802; Thu, 15 Apr 2021 07:51:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618498262; cv=none; d=google.com; s=arc-20160816; b=EcjTs64ldqosQAkVOZVENzOpAIafdfX6yXJjE6XDXiJ1p0lj2S1uwgPg0uaURlyMyd 9Ha516sHu7PzBjkV4b7rCqC8KdIMDwqbyI7mcl0PlK6Qqkv7M6vi8pJGOJmkS9sBYYXr wgwHw0sQQ4DutFb+MviM+7AfEzDadjwzuGYDyTFp50H0pFexJ0rnC2KkN47UkMYQEOCI ikO7ACkDO6p9JwP1gmRuLmMWdBUSwZd3Wcy6V4TRDadPziFBxAV3pNp1gcxcvCWQTfCI 2PYTtMVS1A0neIGiiLIXK50qjmiViujYhF5e/oolUSR+R8tuHomLvc4qoGIRayVvMSNn 6Gjw== 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=A70U8QIFYYLmDN37tdz3/NgNZu2my+OWrGeZPo2S+GM=; b=yJjungZQDaZANdBuJVxdsAJtEp5Hq3gqDXeU8TLN/mXDmfAKtuAhZAQM0rSElIJ2XP D8+1tohEmUBLzcYc8q78+xdn2PRlHOJLg5J+facZLttn2IERz8DY2Os+twH9hlXqLKn6 uvj65nq0ZwBvk6q/ow2mfdf/+3jyoLBznrci6dNl33gPvWGeCsK4ZHla+m/uXT80t705 NjFQo0YuLXnybW6T9hS+RiwoHGZaLIfuXXo6CYvCn6R0l8+icqGD6F06phucQU+DRLxM m7LUFayLFk+jRmBVsfWuLfEIaMR1g2A4P2e4ehOMv4V2XO8t6B449OPVsj5hy7TX4T57 Saew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gwgOHYX5; 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 q16si3433886pgg.312.2021.04.15.07.51.02; Thu, 15 Apr 2021 07:51:02 -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=gwgOHYX5; 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 S234097AbhDOOvV (ORCPT + 12 others); Thu, 15 Apr 2021 10:51:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:37724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233973AbhDOOul (ORCPT ); Thu, 15 Apr 2021 10:50:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3CB926137D; Thu, 15 Apr 2021 14:50:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618498218; bh=Nw8MRyPv6hItzUsKE/Wox9Bq6mnbMARlYufUwDjARLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gwgOHYX5Wq5ai41JXmS149gXQdIogHAyTi1wrmo9vWc4E1UUQfl4ziZsxipVGD3LM jWU4BxxL/pFQCBl+wts/4IgDG/2poqiJTEQzbKIps58JQee92uS8IkDRV7Kh9qS33i /M52WZ8nQMNJ54tVcoOa0g+abZOhg8lXBj77xuwA= 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.4 35/38] drm/imx: imx-ldb: fix out of bounds array access warning Date: Thu, 15 Apr 2021 16:47:29 +0200 Message-Id: <20210415144414.492206846@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210415144413.352638802@linuxfoundation.org> References: <20210415144413.352638802@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 b9dc2ef64ed8..74585ba16501 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -217,6 +217,11 @@ static void imx_ldb_encoder_commit(struct drm_encoder *encoder) int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; int mux = imx_drm_encoder_get_mux_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) { @@ -267,6 +272,11 @@ static void imx_ldb_encoder_mode_set(struct drm_encoder *encoder, unsigned long di_clk = mode->clock * 1000; int mux = imx_drm_encoder_get_mux_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; + } + if (mode->clock > 170000) { dev_warn(ldb->dev, "%s: mode exceeds 170 MHz pixel clock\n", __func__);