linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Ferre <nicolas.ferre@microchip.com>
To: Julia Cartwright <julia@ni.com>, Julia Lawall <julia.lawall@lip6.fr>
Cc: Rafal Ozieblo <rafalo@cadence.com>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <kbuild-all@01.org>
Subject: Re: [PATCH 2/2] net: macb: kill useless use of list_empty()
Date: Tue, 5 Dec 2017 22:28:40 +0100	[thread overview]
Message-ID: <40553101-3ebf-0559-363e-f982d8494968@microchip.com> (raw)
In-Reply-To: <20171205201830.GB18445@jcartwri.amer.corp.natinst.com>

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 <rafalo@cadence.com>
> Signed-off-by: Julia Cartwright <julia@ni.com>
> ---
> This is an additional cleanup patch found when looking at this code.
> 
>    Julia

Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>

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

  reply	other threads:[~2017-12-05 21:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-02  7:01 [PATCH v2] net: macb: change GFP_KERNEL to GFP_ATOMIC Julia Lawall
2017-12-05 16:27 ` David Miller
2017-12-05 20:17 ` [PATCH 1/2] net: macb: reduce scope of rx_fs_lock-protected regions Julia Cartwright
2017-12-05 20:18   ` [PATCH 2/2] net: macb: kill useless use of list_empty() Julia Cartwright
2017-12-05 21:28     ` Nicolas Ferre [this message]
2017-12-05 21:26   ` [PATCH 1/2] net: macb: reduce scope of rx_fs_lock-protected regions Nicolas Ferre
2017-12-05 23:00   ` David Miller
2017-12-06  0:02     ` [PATCH v2 0/3] macb rx filter cleanups Julia Cartwright
2017-12-06  0:02       ` [PATCH v2 1/3] net: macb: kill useless use of list_empty() Julia Cartwright
2017-12-06  0:02       ` [PATCH v2 2/3] net: macb: reduce scope of rx_fs_lock-protected regions Julia Cartwright
2017-12-06  0:02       ` [PATCH v2 3/3] net: macb: change GFP_ATOMIC to GFP_KERNEL Julia Cartwright
2017-12-06  5:49         ` Julia Lawall
2017-12-06  1:08       ` [PATCH v2 0/3] macb rx filter cleanups David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40553101-3ebf-0559-363e-f982d8494968@microchip.com \
    --to=nicolas.ferre@microchip.com \
    --cc=julia.lawall@lip6.fr \
    --cc=julia@ni.com \
    --cc=kbuild-all@01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rafalo@cadence.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).