From patchwork Thu Apr 15 14:47:52 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: 421786 Delivered-To: patch@linaro.org Received: by 2002:a02:6a6f:0:0:0:0:0 with SMTP id m47csp554065jaf; Thu, 15 Apr 2021 08:02:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzh1dm1f/WuNPYaHyPSuYVFKev5AXU1McwZuzMqxXb7V/fr5gk2plPgcsh9FjkvFtO1ir+O X-Received: by 2002:a17:906:29ca:: with SMTP id y10mr3969772eje.250.1618498922824; Thu, 15 Apr 2021 08:02:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618498922; cv=none; d=google.com; s=arc-20160816; b=NQswImJCTFAqjtQwJMFPD+iKNqsi5VgeEIXV6zimncioH7g5SC0MonwVWQqGIy+xUs cXIlm0CbjD6HY67itOVAPc87xAfDH/n5z8SN4MFFOMzY0AuNmnT3A4Qr+frw8Ib6U9Up sBdaJpOKrXUTEpTP4gK0JDkyofnKkGkyec1atranstcmgTkyYuQhexMVHop0h0KoOtFG Z4+RqODr4rzWd0EQkIIt7a19oLtiA/RpTqPb4F1m/9TrbBDFPLw3WKX6EIf+L/nyp1n1 YAQnAvefQvkmc2aUQWOD0dOcdoPGj54I+MaODLb8q+98nlq7E05Yur5boeUD5pjT0hWB MqXA== 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=XkPdNVaNQcSy6cEWQ8rO6MjXPFYgkoQL1AcvqptpAz4=; b=hSXz7yaBdU6suGdpjO/6VBA3WcdyQqAif5DNy387BUqa39ucx/HnJaXKvU/mYb11/3 VQ2FN7wlHmWUcZocm7z3So/sOEpTrL+ftmP31K+o3YllKDL+5Ey9jl0l3+EFtReJGRNN ZkQr5m4ecHgfWs74I+ZcU5hgDZbPO5zgHMHds8M5vRBXHf38Eqgw52vDNBTASlXwavdm Jv0aKZa9HCOsO8MBFkoqo0rRpuneaftUjfo96CbQ8MEVTFT9khmKUi4Fqv9ntn2VT0nf nzN+/FTs13SzZdcuyXriTUZAzg998+ZUoGyI82c9xnSeCoeWsO2/TCMssqaZaZES0qKB avjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zFmk8hZW; 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 b13si2713610ede.461.2021.04.15.08.02.02; Thu, 15 Apr 2021 08:02: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=zFmk8hZW; 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 S234140AbhDOPCX (ORCPT + 12 others); Thu, 15 Apr 2021 11:02:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:46934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234907AbhDOPAI (ORCPT ); Thu, 15 Apr 2021 11:00:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 79B4861406; Thu, 15 Apr 2021 14:55:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618498556; bh=/OqoiyF58eJ1ZX2Sbi4gzBwj/jNfSytLlR1vYZznEso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zFmk8hZW+/GtwqxS56QSdICPahl65zZ5FCpBGrnGx+4YGawVpLBvbSLPCPuJv1odx xaVXF8j+rQx89uvAHwoKHrdbpk8MCMKpXymOpR9JihhNiJa+UhutXCtaTt49ll+JQd vLS2Wn+rIfsPXl+5AqFaDvbkNYxsGpeLn2cpNgzI= 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.19 03/13] drm/imx: imx-ldb: fix out of bounds array access warning Date: Thu, 15 Apr 2021 16:47:52 +0200 Message-Id: <20210415144411.707717946@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210415144411.596695196@linuxfoundation.org> References: <20210415144411.596695196@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 221a8cbc57f9..a4dba034dca4 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -206,6 +206,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) { @@ -264,6 +269,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__);