From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4DD4EA04FD; Mon, 23 May 2022 20:10:30 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4020542670; Mon, 23 May 2022 20:10:30 +0200 (CEST) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2056.outbound.protection.outlook.com [40.107.220.56]) by mails.dpdk.org (Postfix) with ESMTP id 1C4C941611 for ; Mon, 23 May 2022 20:10:28 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JEtRSnVN0AWsnRv19HwRSCkkEd/fIUzajCAWAS96d75aNljWi2qr4Dppqae/hCazsbAd7LmvqyglBwvRBUyhyd2BPLR0TqxWK3jF11scRZV6HgPs7csF/Z+P0gFegMEwOyoq7fuS8vzCdX1P4/9/tk/Fb4gblGA+W3mQO5jKjBXhOYEsSF4pwMTkz0igxXF3rrup9IqaVHhHv9tptiFCy1zhxMlVSBN0XeCsL7HnXQw9ReXqcg6PUtsnn9GaMJhW5039pb2KIuUbS+seLuVI8ytu2Zmw8okqNe529L87VR4DqHCkgEND7zkwJTUqLaC7/rsqViuBzcMYR9VAf2j9sg== 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=cFURrCBErrvA4KF+Sl4XLXwTzNzxoFc6iZ43DLmo/jw=; b=S6GWVKee97YY2Dr+m9ng3UCHgaHF5KkFBLytlA+4uyTycT7NozkpU2Jke26J5ccTmBSrWSEPR90/XHAVSPQkY5FZrceweui+Gfhu9N3AmWkT+JXIA161/f4BVezdTHDGEuFDQ642ztXsvtr7xL6mCOTiO/1/xIxlVlb4A1OKFXp/iCFsqvoiScsgk3841RXUIZsrtpqCJUS10wnta2GuUAYAkI47KeTpjIAoUaY5gFBv0W8gtvZGiZB1fijrX+8vw9SNaNWLv9JUZ9WCXnkk6X6T5tSR1DeIEVin/os+DTBqJilMRRIMcejM5aQ9WRSKGM+5Ny+dvXDzWU5uShiu1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 149.199.80.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=fail (p=quarantine sp=quarantine pct=100) action=quarantine header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cFURrCBErrvA4KF+Sl4XLXwTzNzxoFc6iZ43DLmo/jw=; b=Nk/fxA6J3jpUoS6Q2jGr8E+n9HxfMtW2uAbcve+SdKffcjE1AHQ1eRTorYeBiqtz9G7jLSiwAA7x6nEf5Iqyon/cx+GdCvFAH0CxsPyaFj02JkW81obpz+OLoJgBmfQPipe7ExNUDfc8UPtkmbvBQHmdHNFwyDHkHcI4xzYCMXI= Received: from BN9PR03CA0535.namprd03.prod.outlook.com (2603:10b6:408:131::30) by SJ0PR02MB8627.namprd02.prod.outlook.com (2603:10b6:a03:3fc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.14; Mon, 23 May 2022 18:10:25 +0000 Received: from BN1NAM02FT054.eop-nam02.prod.protection.outlook.com (2603:10b6:408:131:cafe::1f) by BN9PR03CA0535.outlook.office365.com (2603:10b6:408:131::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.16 via Frontend Transport; Mon, 23 May 2022 18:10:25 +0000 X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 149.199.80.198) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=fail action=quarantine header.from=amd.com; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning amd.com discourages use of 149.199.80.198 as permitted sender) Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by BN1NAM02FT054.mail.protection.outlook.com (10.13.2.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5273.14 via Frontend Transport; Mon, 23 May 2022 18:10:25 +0000 Received: from xir-pvapexch02.xlnx.xilinx.com (172.21.17.17) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Mon, 23 May 2022 19:10:24 +0100 Received: from smtp.xilinx.com (172.21.105.197) by xir-pvapexch02.xlnx.xilinx.com (172.21.17.17) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Mon, 23 May 2022 19:10:24 +0100 Envelope-to: david.marchand@redhat.com, dev@dpdk.org, thomas@monjalon.net, andrew.rybchenko@oktetlabs.ru, xiaoyun.li@intel.com, aman.deep.singh@intel.com, yuying.zhang@intel.com, bruce.richardson@intel.com Received: from [10.71.119.126] (port=9787) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1ntCVc-00044E-1F; Mon, 23 May 2022 19:10:24 +0100 Message-ID: Date: Mon, 23 May 2022 19:10:23 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH 2/6] app/testpmd: register driver specific commands Content-Language: en-US To: David Marchand , CC: , , Xiaoyun Li , Aman Singh , Yuying Zhang , Bruce Richardson References: <20220513075718.18674-1-david.marchand@redhat.com> <20220523071031.1868862-1-david.marchand@redhat.com> <20220523071031.1868862-3-david.marchand@redhat.com> From: Ferruh Yigit In-Reply-To: <20220523071031.1868862-3-david.marchand@redhat.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b7c54fd8-06c1-4ae2-7a27-08da3ce782a8 X-MS-TrafficTypeDiagnostic: SJ0PR02MB8627:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 2 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MAsdEtGuMjLEJlS8a+DxKzfAW83l87SUEvuIMhg6IYCUjDQUQQVz1qzUsRbKrNWpH771QNSV+z46YBgOTYGaqDfZmJgE5MxweE6fNsolTLxUUKOhNiOc91vd1+SvG6wSZGjOQVvoJn5PL2RGb+JbwoiQTRvWtXskVpfYjRlgTJLefQR7kBIcJtZ84luiyZ29vxMnWLtgXbMxjXnnd73g+/AJrJ+G3MQaPY+Hm9wpGS3O8VZAj1TiiQ/Q/FCPP9y3bTQkNOi+yO17k/lFlXAYcpjiJiCJHQbqjtfSWfsRH1C6pG9C1G/fHomq02mR5OBe6N9+k1HhpJkR0Ae87JI3hPauH2BcuEG2s+Tk3Jkb66VH/9gY984oCy2GddY0clMByB3k6pwyYtJR9MrOo7VSMDyRMVrqZ3Mle0f6tY77H8XuShBhQcN+PfXs077JUDT4WNBvTDyxj9bkAR72B3s/1ABidPuMv0SxnV4HfV32Rl/bSXnTWidoWmwRM3D5XYVx92KpgsSOl20rkNtAC1oGTDiz1Ho3NWCSN6dTdTEJ85/74hNxIFm8EZwy9jbjLQ1ivXFFcs/HTPrskj/Hz+B7RmBPmX2OfWylrMnp1UGA23ILtJVFowfLCtoO4VnzOQU9nWR4BFvG5B9pHJWOhWnqEU5JltE1htLbngpguIyIGwmmcNyNBv+KxNIU9M+7Yxe/OLh5g0kU7HVHZHEAK78pOSMyglHEfSlnQsbDyNsS4q7YfADlIR8+2RSyrT6ddFO6 X-Forefront-Antispam-Report: CIP:149.199.80.198; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:xir-pvapexch01.xlnx.xilinx.com; PTR:unknown-80-198.xilinx.com; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(2906002)(8676002)(8936002)(7636003)(4326008)(70206006)(44832011)(31696002)(86362001)(9786002)(70586007)(5660300002)(35950700001)(356005)(36756003)(336012)(316002)(31686004)(2616005)(110136005)(53546011)(26005)(82310400005)(508600001)(40460700003)(54906003)(83380400001)(47076005)(50156003)(43740500002)(2101003); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.onmicrosoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2022 18:10:25.1662 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b7c54fd8-06c1-4ae2-7a27-08da3ce782a8 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.80.198]; Helo=[xir-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: BN1NAM02FT054.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR02MB8627 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 On 5/23/2022 8:10 AM, David Marchand wrote: > +int > +init_cmdline(void) > +{ > + struct testpmd_commands *c; > + cmdline_parse_ctx_t *ctx; > + unsigned int count = 0; > + unsigned int i; > + > + /* initialize non-constant commands */ > + cmd_set_fwd_mode_init(); > + cmd_set_fwd_retry_mode_init(); > + > + main_ctx = NULL; > + for (i = 0; builtin_ctx[i] != NULL; i++) { > + ctx = realloc(main_ctx, (count + i + 1) * sizeof(*ctx)); > + if (ctx == NULL) > + goto err; > + main_ctx = ctx; Instead of 'realloc()', check and assign pointer in each entry, what do you think about first calculate the size and alloc once, both for 'builtin_ctx' & driver specific command? But of course trade off is to loop twice in that case. > + main_ctx[count + i] = builtin_ctx[i]; > + } no need to use 'count' in this loop, since it is always '0'. > + count += i; > + > + TAILQ_FOREACH(c, &commands_head, next) { > + for (i = 0; c->commands[i].ctx != NULL; i++) { > + ctx = realloc(main_ctx, (count + i + 1) * sizeof(*ctx)); > + if (ctx == NULL) > + goto err; > + main_ctx = ctx; > + main_ctx[count + i] = c->commands[i].ctx; > + } > + count += i; > + } > + > + /* cmdline expects a NULL terminated array */ > + ctx = realloc(main_ctx, (count + 1) * sizeof(*ctx)); > + if (ctx == NULL) > + goto err; > + main_ctx = ctx; > + main_ctx[count] = NULL; > + count += 1; Above block also can be avoided if size calculated in advance. > + > + return 0; > +err: > + free(main_ctx); > + return -1; > +} > +