Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp740402pxf; Wed, 24 Mar 2021 15:00:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz77jN6FpESQ9tUako1EGSweRu33TldEjcfJ1/DzUW8fsmeR3c5EDhQFsSM2mCN8UOq6Qem X-Received: by 2002:a05:6402:b85:: with SMTP id cf5mr5802738edb.248.1616623236806; Wed, 24 Mar 2021 15:00:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1616623236; cv=pass; d=google.com; s=arc-20160816; b=PvAKNcvzsY6CN8EkcdxIgEREyU0OtM12IzVLVghypDYB4AJbReHgLm/CuzFYS5dJYr odT1hDm+OY2OO3uleNjrtIc3stQt6dgdzeB1akzbc8EcII+oK/CrShZZ3qRqX4O2fu7d uHArS94fduLgT7HGfEVl8uNhb6rg3Sfxh/ue/88doiIE8uQeh9FTCF0kCgazrc2cjFdL gJgJLLs8E5BzGwWqYnb6mmeLChavO1Z89bCk3+SkZVxUfFe9r1a8njoRCeERslLh9AHO Gx2hix0UGSfEnvQRJsVxCp7e54i16SwbRG4jN+f1zl7iMufmYD1GkzvuHfrHK4jjw7Yf VAPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=Z3msbDLVig5TDeBeIUNlcBBjUdrbeWlg7fEQYMYDJ1I=; b=gbphnKnLOD6tYb/6nmVtqZJgAmSVMGII4CtNgsKwIVIdq/DKxS8yOY79GVt1tQBKHs eW8xWY84lO8WMn4sJq+RC401GZpt1j8XWs/9JgtG9U71OeoNVwpy9i2q4caQ3nRwnZ5B wV+0HFO4j5/2eJVaZ6MllMM+U4/vAb2ifns3D69oTnOFW7KGUjsndOpsqLOns2nfaaf0 X0OT8D5oGxZMgbhpa3NPZUJIlLjKsqSG7IGK2OzawswO0UUH78pEoBZKuXAhyLQddiww 2on9vhiELt4fnCUlVG/OK3VJi24XYQFWzwFUrMpa76zhQrYj15PrxirCiHwl2INp5eAs GpNA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=pIXX6pSW; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d10si2712440edz.305.2021.03.24.15.00.12; Wed, 24 Mar 2021 15:00:36 -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; dkim=pass header.i=@nxp.com header.s=selector2 header.b=pIXX6pSW; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232029AbhCXCxE (ORCPT + 99 others); Tue, 23 Mar 2021 22:53:04 -0400 Received: from mail-eopbgr20087.outbound.protection.outlook.com ([40.107.2.87]:64537 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231655AbhCXCwa (ORCPT ); Tue, 23 Mar 2021 22:52:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JYJg2dsiQXRwaQTqW0qiY69SWZqbZNUrNn9WDSJvYqgnQqpnqFxiPzOtQ72v1/srEjjmgUktLtIUSY1NwJuYxBHHQMMfrHbOpHsJyqOcsKiPLu9jEIU+3vD1joE63SeoBCabh2Yq2Kyoe55UGH6tJaX+3rlWoTSj5Q4KdAd8ybUtlsk4M7b7VGWKQOb8u6EUYOFN4nHMFdkpGO1T1vdgr9PBarXq2J0kN71gEIe9QOg/CbguY4Ue8ja/yJmPvSJGgzt0LoJXVO7Z/P7r/oVWp1c+5u1NxQLzlK/qQw4HihLWrdANbG4+quk9i4Cgytfv9iuNB+oS0VlqKajIeQopuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z3msbDLVig5TDeBeIUNlcBBjUdrbeWlg7fEQYMYDJ1I=; b=Um+qRwimqH6a1NaMIlPKjorM1izrvyhZETZJTcvfMQ0d6X81FPH3uRJHnXv+iUhzYm33eCjRrBryqRaGyQS4c3hsgwzGf1PtWZgrKKzsj9euXAt5z13tOWbQF2FoT6d20pdJNwOGx6BAB/DUqBNojQn0QOsbHXlr4NNLedmrl+oWT3AOdOyep2yFw7Lf2og8Lk6vAX3mPxrlr/2DaDazmELMgkr1R0n4b7N2TZm/cEBRsK0T3CJIojvzFUydzfkQMkEzzVllPr3j+sUxCmvG1VkBulJemG9shCDPNlYbsmVe0mRkFrbbfHjpK/MmXu5aCJzxBfOWa6M3CWW/yRbrew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z3msbDLVig5TDeBeIUNlcBBjUdrbeWlg7fEQYMYDJ1I=; b=pIXX6pSWmwy3RHevD3MJHWN41xRWyg7pHYFb28r8nLOaMKSQ8ROlNfcItWk0b5eMYYr7oDxKBdUWgTADyTZlvZZJGUr/G4UE6KLqlg3tn/lhwzo7kAH5C6O+iqrbSGgJUcdSx1tnkAw5Oebb4RG9ad11hsoeFxHtgZj4XH9omGU= Authentication-Results: perches.com; dkim=none (message not signed) header.d=none;perches.com; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB3983.eurprd04.prod.outlook.com (2603:10a6:803:4c::16) by VI1PR04MB5181.eurprd04.prod.outlook.com (2603:10a6:803:62::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Wed, 24 Mar 2021 02:52:23 +0000 Received: from VI1PR04MB3983.eurprd04.prod.outlook.com ([fe80::3ce1:4759:5c33:514c]) by VI1PR04MB3983.eurprd04.prod.outlook.com ([fe80::3ce1:4759:5c33:514c%5]) with mapi id 15.20.3955.027; Wed, 24 Mar 2021 02:52:23 +0000 Message-ID: <957096a844761fe3069eff983ff308ae65e8d47c.camel@nxp.com> Subject: Re: [PATCH] drm/imx: fix out of bounds array access warning From: Liu Ying To: Joe Perches , 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 , Thomas Zimmermann , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Date: Wed, 24 Mar 2021 10:50:49 +0800 In-Reply-To: <7ef41d771af88f84b650ff83771cd59eb745634f.camel@perches.com> References: <20210323130550.2289487-1-arnd@kernel.org> <7ef41d771af88f84b650ff83771cd59eb745634f.camel@perches.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.4-0ubuntu1 Content-Transfer-Encoding: 7bit X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: HKAPR03CA0023.apcprd03.prod.outlook.com (2603:1096:203:c9::10) To VI1PR04MB3983.eurprd04.prod.outlook.com (2603:10a6:803:4c::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from blueberry (119.31.174.66) by HKAPR03CA0023.apcprd03.prod.outlook.com (2603:1096:203:c9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.10 via Frontend Transport; Wed, 24 Mar 2021 02:52:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e146848d-253f-42e4-dc76-08d8ee6fd9b8 X-MS-TrafficTypeDiagnostic: VI1PR04MB5181: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:338; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 53wuYKoV9lhPKt/p1fU6COmcCv+1yJip1L24nsjd4PgJMtZe5eFZgXQK7h2+C3+IIw5SZp5MbXWFCxg+53dPF20F9smHeTlxL20Jpt9+/OunynhwZHakkRUZm0/cLmccu/dC1Q/mnES+cpZ3z2uSdc58WdNVSD6WaP6THFjop4eqCmZ4+m+D3QeizZozHcdGoHMVC/N+IOCRtwalqCD6NSMzU5Rh37PlMeAtWs8gwhrxMxjWkD2wBq5QEyQYCNaKf/rOxkQdH9Adqu4GjfGcGrs5QTLZN/RfhQo+/9jm8gwhy65p4MIU8dlTgtESNNVkvw0/wTd/SJuOKP1lqrBqCgyEWyK4joCGvW4hi4dooZKBVhtnXxAamBGfVl4Sy/mzK7+RSK+l2ebl9mWtulryk4qx5AKkM/Fl/RBLHT/C1BE6E2VLdKSOgy6/lgQdj+ULc5SZCM3HX44u3j4DiB5gLCd6dgrBsTTG/YBJW2MSNAk8yLJCgxbRzwqZ6T0df7C2RXgIMWqu7tls3YE0MLokwiVTVwgaJq5U0lqbTlabqlYR6aSkKRHvQKRPpROJIvxgPYITGU7WHRkPZS79ezFt1CqxQs8auu5Ve4RmuGBZ6mpavCFw7lC7H4OC1cSTRwx/EdtRfawECTTrDcCaqitHGg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB3983.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(5660300002)(4326008)(2616005)(36756003)(186003)(498600001)(6486002)(54906003)(110136005)(66556008)(16526019)(66476007)(956004)(66946007)(26005)(7416002)(6496006)(38100700001)(83380400001)(2906002)(52116002)(8936002)(8676002)(86362001)(6666004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?SXVlUHFvbldBMGt6b2FZbGYwZkw4V0JHTWQrdHRQc0pvTTNJeDNCRllLMjdO?= =?utf-8?B?cm9BRUo4VytXbTg1M1ViREUrM0hBSCtlSXloYkFPWWxFOGs0RmtoTHpRbG5I?= =?utf-8?B?WHNSbzF2am9KVkJyeGIzZ0dpNHRKNW1PeGpUb3hWVVBGNVNXN0t4aExTOC9u?= =?utf-8?B?TnhwRHU3UmFnWE9ma0JlNmFxS3d0Qy9IeEVtVDRYaHM0VEZtTCthdk5WejZD?= =?utf-8?B?YzZ0azkyYU5GRVRIWFZGWjVmU3A5Qys2UEgxaUwzb01OQm5Qa3ppeWR6L1Nk?= =?utf-8?B?RldDbXVhbm1TR0tIaU9uOUFSN0dFMU95a1N1OXFVNGdwOTNkUG5LNlp6dDZw?= =?utf-8?B?K09XZTc4VnNzWHllQlBnZHBxclYvajBjOUxJcmNaRFRWbVlPSlhsTDVYNUgr?= =?utf-8?B?bW9NMDFwbVNwMGRYVStzYWpIZnlEVzltSnY1YTlMaFpISTBIR3Q5OTNyWEVt?= =?utf-8?B?R01SelFoa1IxV3ptV256NkRUYVlySTZUZWhrSkNsMHlQYi9BYWJmZHBEclBO?= =?utf-8?B?QTc1aVAxN2h1V0xJS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vMEpwVzJQYjBYQVY3UkUxekZzYlhWSjBvNHZhVUVjOEdRcTMr?= =?utf-8?B?ejNxTlV0cUs4OFFrTmw0cUhIcXlhTThkd0N5cjVPVEZYMWFXK0RMazM2R3Jp?= =?utf-8?B?YmlWVktRempkNXBaYTRnN1NVUHI5a3g1S2hmR21UU3liWWw2SE0vcXc1U2VT?= =?utf-8?B?UHoxNm5rZWhNeWxYRkFPTVNNZjhIUWtjd3MzSExVN1lFbEh5d3ZZclBsSEo3?= =?utf-8?B?eVpXZWlEaGwzNHB0a0lMRGxmZW03K2FZeFc4MU42WTJKdHlPQ3M4RjY4QkZW?= =?utf-8?Q?fVk99KIb6wcSq9kzL98ESJ10hczn8vRpQ8oFIQy?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e146848d-253f-42e4-dc76-08d8ee6fd9b8 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB3983.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2021 02:52:23.8724 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CbboxsKkfgFLG/GXPnqls64rbOgDTEY37qWYCx/oJM8YUHPPYsbsFBbiUflXnC+bi6ttlAjvp8/IsuBfHWGfIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5181 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2021-03-23 at 07:19 -0700, Joe Perches wrote: > 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)); +1 The second one looks better as it's more informative. Regards, Liu Ying > > > @@ -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... > >