Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752078AbdLEV2r (ORCPT ); Tue, 5 Dec 2017 16:28:47 -0500 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:48251 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751453AbdLEV2p (ORCPT ); Tue, 5 Dec 2017 16:28:45 -0500 X-IronPort-AV: E=Sophos;i="5.45,365,1508828400"; d="scan'208";a="9897977" Subject: Re: [PATCH 2/2] net: macb: kill useless use of list_empty() To: Julia Cartwright , Julia Lawall CC: Rafal Ozieblo , , , References: <20171205201711.GA18445@jcartwri.amer.corp.natinst.com> <20171205201830.GB18445@jcartwri.amer.corp.natinst.com> From: Nicolas Ferre Organization: microchip Message-ID: <40553101-3ebf-0559-363e-f982d8494968@microchip.com> Date: Tue, 5 Dec 2017 22:28:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171205201830.GB18445@jcartwri.amer.corp.natinst.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2629 Lines: 80 On 05/12/2017 at 21:18, Julia Cartwright wrote: > The list_for_each_entry() macro already handles the case where the list > is empty (by not executing the loop body). It's not necessary to handle > this case specially, so stop doing so. > > Cc: Rafal Ozieblo > Signed-off-by: Julia Cartwright > --- > This is an additional cleanup patch found when looking at this code. > > Julia Acked-by: Nicolas Ferre Thanks > > drivers/net/ethernet/cadence/macb_main.c | 34 ++++++++++++-------------------- > 1 file changed, 13 insertions(+), 21 deletions(-) > > diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c > index e7ef104a077d..3643c6ad2322 100644 > --- a/drivers/net/ethernet/cadence/macb_main.c > +++ b/drivers/net/ethernet/cadence/macb_main.c > @@ -2815,25 +2815,22 @@ static int gem_add_flow_filter(struct net_device *netdev, > spin_lock_irqsave(&bp->rx_fs_lock, flags); > > /* find correct place to add in list */ > - if (list_empty(&bp->rx_fs_list.list)) > - list_add(&newfs->list, &bp->rx_fs_list.list); > - else { > - list_for_each_entry(item, &bp->rx_fs_list.list, list) { > - if (item->fs.location > newfs->fs.location) { > - list_add_tail(&newfs->list, &item->list); > - added = true; > - break; > - } else if (item->fs.location == fs->location) { > - netdev_err(netdev, "Rule not added: location %d not free!\n", > - fs->location); > - ret = -EBUSY; > - goto err; > - } > + list_for_each_entry(item, &bp->rx_fs_list.list, list) { > + if (item->fs.location > newfs->fs.location) { > + list_add_tail(&newfs->list, &item->list); > + added = true; > + break; > + } else if (item->fs.location == fs->location) { > + netdev_err(netdev, "Rule not added: location %d not free!\n", > + fs->location); > + ret = -EBUSY; > + goto err; > } > - if (!added) > - list_add_tail(&newfs->list, &bp->rx_fs_list.list); > } > > + if (!added) > + list_add_tail(&newfs->list, &bp->rx_fs_list.list); > + > gem_prog_cmp_regs(bp, fs); > bp->rx_fs_list.count++; > /* enable filtering if NTUPLE on */ > @@ -2859,11 +2856,6 @@ static int gem_del_flow_filter(struct net_device *netdev, > > spin_lock_irqsave(&bp->rx_fs_lock, flags); > > - if (list_empty(&bp->rx_fs_list.list)) { > - spin_unlock_irqrestore(&bp->rx_fs_lock, flags); > - return -EINVAL; > - } > - > list_for_each_entry(item, &bp->rx_fs_list.list, list) { > if (item->fs.location == cmd->fs.location) { > /* disable screener regs for the flow entry */ > -- Nicolas Ferre