Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4290433pxf; Tue, 23 Mar 2021 07:23:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1QwB7yRJ1oXrH+d1uvYM6KLmFHA1EceC3kgPADG1xX45nKyX7jOCjYiLaVR6dvK9AUZds X-Received: by 2002:a05:6402:1d39:: with SMTP id dh25mr4983135edb.282.1616509419085; Tue, 23 Mar 2021 07:23:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616509419; cv=none; d=google.com; s=arc-20160816; b=TBl19qpDePEY96Y3C+VcfOyU7/CxdOeMy2YqE+8aBt2//CtPATZ7KhcoIQ47o2sAOJ KjMzfs1cH5qS8cnt/sBZnMQj3ryJDVbKp9Vyqw1teVL2geBZtgNmMDp7GOJY3DPc6H8l /evW7xuTqSMHm86+cRDhbuJO6A23netRMvAiPPEG5AeGt3KusOxouYiSh3l0VjIyfg03 EACDL4Tf3Rjheu+Z302akjKcsTJUWomdthbm/s0cQ2H/6wudH/se+5A21YU77AP9m3yI b0VrhyJSI1Y2s43CaYh/j44hZs9nOx5jSDvGlpJX/A/+kT9+ixKGeUaa8ahHT6kQtz7z DAdg== 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:date:cc:to:from:subject :message-id; bh=cYv0OmrS42SGAiKtZ8zUaMQbSMjNyNMpgSRbsmcCnAA=; b=dc4lWXUUyV+dTvxgpfgDj31frvRJ+plUlLy6hf3+dDk7H7EgvcvIWKsr7w+rM39Q2y smHryO3UrVQ3dF1mQbu+UO0XS6zSERhJ/OqdXgzOTyxR9jqaCKOr7SY0P4ZZ/6PCigTB MzuiMatdHw0hRkJ9f1GBVmEoILgcPXAyyczp2Zvn+8kfSASBYW+vp7KpiCFg0XNR7ubZ mSBCU/fgcyksywiItO5yF805OhL8UuAjQ2WvyljTrLtj0xMGCwVmfqv5nKammTImtHuH xK8qLUzwXiL/YqNCJOMz5CAAngRHv05dhYUnQJtvvvayhjlgWadkK/lObo7eirsA/0kB gFzQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b25si13570790ejv.506.2021.03.23.07.23.14; Tue, 23 Mar 2021 07:23:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232114AbhCWOTi (ORCPT + 99 others); Tue, 23 Mar 2021 10:19:38 -0400 Received: from smtprelay0155.hostedemail.com ([216.40.44.155]:52234 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231718AbhCWOTG (ORCPT ); Tue, 23 Mar 2021 10:19:06 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 5CD28180931AA; Tue, 23 Mar 2021 14:19:04 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:355:379:599:800:960:982:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2828:2901:3138:3139:3140:3141:3142:3352:3622:3865:3866:3867:3870:3871:3872:3874:4321:5007:6119:6742:7576:7652:7903:10004:10400:10848:11026:11232:11473:11657:11658:11914:12043:12048:12295:12296:12297:12438:12679:12740:12895:13069:13311:13357:13439:13894:14181:14659:14721:21080:21451:21627:21660:21966:30054:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: glove95_5b1863d27772 X-Filterd-Recvd-Size: 2732 Received: from [192.168.1.159] (unknown [47.151.137.21]) (Authenticated sender: joe@perches.com) by omf04.hostedemail.com (Postfix) with ESMTPA; Tue, 23 Mar 2021 14:19:01 +0000 (UTC) Message-ID: <7ef41d771af88f84b650ff83771cd59eb745634f.camel@perches.com> Subject: Re: [PATCH] drm/imx: fix out of bounds array access warning From: Joe Perches To: Arnd Bergmann , Philipp Zabel , David Airlie , Daniel Vetter , Shawn Guo , Sascha Hauer Cc: Arnd Bergmann , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Marco Felsch , Laurent Pinchart , Liu Ying , Thomas Zimmermann , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Date: Tue, 23 Mar 2021 07:19:00 -0700 In-Reply-To: <20210323130550.2289487-1-arnd@kernel.org> References: <20210323130550.2289487-1-arnd@kernel.org> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2021-03-23 at 14:05 +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > 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. [] > diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c [] > @@ -197,6 +197,12 @@ 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) { > + dev_warn(ldb->dev, > + "%s: invalid mux\n", __func__); trivia: Any real reason to make this 2 lines? It fits nicely in 80 chars. Maybe: dev_warn(ldb->dev, "%s: invalid mux: %d\n", __func__, mux); or maybe: dev_warn(ldb->dev, "%s: invalid mux: %pe\n", __func__, ERR_PTR(mux)); > @@ -255,6 +261,12 @@ imx_ldb_encoder_atomic_mode_set(struct drm_encoder *encoder, [] > + if (mux < 0) { > + dev_warn(ldb->dev, > + "%s: invalid mux\n", __func__); etc...