All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: mv643xx_eth: use managed devm_kzalloc
@ 2013-04-10 17:38 Sebastian Hesselbarth
  2013-04-10 18:41 ` Sergei Shtylyov
  2013-04-10 20:42 ` [PATCH v2] " Sebastian Hesselbarth
  0 siblings, 2 replies; 8+ messages in thread
From: Sebastian Hesselbarth @ 2013-04-10 17:38 UTC (permalink / raw)
  To: Sebastian Hesselbarth
  Cc: Lennert Buytenhek, Andrew Lunn, Jason Cooper, Florian Fainelli,
	netdev, linux-kernel

This patch moves shared private data kzalloc to managed devm_kzalloc and
cleans now unneccessary kfree and error handling.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Note that there is also an ioremap call, that could be transferred to
devm_ioremap_resource. But as long as mv643xx_eth and mvmdio iomem
resources overlap, this will throw -EBUSY.

Cc: Lennert Buytenhek <buytenh@wantstofly.org>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Jason Cooper <jason@lakedaemon.net>
Cc: Florian Fainelli <florian@openwrt.org>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/marvell/mv643xx_eth.c |   17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index bbe6104..955baab 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -2547,25 +2547,22 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev)
 	struct mv643xx_eth_shared_private *msp;
 	const struct mbus_dram_target_info *dram;
 	struct resource *res;
-	int ret;
 
 	if (!mv643xx_eth_version_printed++)
 		pr_notice("MV-643xx 10/100/1000 ethernet driver version %s\n",
 			  mv643xx_eth_driver_version);
 
-	ret = -EINVAL;
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (res == NULL)
-		goto out;
+		return -EINVAL;
 
-	ret = -ENOMEM;
-	msp = kzalloc(sizeof(*msp), GFP_KERNEL);
+	msp = devm_kzalloc(&pdev->dev, sizeof(*msp), GFP_KERNEL);
 	if (msp == NULL)
-		goto out;
+		return -ENOMEM;
 
 	msp->base = ioremap(res->start, resource_size(res));
 	if (msp->base == NULL)
-		goto out_free;
+		return -EADDRNOTAVAIL;
 
 	msp->clk = devm_clk_get(&pdev->dev, NULL);
 	if (!IS_ERR(msp->clk))
@@ -2585,11 +2582,6 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, msp);
 
 	return 0;
-
-out_free:
-	kfree(msp);
-out:
-	return ret;
 }
 
 static int mv643xx_eth_shared_remove(struct platform_device *pdev)
@@ -2599,7 +2591,6 @@ static int mv643xx_eth_shared_remove(struct platform_device *pdev)
 	iounmap(msp->base);
 	if (!IS_ERR(msp->clk))
 		clk_disable_unprepare(msp->clk);
-	kfree(msp);
 
 	return 0;
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] net: mv643xx_eth: use managed devm_kzalloc
  2013-04-10 17:38 [PATCH] net: mv643xx_eth: use managed devm_kzalloc Sebastian Hesselbarth
@ 2013-04-10 18:41 ` Sergei Shtylyov
  2013-04-10 20:17   ` Sebastian Hesselbarth
  2013-04-10 20:42 ` [PATCH v2] " Sebastian Hesselbarth
  1 sibling, 1 reply; 8+ messages in thread
From: Sergei Shtylyov @ 2013-04-10 18:41 UTC (permalink / raw)
  To: Sebastian Hesselbarth
  Cc: Lennert Buytenhek, Andrew Lunn, Jason Cooper, Florian Fainelli,
	netdev, linux-kernel

Hello.

On 04/10/2013 09:38 PM, Sebastian Hesselbarth wrote:

> This patch moves shared private data kzalloc to managed devm_kzalloc and
> cleans now unneccessary kfree and error handling.
>
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> ---
> Note that there is also an ioremap call, that could be transferred to
> devm_ioremap_resource. But as long as mv643xx_eth and mvmdio iomem
> resources overlap, this will throw -EBUSY.
>
> Cc: Lennert Buytenhek <buytenh@wantstofly.org>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Jason Cooper <jason@lakedaemon.net>
> Cc: Florian Fainelli <florian@openwrt.org>
> Cc: netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>   drivers/net/ethernet/marvell/mv643xx_eth.c |   17 ++++-------------
>   1 file changed, 4 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
> index bbe6104..955baab 100644
> --- a/drivers/net/ethernet/marvell/mv643xx_eth.c
> +++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
> @@ -2547,25 +2547,22 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev)
>   	struct mv643xx_eth_shared_private *msp;
>   	const struct mbus_dram_target_info *dram;
>   	struct resource *res;
> -	int ret;
>   
>   	if (!mv643xx_eth_version_printed++)
>   		pr_notice("MV-643xx 10/100/1000 ethernet driver version %s\n",
>   			  mv643xx_eth_driver_version);
>   
> -	ret = -EINVAL;
>   	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>   	if (res == NULL)
> -		goto out;
> +		return -EINVAL;
>   
> -	ret = -ENOMEM;
> -	msp = kzalloc(sizeof(*msp), GFP_KERNEL);
> +	msp = devm_kzalloc(&pdev->dev, sizeof(*msp), GFP_KERNEL);
>   	if (msp == NULL)
> -		goto out;
> +		return -ENOMEM;
>   
>   	msp->base = ioremap(res->start, resource_size(res));
>   	if (msp->base == NULL)
> -		goto out_free;
> +		return -EADDRNOTAVAIL;

    -ENOMEM usually.

WBR, Sergei


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] net: mv643xx_eth: use managed devm_kzalloc
  2013-04-10 18:41 ` Sergei Shtylyov
@ 2013-04-10 20:17   ` Sebastian Hesselbarth
  2013-04-10 20:26     ` Sergei Shtylyov
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Hesselbarth @ 2013-04-10 20:17 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: Lennert Buytenhek, Andrew Lunn, Jason Cooper, Florian Fainelli,
	netdev, linux-kernel

On 04/10/2013 08:41 PM, Sergei Shtylyov wrote:
> Hello.
>
> On 04/10/2013 09:38 PM, Sebastian Hesselbarth wrote:
>
>> This patch moves shared private data kzalloc to managed devm_kzalloc and
>> cleans now unneccessary kfree and error handling.
>>
>> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
>> ---
>> Note that there is also an ioremap call, that could be transferred to
>> devm_ioremap_resource. But as long as mv643xx_eth and mvmdio iomem
>> resources overlap, this will throw -EBUSY.
>>
>> Cc: Lennert Buytenhek <buytenh@wantstofly.org>
>> Cc: Andrew Lunn <andrew@lunn.ch>
>> Cc: Jason Cooper <jason@lakedaemon.net>
>> Cc: Florian Fainelli <florian@openwrt.org>
>> Cc: netdev@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> ---
>> drivers/net/ethernet/marvell/mv643xx_eth.c | 17 ++++-------------
>> 1 file changed, 4 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c
>> b/drivers/net/ethernet/marvell/mv643xx_eth.c
>> index bbe6104..955baab 100644
>> --- a/drivers/net/ethernet/marvell/mv643xx_eth.c
>> +++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
>> @@ -2547,25 +2547,22 @@ static int mv643xx_eth_shared_probe(struct
>> platform_device *pdev)
>> struct mv643xx_eth_shared_private *msp;
>> const struct mbus_dram_target_info *dram;
>> struct resource *res;
>> - int ret;
>> if (!mv643xx_eth_version_printed++)
>> pr_notice("MV-643xx 10/100/1000 ethernet driver version %s\n",
>> mv643xx_eth_driver_version);
>> - ret = -EINVAL;
>> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> if (res == NULL)
>> - goto out;
>> + return -EINVAL;
>> - ret = -ENOMEM;
>> - msp = kzalloc(sizeof(*msp), GFP_KERNEL);
>> + msp = devm_kzalloc(&pdev->dev, sizeof(*msp), GFP_KERNEL);
>> if (msp == NULL)
>> - goto out;
>> + return -ENOMEM;
>> msp->base = ioremap(res->start, resource_size(res));
>> if (msp->base == NULL)
>> - goto out_free;
>> + return -EADDRNOTAVAIL;
>
> -ENOMEM usually.

Sergei,

I was looking at the example for devm_request_and_ioremap() in
lib/devres.c. There it is -EADDRNOTAVAIL which is returned on
failing ioremap.

Actually, I was hoping to also use devm_ioremap_resource() for
the above, but that is too early as mv643xx_eth and mvmdio have
overlapping mem resources. Changing this will require some more
step-by-step patches that get also tested on arch/ppc and others
using platform mv643xx_eth.

But, I can send an updated patch with -ENOMEM above if required.

Sebastian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] net: mv643xx_eth: use managed devm_kzalloc
  2013-04-10 20:17   ` Sebastian Hesselbarth
@ 2013-04-10 20:26     ` Sergei Shtylyov
  0 siblings, 0 replies; 8+ messages in thread
From: Sergei Shtylyov @ 2013-04-10 20:26 UTC (permalink / raw)
  To: Sebastian Hesselbarth
  Cc: Lennert Buytenhek, Andrew Lunn, Jason Cooper, Florian Fainelli,
	netdev, linux-kernel

On 04/11/2013 12:17 AM, Sebastian Hesselbarth wrote:
>
>>
>>> This patch moves shared private data kzalloc to managed devm_kzalloc 
>>> and
>>> cleans now unneccessary kfree and error handling.
>>>
>>> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
>>> ---
>>> Note that there is also an ioremap call, that could be transferred to
>>> devm_ioremap_resource. But as long as mv643xx_eth and mvmdio iomem
>>> resources overlap, this will throw -EBUSY.
>>>
>>> Cc: Lennert Buytenhek <buytenh@wantstofly.org>
>>> Cc: Andrew Lunn <andrew@lunn.ch>
>>> Cc: Jason Cooper <jason@lakedaemon.net>
>>> Cc: Florian Fainelli <florian@openwrt.org>
>>> Cc: netdev@vger.kernel.org
>>> Cc: linux-kernel@vger.kernel.org
>>> ---
>>> drivers/net/ethernet/marvell/mv643xx_eth.c | 17 ++++-------------
>>> 1 file changed, 4 insertions(+), 13 deletions(-)
>>>
>>> diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c
>>> b/drivers/net/ethernet/marvell/mv643xx_eth.c
>>> index bbe6104..955baab 100644
>>> --- a/drivers/net/ethernet/marvell/mv643xx_eth.c
>>> +++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
>>> @@ -2547,25 +2547,22 @@ static int mv643xx_eth_shared_probe(struct
>>> platform_device *pdev)
>>> struct mv643xx_eth_shared_private *msp;
>>> const struct mbus_dram_target_info *dram;
>>> struct resource *res;
>>> - int ret;
>>> if (!mv643xx_eth_version_printed++)
>>> pr_notice("MV-643xx 10/100/1000 ethernet driver version %s\n",
>>> mv643xx_eth_driver_version);
>>> - ret = -EINVAL;
>>> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>> if (res == NULL)
>>> - goto out;
>>> + return -EINVAL;
>>> - ret = -ENOMEM;
>>> - msp = kzalloc(sizeof(*msp), GFP_KERNEL);
>>> + msp = devm_kzalloc(&pdev->dev, sizeof(*msp), GFP_KERNEL);
>>> if (msp == NULL)
>>> - goto out;
>>> + return -ENOMEM;
>>> msp->base = ioremap(res->start, resource_size(res));
>>> if (msp->base == NULL)
>>> - goto out_free;
>>> + return -EADDRNOTAVAIL;
>>
>> -ENOMEM usually.
>
> Sergei,
>
> I was looking at the example for devm_request_and_ioremap() in
> lib/devres.c. There it is -EADDRNOTAVAIL which is returned on
> failing ioremap.

    This is a recommended value to return if this function fails, to be 
precise --
regardless of the reason.
    With mere ioremap(), the value has always been -ENOMEM.

WBR, Sergei


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] net: mv643xx_eth: use managed devm_kzalloc
  2013-04-10 17:38 [PATCH] net: mv643xx_eth: use managed devm_kzalloc Sebastian Hesselbarth
  2013-04-10 18:41 ` Sergei Shtylyov
@ 2013-04-10 20:42 ` Sebastian Hesselbarth
  2013-04-11  3:39   ` David Miller
  1 sibling, 1 reply; 8+ messages in thread
From: Sebastian Hesselbarth @ 2013-04-10 20:42 UTC (permalink / raw)
  To: Sebastian Hesselbarth
  Cc: Lennert Buytenhek, Andrew Lunn, Jason Cooper, Florian Fainelli,
	Sergei Shtylyov, netdev, linux-kernel

This patch moves shared private data kzalloc to managed devm_kzalloc and
cleans now unneccessary kfree and error handling.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Changes from v1:
- replaced EADDRNOTAVAIL with ENOMEM on failing ioremap (Reported by
  Sergei Shtylyov)

Cc: Lennert Buytenhek <buytenh@wantstofly.org>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Jason Cooper <jason@lakedaemon.net>
Cc: Florian Fainelli <florian@openwrt.org>
Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/marvell/mv643xx_eth.c |   17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index bbe6104..305038f 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -2547,25 +2547,22 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev)
 	struct mv643xx_eth_shared_private *msp;
 	const struct mbus_dram_target_info *dram;
 	struct resource *res;
-	int ret;
 
 	if (!mv643xx_eth_version_printed++)
 		pr_notice("MV-643xx 10/100/1000 ethernet driver version %s\n",
 			  mv643xx_eth_driver_version);
 
-	ret = -EINVAL;
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (res == NULL)
-		goto out;
+		return -EINVAL;
 
-	ret = -ENOMEM;
-	msp = kzalloc(sizeof(*msp), GFP_KERNEL);
+	msp = devm_kzalloc(&pdev->dev, sizeof(*msp), GFP_KERNEL);
 	if (msp == NULL)
-		goto out;
+		return -ENOMEM;
 
 	msp->base = ioremap(res->start, resource_size(res));
 	if (msp->base == NULL)
-		goto out_free;
+		return -ENOMEM;
 
 	msp->clk = devm_clk_get(&pdev->dev, NULL);
 	if (!IS_ERR(msp->clk))
@@ -2585,11 +2582,6 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, msp);
 
 	return 0;
-
-out_free:
-	kfree(msp);
-out:
-	return ret;
 }
 
 static int mv643xx_eth_shared_remove(struct platform_device *pdev)
@@ -2599,7 +2591,6 @@ static int mv643xx_eth_shared_remove(struct platform_device *pdev)
 	iounmap(msp->base);
 	if (!IS_ERR(msp->clk))
 		clk_disable_unprepare(msp->clk);
-	kfree(msp);
 
 	return 0;
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] net: mv643xx_eth: use managed devm_kzalloc
  2013-04-10 20:42 ` [PATCH v2] " Sebastian Hesselbarth
@ 2013-04-11  3:39   ` David Miller
  2013-04-11  6:53     ` Sebastian Hesselbarth
  0 siblings, 1 reply; 8+ messages in thread
From: David Miller @ 2013-04-11  3:39 UTC (permalink / raw)
  To: sebastian.hesselbarth
  Cc: buytenh, andrew, jason, florian, sergei.shtylyov, netdev, linux-kernel

From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Date: Wed, 10 Apr 2013 22:42:07 +0200

> This patch moves shared private data kzalloc to managed devm_kzalloc and
> cleans now unneccessary kfree and error handling.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>

This doesn't apply cleanly to the net-next tree.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] net: mv643xx_eth: use managed devm_kzalloc
  2013-04-11  3:39   ` David Miller
@ 2013-04-11  6:53     ` Sebastian Hesselbarth
  2013-04-11 17:15       ` David Miller
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Hesselbarth @ 2013-04-11  6:53 UTC (permalink / raw)
  To: David Miller
  Cc: buytenh, andrew, jason, florian, sergei.shtylyov, netdev, linux-kernel

On 04/11/2013 05:39 AM, David Miller wrote:
> From: Sebastian Hesselbarth<sebastian.hesselbarth@gmail.com>
> Date: Wed, 10 Apr 2013 22:42:07 +0200
>
>> This patch moves shared private data kzalloc to managed devm_kzalloc and
>> cleans now unneccessary kfree and error handling.
>>
>> Signed-off-by: Sebastian Hesselbarth<sebastian.hesselbarth@gmail.com>
>
> This doesn't apply cleanly to the net-next tree.

Yeah. I sent two single patches for mv643xx_eth, while they should
have been sent together in one patch set. I'll prepare a cover letter
and resend both in one patch set.

Sebastian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] net: mv643xx_eth: use managed devm_kzalloc
  2013-04-11  6:53     ` Sebastian Hesselbarth
@ 2013-04-11 17:15       ` David Miller
  0 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2013-04-11 17:15 UTC (permalink / raw)
  To: sebastian.hesselbarth
  Cc: buytenh, andrew, jason, florian, sergei.shtylyov, netdev, linux-kernel

From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Date: Thu, 11 Apr 2013 08:53:19 +0200

> On 04/11/2013 05:39 AM, David Miller wrote:
>> From: Sebastian Hesselbarth<sebastian.hesselbarth@gmail.com>
>> Date: Wed, 10 Apr 2013 22:42:07 +0200
>>
>>> This patch moves shared private data kzalloc to managed devm_kzalloc
>>> and
>>> cleans now unneccessary kfree and error handling.
>>>
>>> Signed-off-by: Sebastian Hesselbarth<sebastian.hesselbarth@gmail.com>
>>
>> This doesn't apply cleanly to the net-next tree.
> 
> Yeah. I sent two single patches for mv643xx_eth, while they should
> have been sent together in one patch set. I'll prepare a cover letter
> and resend both in one patch set.

If you don't number the patches or mention the dependency, there is no way
for people to know.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-04-11 17:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-10 17:38 [PATCH] net: mv643xx_eth: use managed devm_kzalloc Sebastian Hesselbarth
2013-04-10 18:41 ` Sergei Shtylyov
2013-04-10 20:17   ` Sebastian Hesselbarth
2013-04-10 20:26     ` Sergei Shtylyov
2013-04-10 20:42 ` [PATCH v2] " Sebastian Hesselbarth
2013-04-11  3:39   ` David Miller
2013-04-11  6:53     ` Sebastian Hesselbarth
2013-04-11 17:15       ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.