From patchwork Thu Apr 15 14:48:12 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: 421796 Delivered-To: patch@linaro.org Received: by 2002:a02:6a6f:0:0:0:0:0 with SMTP id m47csp559584jaf; Thu, 15 Apr 2021 08:07:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuXQOStZEE/YtK/Lq+LwwHRd0cmU0MgSvHREcCs1NIpIwGOqC7EIv8mHLb7ByD1n/FJJ+k X-Received: by 2002:a62:76cf:0:b029:241:ba8d:eac1 with SMTP id r198-20020a6276cf0000b0290241ba8deac1mr3411686pfc.71.1618499153314; Thu, 15 Apr 2021 08:05:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618499153; cv=none; d=google.com; s=arc-20160816; b=bkpOhiAYmu2lmR2T1F7wjCYBwDggvdQeJQbAJdcl79C7+dg4CH+HYwLFvLE5rt+iwU mX/N2TZ9by4xb9LrxyHqTl8yK0FUWYa4kMomVepQOT1nUbwwfsyPemjiSGZTmXrix2rp y91vJThrIHPeBLiDdo/igdB05lRhpqcb4UfXDs+rROviyoknElVa6bUiX6z4n9++Ishp jutgBQc9LPu5/aQc3kmMUi6vjhe3hbg4YNBPaAjDGZUytGaTav2tvcWAbrrl07+Abk6w MPcDfHnsXBcKYIrKI1vXAzPyK2w87P050GaUn5z+RSmTTAePmJ/n4stySCLSrq8hQHhA vPxg== 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=h2dFMcZw6X4b5BdyIFBfEpXNvDoyhjoB9azbrQSxCYw=; b=CK/5+Gw2+ymQm0k9d0b5WiqPdFlllaM97thi3n7s3ndfm4n+sageyr79PeLuK684gQ +O6+DLorq+Y+m0hCg0/xi3AJ09ivM95Bzt/UWx7rxtZp5VnmCKiy4Ytp/pEXazVnS7ei a52nS8LNQ71+VVLirpso/0JkuTXO9fuPlca4uIZcdN65YrHFTSPDOSfWl7rBlqC+TCPF jsm71MkdZNZ4bZRvHsH80aLP8d3Xs0TjCyD0rW4bBrWjoR9Rp5lWZEq/gR9w47VodhEt 1q3zlcdIKjhVR6PVREVPQ1fqCHN80Ls/DUjgyizqaD20ECyaQaSYk7F6LOtL+HdJBkwW t1rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=geDI7o1M; 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 y7si3641929plg.223.2021.04.15.08.05.53; Thu, 15 Apr 2021 08:05:53 -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=geDI7o1M; 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 S234244AbhDOPGN (ORCPT + 12 others); Thu, 15 Apr 2021 11:06:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:48874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234766AbhDOPE5 (ORCPT ); Thu, 15 Apr 2021 11:04:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9C29D613E7; Thu, 15 Apr 2021 14:58:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618498732; bh=lcU4DKczLEKRUAQnyQb4jFFbgCf8JhMH6o2UIlf5vnM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=geDI7o1MmR72zOjmnTwMt+czu57O/CPqU6JTE2QbV95FODKfgRO/StJCHss63PRdF i8mNtj7gh5HODI2brQnSbRXSmjy5NhxuyEn3ojgITWNzxeORuAbt3uB4UlHm3XZCFS 4uRtZQmeZpxXc5g7gm41tE3AbWH+4vuZ7v/9OQiI= 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 5.11 05/23] drm/imx: imx-ldb: fix out of bounds array access warning Date: Thu, 15 Apr 2021 16:48:12 +0200 Message-Id: <20210415144413.326327979@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210415144413.146131392@linuxfoundation.org> References: <20210415144413.146131392@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 41e2978cb1eb..75036aaa0c63 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -190,6 +190,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) { @@ -248,6 +253,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__);