From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Perches Subject: Re: [Patch V4 net 01/11] net: hns3: add error handler for hns3_nic_init_vector_data() Date: Mon, 29 Oct 2018 18:31:03 -0700 Message-ID: <8bf932088a84f35111d2ae99dcd77051f3e854cc.camel@perches.com> References: <1540821261-55002-1-git-send-email-tanhuazhong@huawei.com> <1540821261-55002-2-git-send-email-tanhuazhong@huawei.com> <1ce6639d-fa73-52f0-1b02-a9b8e64e3608@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org, linuxarm@huawei.com, salil.mehta@huawei.com, yisen.zhuang@huawei.com, lipeng321@huawei.com, linyunsheng@huawei.com To: tanhuazhong , davem@davemloft.net, sergei.shtylyov@cogentembedded.com Return-path: Received: from smtprelay0179.hostedemail.com ([216.40.44.179]:52140 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725902AbeJ3KW1 (ORCPT ); Tue, 30 Oct 2018 06:22:27 -0400 In-Reply-To: <1ce6639d-fa73-52f0-1b02-a9b8e64e3608@huawei.com> Sender: netdev-owner@vger.kernel.org List-ID: On Tue, 2018-10-30 at 09:21 +0800, tanhuazhong wrote: > > On 2018/10/30 1:44, Joe Perches wrote: > > On Mon, 2018-10-29 at 21:54 +0800, Huazhong Tan wrote: > > > When hns3_nic_init_vector_data() fails to map ring to vector, > > > it should cancel the netif_napi_add() that has been successfully > > > done and then exits. > > [] > > > diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c > > [] > > > @@ -2821,7 +2821,7 @@ static int hns3_nic_init_vector_data(struct hns3_nic_priv *priv) > > > struct hnae3_handle *h = priv->ae_handle; > > > struct hns3_enet_tqp_vector *tqp_vector; > > > int ret = 0; > > > - u16 i; > > > + int i, j; > > > > > > hns3_nic_set_cpumask(priv); > > > > > > @@ -2868,13 +2868,19 @@ static int hns3_nic_init_vector_data(struct hns3_nic_priv *priv) > > > hns3_free_vector_ring_chain(tqp_vector, &vector_ring_chain); > > > > > > if (ret) > > > - return ret; > > > + goto map_ring_fail; > > > > > > netif_napi_add(priv->netdev, &tqp_vector->napi, > > > hns3_nic_common_poll, NAPI_POLL_WEIGHT); > > > } > > > > > > return 0; > > > + > > > +map_ring_fail: > > > + for (j = i - 1; j >= 0; j--) > > > + netif_napi_del(&priv->tqp_vector[j].napi); > > > > style trivia: > > > > Error clearing is most commonly done without another variable > > by decrementing i in the loop. > > > > Hi, Joe. > Is the below one more suitable? Yes. > + > +map_ring_fail: > + while(i--) > + netif_napi_del(&priv->tqp_vector[i].napi); > + > + return ret; > > Or do you have any other better suggestion? No I do not. "while (i--)" is a much more common style. cheers, Joe