diff mbox

[v6,03/22] mfd: omap-usb-tll: Use devm_kzalloc/ioremap and clean up error path

Message ID 1358347433-329-4-git-send-email-rogerq@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roger Quadros Jan. 16, 2013, 2:43 p.m. UTC
Use devm_ variants of kzalloc() and ioremap(). Simplify the error path.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 drivers/mfd/omap-usb-tll.c |   36 +++++++++++-------------------------
 1 files changed, 11 insertions(+), 25 deletions(-)

Comments

Sergei Shtylyov Jan. 16, 2013, 7:37 p.m. UTC | #1
Hello.

On 01/16/2013 05:43 PM, Roger Quadros wrote:

> Use devm_ variants of kzalloc() and ioremap(). Simplify the error path.

> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
>  drivers/mfd/omap-usb-tll.c |   36 +++++++++++-------------------------
>  1 files changed, 11 insertions(+), 25 deletions(-)

> diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
> index 9658e18..53ed10b 100644
> --- a/drivers/mfd/omap-usb-tll.c
> +++ b/drivers/mfd/omap-usb-tll.c
[...]
> -	base = ioremap(res->start, resource_size(res));
> +	base = devm_request_and_ioremap(dev, res);
>  	if (!base) {
> -		dev_err(dev, "TLL ioremap failed\n");
>  		ret = -ENOMEM;

   -EADDRNOTAVAIL as the comment to devm_request_and_ioremap() suggests.

> -		goto err_usbtll_p2_fck;
> +		dev_err(dev, "Resource request/ioremap failed:%d\n", ret);
> +		goto err_res;
>  	}

WBR, Sergei
Roger Quadros Jan. 17, 2013, 9:12 a.m. UTC | #2
On 01/16/2013 09:37 PM, Sergei Shtylyov wrote:
> Hello.
> 
> On 01/16/2013 05:43 PM, Roger Quadros wrote:
> 
>> Use devm_ variants of kzalloc() and ioremap(). Simplify the error path.
> 
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>>  drivers/mfd/omap-usb-tll.c |   36 +++++++++++-------------------------
>>  1 files changed, 11 insertions(+), 25 deletions(-)
> 
>> diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
>> index 9658e18..53ed10b 100644
>> --- a/drivers/mfd/omap-usb-tll.c
>> +++ b/drivers/mfd/omap-usb-tll.c
> [...]
>> -	base = ioremap(res->start, resource_size(res));
>> +	base = devm_request_and_ioremap(dev, res);
>>  	if (!base) {
>> -		dev_err(dev, "TLL ioremap failed\n");
>>  		ret = -ENOMEM;
> 
>    -EADDRNOTAVAIL as the comment to devm_request_and_ioremap() suggests.
> 

I changed it deliberately to ENOMEM, as I could not find EADDRNOTAVAIL
defined in all architectures.

ENOMEM shouldn't harm.

cheers,
-roger
Roger Quadros Jan. 17, 2013, 10:32 a.m. UTC | #3
On 01/17/2013 11:12 AM, Roger Quadros wrote:
> On 01/16/2013 09:37 PM, Sergei Shtylyov wrote:
>> Hello.
>>
>> On 01/16/2013 05:43 PM, Roger Quadros wrote:
>>
>>> Use devm_ variants of kzalloc() and ioremap(). Simplify the error path.
>>
>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>> ---
>>>  drivers/mfd/omap-usb-tll.c |   36 +++++++++++-------------------------
>>>  1 files changed, 11 insertions(+), 25 deletions(-)
>>
>>> diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
>>> index 9658e18..53ed10b 100644
>>> --- a/drivers/mfd/omap-usb-tll.c
>>> +++ b/drivers/mfd/omap-usb-tll.c
>> [...]
>>> -	base = ioremap(res->start, resource_size(res));
>>> +	base = devm_request_and_ioremap(dev, res);
>>>  	if (!base) {
>>> -		dev_err(dev, "TLL ioremap failed\n");
>>>  		ret = -ENOMEM;
>>
>>    -EADDRNOTAVAIL as the comment to devm_request_and_ioremap() suggests.
>>
> 
> I changed it deliberately to ENOMEM, as I could not find EADDRNOTAVAIL
> defined in all architectures.
> 
> ENOMEM shouldn't harm.
> 

Correcting myself,

It is defined here

include/uapi/asm-generic/errno.h:#define        EADDRNOTAVAIL   99
/* Cannot assign requested address */

So i'll update both patches.

--
cheers,
-roger
diff mbox

Patch

diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
index 9658e18..53ed10b 100644
--- a/drivers/mfd/omap-usb-tll.c
+++ b/drivers/mfd/omap-usb-tll.c
@@ -215,11 +215,10 @@  static int usbtll_omap_probe(struct platform_device *pdev)
 
 	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
-	tll = kzalloc(sizeof(struct usbtll_omap), GFP_KERNEL);
+	tll = devm_kzalloc(dev, sizeof(struct usbtll_omap), GFP_KERNEL);
 	if (!tll) {
 		dev_err(dev, "Memory allocation failed\n");
-		ret = -ENOMEM;
-		goto end;
+		return -ENOMEM;
 	}
 
 	spin_lock_init(&tll->lock);
@@ -230,28 +229,22 @@  static int usbtll_omap_probe(struct platform_device *pdev)
 	if (IS_ERR(tll->usbtll_p1_fck)) {
 		ret = PTR_ERR(tll->usbtll_p1_fck);
 		dev_err(dev, "usbtll_p1_fck failed error:%d\n", ret);
-		goto err_tll;
+		return ret;
 	}
 
 	tll->usbtll_p2_fck = clk_get(dev, "usb_tll_hs_usb_ch1_clk");
 	if (IS_ERR(tll->usbtll_p2_fck)) {
 		ret = PTR_ERR(tll->usbtll_p2_fck);
 		dev_err(dev, "usbtll_p2_fck failed error:%d\n", ret);
-		goto err_usbtll_p1_fck;
+		goto err_p2_fck;
 	}
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(dev, "usb tll get resource failed\n");
-		ret = -ENODEV;
-		goto err_usbtll_p2_fck;
-	}
-
-	base = ioremap(res->start, resource_size(res));
+	base = devm_request_and_ioremap(dev, res);
 	if (!base) {
-		dev_err(dev, "TLL ioremap failed\n");
 		ret = -ENOMEM;
-		goto err_usbtll_p2_fck;
+		dev_err(dev, "Resource request/ioremap failed:%d\n", ret);
+		goto err_res;
 	}
 
 	platform_set_drvdata(pdev, tll);
@@ -323,23 +316,17 @@  static int usbtll_omap_probe(struct platform_device *pdev)
 	}
 
 	spin_unlock_irqrestore(&tll->lock, flags);
-	iounmap(base);
 	pm_runtime_put_sync(dev);
 	tll_pdev = pdev;
-	if (!ret)
-		goto end;
-	pm_runtime_disable(dev);
 
-err_usbtll_p2_fck:
+	return 0;
+
+err_res:
 	clk_put(tll->usbtll_p2_fck);
 
-err_usbtll_p1_fck:
+err_p2_fck:
 	clk_put(tll->usbtll_p1_fck);
 
-err_tll:
-	kfree(tll);
-
-end:
 	return ret;
 }
 
@@ -356,7 +343,6 @@  static int usbtll_omap_remove(struct platform_device *pdev)
 	clk_put(tll->usbtll_p2_fck);
 	clk_put(tll->usbtll_p1_fck);
 	pm_runtime_disable(&pdev->dev);
-	kfree(tll);
 	return 0;
 }