linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Yuval Shaia <yuval.shaia@oracle.com>
Cc: davem@davemloft.net, tariqt@mellanox.com, netdev@vger.kernel.org,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] net/mlx4_en: Fix an error handling path in 'mlx4_en_init_netdev()'
Date: Thu, 10 May 2018 16:35:43 +0200	[thread overview]
Message-ID: <b099afcb-c83b-8a11-4025-2008d56b5ef6@wanadoo.fr> (raw)
In-Reply-To: <20180510133808.GA10943@lap1>

Le 10/05/2018 à 15:38, Yuval Shaia a écrit :
> On Thu, May 10, 2018 at 09:02:26AM +0200, Christophe JAILLET wrote:
>> If an error occurs, 'mlx4_en_destroy_netdev()' is called.
>> It then calls 'mlx4_en_free_resources()' which does the needed resources
>> cleanup.
>>
>> So, doing some explicit kfree in the error handling path would lead to
>> some double kfree.
> Patch make sense but what's bothering me is that mlx4_en_free_resources
> loops on the entire array, assuming !priv->tx_ring[t] means entry is
> allocated but the existing code does not assume that, see [1]. So i looked
> to see where tx_ring array is zeroed and didn't find it.
>
> Am i missing something here.
My understanding is that the array is zeoed at line 3289, when the whole 
priv struct is memset(0)'ed (also done in alloc_etherdev_mqs but leaving 
an explicit memset help to remind that the struct is zeroed)
If speed matters here (and I don't think so), the memset could be saved 
(the mlx4_en_priv struct is quite big after all), but at least a comment 
should remind that it is initialized within alloc_etherdev_mqs.

CJ


>> Simplify code to avoid such a case.
>>
>> Fixes: 67f8b1dcb9ee ("net/mlx4_en: Refactor the XDP forwarding rings scheme")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>>   drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 8 +-------
>>   1 file changed, 1 insertion(+), 7 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
>> index e0adac4a9a19..9670b33fc9b1 100644
>> --- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
>> +++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
>> @@ -3324,12 +3324,11 @@ int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
>>   					   MAX_TX_RINGS, GFP_KERNEL);
>>   		if (!priv->tx_ring[t]) {
>>   			err = -ENOMEM;
>> -			goto err_free_tx;
>> +			goto out;
>>   		}
>>   		priv->tx_cq[t] = kzalloc(sizeof(struct mlx4_en_cq *) *
>>   					 MAX_TX_RINGS, GFP_KERNEL);
>>   		if (!priv->tx_cq[t]) {
>> -			kfree(priv->tx_ring[t]);
>>   			err = -ENOMEM;
>>   			goto out;
>>   		}
>> @@ -3582,11 +3581,6 @@ int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
>>   
>>   	return 0;
>>   
>> -err_free_tx:
>> -	while (t--) {
> [1]
>
>> -		kfree(priv->tx_ring[t]);
>> -		kfree(priv->tx_cq[t]);
>> -	}
>>   out:
>>   	mlx4_en_destroy_netdev(dev);
>>   	return err;
>> -- 
>> 2.17.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2018-05-10 14:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-10  7:02 [PATCH] net/mlx4_en: Fix an error handling path in 'mlx4_en_init_netdev()' Christophe JAILLET
2018-05-10 13:38 ` Yuval Shaia
2018-05-10 14:18   ` Dan Carpenter
2018-05-10 14:36     ` Tariq Toukan
2018-05-10 15:03       ` Tariq Toukan
2018-05-10 14:35   ` Christophe JAILLET [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-05-08  9:34 Christophe JAILLET
2018-05-09 10:31 ` Tariq Toukan

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=b099afcb-c83b-8a11-4025-2008d56b5ef6@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=davem@davemloft.net \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tariqt@mellanox.com \
    --cc=yuval.shaia@oracle.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).