From patchwork Thu Apr 15 14:47:59 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: 421793 Delivered-To: patch@linaro.org Received: by 2002:a02:6a6f:0:0:0:0:0 with SMTP id m47csp557798jaf; Thu, 15 Apr 2021 08:05:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkWVz5ujOps4aJJwp3XAuqWq7thPZ3YbXIvlF9bhyrKBTFcFJlgRohIpqGOUVR2dJFeg8S X-Received: by 2002:aa7:83d0:0:b029:241:8fa3:3c6f with SMTP id j16-20020aa783d00000b02902418fa33c6fmr3712810pfn.73.1618499125611; Thu, 15 Apr 2021 08:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618499125; cv=none; d=google.com; s=arc-20160816; b=FQwMwCLYYMUQ0qctAgvESdcnbViAfI/yBD7eqj6hRE1wgSPUX2zfOhHRXU9UX5dBng vMAPdkOQneFHhtIbvDiSfCsLuQn7DNnB8LZJXe88hNW86KagAMDEHH6JMLG1KFk0KPEt A2Ea6LhyK8Zhnowvwp9us8wYE6I7apv1aiWh1jGc3a9tg8QshKBchWissosR+DJ+eS1Q qaVXOR4RB7SAIyTN275c7dDzfRYSvHI06L5H3VY/YPHmWa+5ALI7jt/jBOL5+7UUu6F9 6TesWo2cd/E25iid4c+wugH4CwROGULbi96jX2dpKoYHSEz8gKDo/+d2MaNd2WNYWLyX fKlw== 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=nbXkPZ7OAQfZOnzbFMLaMi5NywaqmyhpJtR/Dh5wtrjd+8OiehaMdkhIA1yq8l2BGO bo7RwiG7waxlpM3qT8z0I8Fq0a9jPjQbqta6qE9Jd3/4GCEjOhkDH9F8yh7P3aR6gzhV wAcsa22qs97oiyrD978xvcXYTTxAX/82E2/h1dbHtajcFB29voW7AMMUE12DY0bJoKmd vCzpwTvdKyIkHYW7oH/P9qqPl2kgtcCNGERbOFGoVFWXYrWrRTF3NqHObGB5Tm93JePQ uv+37c4Zo+3c7dUVFCfQxMMlVKQ9SOTNEdAvcEFRUGAYwTTR5h/RZOesZ72LaYvsK69N yXgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mfvaI9jR; 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 s1si2822824pgk.72.2021.04.15.08.05.25; Thu, 15 Apr 2021 08:05:25 -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=mfvaI9jR; 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 S233683AbhDOPFl (ORCPT + 12 others); Thu, 15 Apr 2021 11:05:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:48596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233903AbhDOPCc (ORCPT ); Thu, 15 Apr 2021 11:02:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 704B761426; Thu, 15 Apr 2021 14:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618498673; bh=lcU4DKczLEKRUAQnyQb4jFFbgCf8JhMH6o2UIlf5vnM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mfvaI9jRWtuh4EtZBKQDtSw/467mo+kKwSto2ZvRktIlqiZrhTz1BsWWPXt4erLuf /1llTmvfCdQlFEA3E3Zm/+qn1Nyg1HkZ30EkF290J4Rd9r91RnDFSaBR6/PEOrO4/t SO3bxVVEPPfmc5Kx5q0LiqC32v+NEvsvIkbOoHqU= 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.10 05/25] drm/imx: imx-ldb: fix out of bounds array access warning Date: Thu, 15 Apr 2021 16:47:59 +0200 Message-Id: <20210415144413.334856476@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210415144413.165663182@linuxfoundation.org> References: <20210415144413.165663182@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__);