From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0F2E6A0471 for ; Mon, 9 Sep 2019 11:56:13 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 768C21EB1D; Mon, 9 Sep 2019 11:56:12 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 54E941EA42 for ; Mon, 9 Sep 2019 11:56:11 +0200 (CEST) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 02:56:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,484,1559545200"; d="scan'208";a="335543512" Received: from yexl-server.sh.intel.com (HELO localhost) ([10.67.117.5]) by orsmga004.jf.intel.com with ESMTP; 09 Sep 2019 02:56:09 -0700 Date: Mon, 9 Sep 2019 17:53:59 +0800 From: Ye Xiaolong To: "Wang, Ying A" Cc: "Zhang, Qi Z" , "Yang, Qiming" , "dev@dpdk.org" , "Zhao1, Wei" Message-ID: <20190909095359.GA25843@intel.com> References: <20190903221522.151382-1-ying.a.wang@intel.com> <20190903221522.151382-3-ying.a.wang@intel.com> <20190906161258.GA108591@intel.com> <44DE8E8A53B4014CA1985CEE86C07F2A0B989DD6@SHSMSX101.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <44DE8E8A53B4014CA1985CEE86C07F2A0B989DD6@SHSMSX101.ccr.corp.intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Subject: Re: [dpdk-dev] [PATCH 2/4] net/ice: rework for generic flow enabling X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 09/09, Wang, Ying A wrote: >> >+ice_unregister_parser(struct ice_flow_parser *parser, >> >+ struct ice_adapter *ad) >> >+{ >> >+ struct ice_pf *pf = &ad->pf; >> >+ struct ice_parser_list *list; >> >+ struct ice_flow_parser *p_parser; >> >+ void *temp; >> >+ >> >+ switch (parser->stage) { >> >+ case ICE_FLOW_STAGE_RSS: >> >+ list = &pf->rss_parser_list; >> >+ break; >> >+ case ICE_FLOW_STAGE_PERMISSION: >> >+ list = &pf->perm_parser_list; >> >+ break; >> >+ case ICE_FLOW_STAGE_DISTRIBUTOR: >> >+ list = &pf->dist_parser_list; >> >+ break; >> >+ default: >> >+ return; >> >+ } >> >> The switch blocks in above functions are the same, it's better to use a common >> function to reduce the duplicated code. > >The switch blocks in the above two functions have little difference in the default behavior, one is return -EINVAL, the other is just return, for register/unregister funcs have different return value types. So, Can I just keep this format? > Duplication is bad and I think it should be easy to deal with the return type difference, struct ice_prase_list * ice_get_parser_list(struct ice_flow_parser *parser, struct ice_adapter *ad) { struct ice_parser_list *list = NULL; struct ice_pf *pf = &ad->pf; switch (parser->stage) { case ICE_FLOW_STAGE_RSS: list = &pf->rss_parser_list; break; case ICE_FLOW_STAGE_PERMISSION: list = &pf->perm_parser_list; break; case ICE_FLOW_STAGE_DISTRIBUTOR: list = &pf->dist_parser_list; break; default: break; } return list; } Then you just need to check its return value, if it's NULL, simply return -EINVAL on register and directly return on unregister. Thanks, Xiaolong