All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] acerhdf: fix resource reclaim in error path
@ 2010-07-07  8:39 Axel Lin
  2010-07-07 12:29 ` Borislav Petkov
  0 siblings, 1 reply; 3+ messages in thread
From: Axel Lin @ 2010-07-07  8:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Feuerer, Matthew Garrett, Andrew Morton, Borislav Petkov,
	Alexey Dobriyan, platform-driver-x86

This patch fix resource reclaim in below cases:
1. acerhdf_register_platform() does not properly handle
   platform_device_alloc() failure and platform_device_add() failure
   This patch adds error handing for acerhdf_register_platform().
2. acerhdf_register_platform() return err with acerhdf_dev == NULL.
   as a result, acerhdf_unregister_platform() does not do resource
   reclaim in acerhdf_init() error path.
   This patch adds error handing for acerhdf_register_platform(),
   thus correct the error handing path in acerhdf_init().
   goto out_err instead of err_unreg if acerhdf_register_platform() fail.
3. platform_device_del() should only used in error handling.
   Current implementation missed a platform_device_put() in acerhdf_exit.
   This patch fixes it by using platform_device_unregister() instead of
   platform_device_del() in acerhdf_unregister_platform.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/platform/x86/acerhdf.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c
index 7b2384d..d9f5ebb 100644
--- a/drivers/platform/x86/acerhdf.c
+++ b/drivers/platform/x86/acerhdf.c
@@ -579,17 +579,26 @@ static int acerhdf_register_platform(void)
 		return err;
 
 	acerhdf_dev = platform_device_alloc("acerhdf", -1);
-	platform_device_add(acerhdf_dev);
+	if (!acerhdf_dev) {
+		err = -ENOMEM;
+		goto err_device_alloc;
+	}
+	err = platform_device_add(acerhdf_dev);
+	if (err)
+		goto err_device_add;
 
 	return 0;
+
+err_device_add:
+	platform_device_put(acerhdf_dev);
+err_device_alloc:
+	platform_driver_unregister(&acerhdf_driver);
+	return err;
 }
 
 static void acerhdf_unregister_platform(void)
 {
-	if (!acerhdf_dev)
-		return;
-
-	platform_device_del(acerhdf_dev);
+	platform_device_unregister(acerhdf_dev);
 	platform_driver_unregister(&acerhdf_driver);
 }
 
@@ -633,7 +642,7 @@ static int __init acerhdf_init(void)
 
 	err = acerhdf_register_platform();
 	if (err)
-		goto err_unreg;
+		goto out_err;
 
 	err = acerhdf_register_thermal();
 	if (err)
@@ -646,7 +655,7 @@ err_unreg:
 	acerhdf_unregister_platform();
 
 out_err:
-	return -ENODEV;
+	return err;
 }
 
 static void __exit acerhdf_exit(void)
-- 
1.5.4.3




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

* Re: [PATCH v2] acerhdf: fix resource reclaim in error path
  2010-07-07  8:39 [PATCH v2] acerhdf: fix resource reclaim in error path Axel Lin
@ 2010-07-07 12:29 ` Borislav Petkov
  2010-07-10 17:41   ` Peter Feuerer
  0 siblings, 1 reply; 3+ messages in thread
From: Borislav Petkov @ 2010-07-07 12:29 UTC (permalink / raw)
  To: Axel Lin
  Cc: linux-kernel, Peter Feuerer, Matthew Garrett, Andrew Morton,
	Borislav Petkov, Alexey Dobriyan, platform-driver-x86

From: Axel Lin <axel.lin@gmail.com>
Date: Wed, Jul 07, 2010 at 04:39:31PM +0800

> This patch fix resource reclaim in below cases:
> 1. acerhdf_register_platform() does not properly handle
>    platform_device_alloc() failure and platform_device_add() failure
>    This patch adds error handing for acerhdf_register_platform().
> 2. acerhdf_register_platform() return err with acerhdf_dev == NULL.
>    as a result, acerhdf_unregister_platform() does not do resource
>    reclaim in acerhdf_init() error path.
>    This patch adds error handing for acerhdf_register_platform(),
>    thus correct the error handing path in acerhdf_init().
>    goto out_err instead of err_unreg if acerhdf_register_platform() fail.
> 3. platform_device_del() should only used in error handling.
>    Current implementation missed a platform_device_put() in acerhdf_exit.
>    This patch fixes it by using platform_device_unregister() instead of
>    platform_device_del() in acerhdf_unregister_platform.
> 
> Signed-off-by: Axel Lin <axel.lin@gmail.com>

Ok, I just gave it a run and it looks good. Just a minor nitpick: when
writing your commit messages you don't have to explain what the code
does since we can see it in the patch itself. Rather, your commit
message should explain why you do this.

See http://userweb.kernel.org/~akpm/stuff/tpp.txt for further info on
how to create your patches.

Other than that:

Acked-by: Borislav Petkov <bp@alien8.de>

> ---
>  drivers/platform/x86/acerhdf.c |   23 ++++++++++++++++-------
>  1 files changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c
> index 7b2384d..d9f5ebb 100644
> --- a/drivers/platform/x86/acerhdf.c
> +++ b/drivers/platform/x86/acerhdf.c
> @@ -579,17 +579,26 @@ static int acerhdf_register_platform(void)
>  		return err;
>  
>  	acerhdf_dev = platform_device_alloc("acerhdf", -1);
> -	platform_device_add(acerhdf_dev);
> +	if (!acerhdf_dev) {
> +		err = -ENOMEM;
> +		goto err_device_alloc;
> +	}
> +	err = platform_device_add(acerhdf_dev);
> +	if (err)
> +		goto err_device_add;
>  
>  	return 0;
> +
> +err_device_add:
> +	platform_device_put(acerhdf_dev);
> +err_device_alloc:
> +	platform_driver_unregister(&acerhdf_driver);
> +	return err;
>  }
>  
>  static void acerhdf_unregister_platform(void)
>  {
> -	if (!acerhdf_dev)
> -		return;
> -
> -	platform_device_del(acerhdf_dev);
> +	platform_device_unregister(acerhdf_dev);
>  	platform_driver_unregister(&acerhdf_driver);
>  }
>  
> @@ -633,7 +642,7 @@ static int __init acerhdf_init(void)
>  
>  	err = acerhdf_register_platform();
>  	if (err)
> -		goto err_unreg;
> +		goto out_err;
>  
>  	err = acerhdf_register_thermal();
>  	if (err)
> @@ -646,7 +655,7 @@ err_unreg:
>  	acerhdf_unregister_platform();
>  
>  out_err:
> -	return -ENODEV;
> +	return err;
>  }
>  
>  static void __exit acerhdf_exit(void)
> -- 
> 1.5.4.3
> 
> 
> 

-- 
Regards/Gruss,
Boris.

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

* Re: [PATCH v2] acerhdf: fix resource reclaim in error path
  2010-07-07 12:29 ` Borislav Petkov
@ 2010-07-10 17:41   ` Peter Feuerer
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Feuerer @ 2010-07-10 17:41 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Axel Lin, linux-kernel, Matthew Garrett, Andrew Morton,
	Borislav Petkov, Alexey Dobriyan, platform-driver-x86

Borislav Petkov writes:

> From: Axel Lin <axel.lin@gmail.com>
> Date: Wed, Jul 07, 2010 at 04:39:31PM +0800
> 
>> This patch fix resource reclaim in below cases:
>> 1. acerhdf_register_platform() does not properly handle
>>    platform_device_alloc() failure and platform_device_add() failure
>>    This patch adds error handing for acerhdf_register_platform().
>> 2. acerhdf_register_platform() return err with acerhdf_dev == NULL.
>>    as a result, acerhdf_unregister_platform() does not do resource
>>    reclaim in acerhdf_init() error path.
>>    This patch adds error handing for acerhdf_register_platform(),
>>    thus correct the error handing path in acerhdf_init().
>>    goto out_err instead of err_unreg if acerhdf_register_platform() fail.
>> 3. platform_device_del() should only used in error handling.
>>    Current implementation missed a platform_device_put() in acerhdf_exit.
>>    This patch fixes it by using platform_device_unregister() instead of
>>    platform_device_del() in acerhdf_unregister_platform.
>> 
>> Signed-off-by: Axel Lin <axel.lin@gmail.com>
> 
> Ok, I just gave it a run and it looks good. Just a minor nitpick: when
> writing your commit messages you don't have to explain what the code
> does since we can see it in the patch itself. Rather, your commit
> message should explain why you do this.
> 
> See http://userweb.kernel.org/~akpm/stuff/tpp.txt for further info on
> how to create your patches.
> 
> Other than that:
> 
> Acked-by: Borislav Petkov <bp@alien8.de>

Acked-by: Peter Feuerer <peter@piie.net>

> 
>> ---
>>  drivers/platform/x86/acerhdf.c |   23 ++++++++++++++++-------
>>  1 files changed, 16 insertions(+), 7 deletions(-)
>> 
>> diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c
>> index 7b2384d..d9f5ebb 100644
>> --- a/drivers/platform/x86/acerhdf.c
>> +++ b/drivers/platform/x86/acerhdf.c
>> @@ -579,17 +579,26 @@ static int acerhdf_register_platform(void)
>>  		return err;
>>  
>>  	acerhdf_dev = platform_device_alloc("acerhdf", -1);
>> -	platform_device_add(acerhdf_dev);
>> +	if (!acerhdf_dev) {
>> +		err = -ENOMEM;
>> +		goto err_device_alloc;
>> +	}
>> +	err = platform_device_add(acerhdf_dev);
>> +	if (err)
>> +		goto err_device_add;
>>  
>>  	return 0;
>> +
>> +err_device_add:
>> +	platform_device_put(acerhdf_dev);
>> +err_device_alloc:
>> +	platform_driver_unregister(&acerhdf_driver);
>> +	return err;
>>  }
>>  
>>  static void acerhdf_unregister_platform(void)
>>  {
>> -	if (!acerhdf_dev)
>> -		return;
>> -
>> -	platform_device_del(acerhdf_dev);
>> +	platform_device_unregister(acerhdf_dev);
>>  	platform_driver_unregister(&acerhdf_driver);
>>  }
>>  
>> @@ -633,7 +642,7 @@ static int __init acerhdf_init(void)
>>  
>>  	err = acerhdf_register_platform();
>>  	if (err)
>> -		goto err_unreg;
>> +		goto out_err;
>>  
>>  	err = acerhdf_register_thermal();
>>  	if (err)
>> @@ -646,7 +655,7 @@ err_unreg:
>>  	acerhdf_unregister_platform();
>>  
>>  out_err:
>> -	return -ENODEV;
>> +	return err;
>>  }
>>  
>>  static void __exit acerhdf_exit(void)
>> -- 
>> 1.5.4.3

thank you,
--peter;

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

end of thread, other threads:[~2010-07-10 17:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-07  8:39 [PATCH v2] acerhdf: fix resource reclaim in error path Axel Lin
2010-07-07 12:29 ` Borislav Petkov
2010-07-10 17:41   ` Peter Feuerer

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.