From patchwork Wed May 3 10:30:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ferruh Yigit X-Patchwork-Id: 126669 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AB0B442A4E; Wed, 3 May 2023 12:31:17 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 833474114B; Wed, 3 May 2023 12:31:17 +0200 (CEST) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2088.outbound.protection.outlook.com [40.107.223.88]) by mails.dpdk.org (Postfix) with ESMTP id 53E3741144 for ; Wed, 3 May 2023 12:31:15 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GKv89ZAWE5+tbhqWhG0AbGiS5FMl1yGYz2olKN2smx4ETkMsxoWXiBNTcmmNoqy9IoNQmF+TBnZhUuwVyLfkPurZVqCJWuRSuVxmCEq3rvUQsSg0EQ7F2rRfsw5CoAMiYR0EGfgwVqegFNnGQnXTp4xG4HqVt3yfPGw+XXxePrB7cfxJTOCSXLKIr5l2QzUaFkDX0OFkbb56TSIQ76TLaR6ARieEmaWXRnX/qSzURjrZx3k3hPiXEi3mar42kDdVPFZcG71BoYqhW5TsVWS2teJlFgK5xfLNdVQg4TGFp/8nn24Cq1C4UzXcwBKc3+pArPkEv1ptzA2Gubqqhy03IQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7byb1pDC1htfz3GMFs5hHaRzzVcRmaby5+Rg8GCyMM4=; b=KpUfxGWQcyU/nm7PxgiLSSvpbWLM/QcgDMKSGvZMdIGaiZ+u463ix5ljK+9w8fvJtxa4YLBrM8hOvecLWJ2ELIKKQPA9Y4B5y0GVPSfQKg4dMop8IKfmX1DuvVW506oI61IWn6XWyvoEBTCOcNt5KU0U3We8DuaXtGcTiHqI83s30gJEnlNEdbUiSZqluesAguoAB0tZcfkljHPjpm4cRJo4MFIn69M09O5cvvso1ujQOX52h0igYiW3fW7vdH/850JoY/qt4hPwsUXmXmJv8xB2NWG/+SgXGQRZ71QaambAXuNH3iaZVb6a6CSU+tuYhoFLRkCdRrP9V4BQezExVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=monjalon.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7byb1pDC1htfz3GMFs5hHaRzzVcRmaby5+Rg8GCyMM4=; b=WpVsEhKO2zONT+m6LaKoRyNpiXQh6ws4IN2NrgVY5Drv05Ss/zqQf4RNwhDKGWaj6JYGEmtecJPenuunSMap9/UVo4FqSCu5jfYc+TBWqcF92f09OzCHopUf0Ympl2uZ2wcrl1yKuuE0o69ubqfJ8Te9SrnZkz+Feq+dB3VRwFc= Received: from BN0PR04CA0145.namprd04.prod.outlook.com (2603:10b6:408:ed::30) by MN2PR12MB4405.namprd12.prod.outlook.com (2603:10b6:208:26d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 10:31:12 +0000 Received: from BN8NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ed:cafe::21) by BN0PR04CA0145.outlook.office365.com (2603:10b6:408:ed::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.22 via Frontend Transport; Wed, 3 May 2023 10:31:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT066.mail.protection.outlook.com (10.13.177.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.22 via Frontend Transport; Wed, 3 May 2023 10:31:12 +0000 Received: from telcodpdk.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 3 May 2023 05:31:10 -0500 From: Ferruh Yigit To: Thomas Monjalon CC: , Bruce Richardson , David Marchand Subject: [PATCH v2] devtools: allow variable declaration inside for loop Date: Wed, 3 May 2023 11:30:53 +0100 Message-ID: <20230503103053.3087445-1-ferruh.yigit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230503095018.1710769-1-ferruh.yigit@amd.com> References: <20230503095018.1710769-1-ferruh.yigit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT066:EE_|MN2PR12MB4405:EE_ X-MS-Office365-Filtering-Correlation-Id: b3804f6f-037b-4cb5-4a26-08db4bc1844c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ihZzuF5koPEkWjVSlh28etroX3/f2UDo03QroY0tyOIEN891VsB5yyEu2bOr4pIhDmrLQoIuyy+UXrTiOEeH2fZgcTU/mMgAh+K1aAwF9yBfu0/Dq8hf0zDDbzydHa+9W/v7i7DSSgY5QkutiM071DHEuq2T/maLNWH0arKmDUKzGm5CIgsMGaKPjglOu+saOd7jquBdTEpFB/wtBoZ4X/5koc+JC9GXzEcSTks7p/PFZ439s7TXW9TKBf1ONI2GbuJr1a4eqIkxHthnDEVeyF0CQYj0ml96+h/O/Zob2Y4M8KYnexlq9sqTCfVCL4/nXvPN3mI3lR0o8g/OT63/SUV94iu508LmvLC1+tNF4Sn3doGEECwROhl+bf8jHNa+N844QvsKKG6aHHooDKN9g3+i1echFp95KV/fUZazPkN9aGGtht3oX7pl1AwC+ZyxGD0ujorK1uvlPJcA/z1HfYjH5bGcc15haUHORrThf6hKmjl10qkeYfcV29Ts3wTKkSDYAxqmF3mmyZ+BByH210We6WG+Ll5dtLkIm8bRQ3MsffUVJfPMUUtKaWEpt+CH+2xHY4vdp1ym/Xm0RlcA34u2XItUfeNcgdqVBxEtYuwNuE8DdyyL5G+xHmRnfpGez5vom+mVQRvnrmeEZ6zPJEdDvLiQ/8FBm6fA//kV995t0YJvYlrDFiArXGnR9X+SombIzHjm1dhtxAYo7Mb0QA1XiLTgAFtrlndTuHwZHWaiNLhpl01lCVvnK5LXs2a1 X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(346002)(451199021)(40470700004)(46966006)(36840700001)(356005)(81166007)(5660300002)(41300700001)(8936002)(8676002)(70206006)(4326008)(316002)(70586007)(82740400003)(2906002)(40480700001)(40460700003)(86362001)(44832011)(16526019)(966005)(26005)(1076003)(186003)(7696005)(6916009)(6666004)(426003)(336012)(83380400001)(36860700001)(47076005)(36756003)(82310400005)(2616005)(478600001)(54906003)(21314003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 10:31:12.2951 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b3804f6f-037b-4cb5-4a26-08db4bc1844c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4405 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Declaring variable inside for loop is not supported via C89 and it was checked in checkpatch.sh via commit [1]. But as DPDK supported C standard is becoming C99/C11 [2], declaring variable inside loop can be allowed. [1] Commit 43e73483a4b8 ("devtools: forbid variable declaration inside for") [2] https://dpdk.org/patch/121912 Signed-off-by: Ferruh Yigit Acked-by: Bruce Richardson Acked-by: Morten Brørup Acked-by: Tyler Retzlaff --- Cc: Bruce Richardson Cc: David Marchand v2: * Update coding convention too --- devtools/checkpatches.sh | 8 -------- doc/guides/contributing/coding_style.rst | 1 + 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 15d5d6709445..b5baf6f2b161 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -78,14 +78,6 @@ check_forbidden_additions() { # -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 - # forbid variable declaration inside "for" loop - awk -v FOLDERS='.' \ - -v EXPRESSIONS='for[[:space:]]*\\((char|u?int|unsigned|s?size_t)' \ - -v RET_ON_FAIL=1 \ - -v MESSAGE='Declaring a variable inside for()' \ - -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ - "$1" || res=1 - # refrain from new additions of 16/32/64 bits rte_atomicNN_xxx() awk -v FOLDERS="lib drivers app examples" \ -v EXPRESSIONS="rte_atomic[0-9][0-9]_.*\\\(" \ diff --git a/doc/guides/contributing/coding_style.rst b/doc/guides/contributing/coding_style.rst index 89db6260cfbf..e18b8d4439ea 100644 --- a/doc/guides/contributing/coding_style.rst +++ b/doc/guides/contributing/coding_style.rst @@ -558,6 +558,7 @@ Local Variables * Variables should be declared at the start of a block of code rather than in the middle. The exception to this is when the variable is ``const`` in which case the declaration must be at the point of first use/assignment. + Declaring variable inside a for loop is OK. * When declaring variables in functions, multiple variables per line are OK. However, if multiple declarations would cause the line to exceed a reasonable line length, begin a new set of declarations on the next line rather than using a line continuation. * Be careful to not obfuscate the code by initializing variables in the declarations, only the last variable on a line should be initialized.