diff mbox

power: bq27x00_battery: Destroy battery_id IDR on module exit

Message ID 1436368700-30852-1-git-send-email-jthumshirn@suse.de (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Johannes Thumshirn July 8, 2015, 3:18 p.m. UTC
Destroy battery_id IDR on module exit, reclaiming the allocated memory.

This was detected by the following semantic patch (written by Luis Rodriguez
<mcgrof@suse.com>)
<SmPL>
@ defines_module_init @
declarer name module_init, module_exit;
declarer name DEFINE_IDR;
identifier init;
@@

module_init(init);

@ defines_module_exit @
identifier exit;
@@

module_exit(exit);

@ declares_idr depends on defines_module_init && defines_module_exit @
identifier idr;
@@

DEFINE_IDR(idr);

@ on_exit_calls_destroy depends on declares_idr && defines_module_exit @
identifier declares_idr.idr, defines_module_exit.exit;
@@

exit(void)
{
 ...
 idr_destroy(&idr);
 ...
}

@ missing_module_idr_destroy depends on declares_idr && defines_module_exit && !on_exit_calls_destroy @
identifier declares_idr.idr, defines_module_exit.exit;
@@

exit(void)
{
 ...
 +idr_destroy(&idr);
}
</SmPL>

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/power/bq27x00_battery.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Pali Rohár July 8, 2015, 4:10 p.m. UTC | #1
On Wednesday 08 July 2015 17:18:20 Johannes Thumshirn wrote:
> Destroy battery_id IDR on module exit, reclaiming the allocated
> memory.
> 
> This was detected by the following semantic patch (written by Luis
> Rodriguez <mcgrof@suse.com>)
> <SmPL>
> @ defines_module_init @
> declarer name module_init, module_exit;
> declarer name DEFINE_IDR;
> identifier init;
> @@
> 
> module_init(init);
> 
> @ defines_module_exit @
> identifier exit;
> @@
> 
> module_exit(exit);
> 
> @ declares_idr depends on defines_module_init && defines_module_exit
> @ identifier idr;
> @@
> 
> DEFINE_IDR(idr);
> 
> @ on_exit_calls_destroy depends on declares_idr &&
> defines_module_exit @ identifier declares_idr.idr,
> defines_module_exit.exit;
> @@
> 
> exit(void)
> {
>  ...
>  idr_destroy(&idr);
>  ...
> }
> 
> @ missing_module_idr_destroy depends on declares_idr &&
> defines_module_exit && !on_exit_calls_destroy @ identifier
> declares_idr.idr, defines_module_exit.exit;
> @@
> 
> exit(void)
> {
>  ...
>  +idr_destroy(&idr);
> }
> </SmPL>
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> ---
>  drivers/power/bq27x00_battery.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/power/bq27x00_battery.c
> b/drivers/power/bq27x00_battery.c index b6b9837..99180d2 100644
> --- a/drivers/power/bq27x00_battery.c
> +++ b/drivers/power/bq27x00_battery.c
> @@ -1106,6 +1106,7 @@ static void __exit bq27x00_battery_exit(void)
>  {
>  	bq27x00_battery_platform_exit();
>  	bq27x00_battery_i2c_exit();
> +	idr_destroy(&battery_id);
>  }
>  module_exit(bq27x00_battery_exit);

Hello, I see that none power supply kernel driver is calling 
idr_destroy() at module exit time. So if this patch is needed for 
bq27x00_battery module, then it is needed also for other charger/battery 
modules...
Johannes Thumshirn July 9, 2015, 7:07 a.m. UTC | #2
Pali Rohár <pali.rohar@gmail.com> writes:

> On Wednesday 08 July 2015 17:18:20 Johannes Thumshirn wrote:
>> Destroy battery_id IDR on module exit, reclaiming the allocated
>> memory.
>> 
>> This was detected by the following semantic patch (written by Luis
>> Rodriguez <mcgrof@suse.com>)
>> <SmPL>
>> @ defines_module_init @
>> declarer name module_init, module_exit;
>> declarer name DEFINE_IDR;
>> identifier init;
>> @@
>> 
>> module_init(init);
>> 
>> @ defines_module_exit @
>> identifier exit;
>> @@
>> 
>> module_exit(exit);
>> 
>> @ declares_idr depends on defines_module_init && defines_module_exit
>> @ identifier idr;
>> @@
>> 
>> DEFINE_IDR(idr);
>> 
>> @ on_exit_calls_destroy depends on declares_idr &&
>> defines_module_exit @ identifier declares_idr.idr,
>> defines_module_exit.exit;
>> @@
>> 
>> exit(void)
>> {
>>  ...
>>  idr_destroy(&idr);
>>  ...
>> }
>> 
>> @ missing_module_idr_destroy depends on declares_idr &&
>> defines_module_exit && !on_exit_calls_destroy @ identifier
>> declares_idr.idr, defines_module_exit.exit;
>> @@
>> 
>> exit(void)
>> {
>>  ...
>>  +idr_destroy(&idr);
>> }
>> </SmPL>
>> 
>> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
>> ---
>>  drivers/power/bq27x00_battery.c | 1 +
>>  1 file changed, 1 insertion(+)
>> 
>> diff --git a/drivers/power/bq27x00_battery.c
>> b/drivers/power/bq27x00_battery.c index b6b9837..99180d2 100644
>> --- a/drivers/power/bq27x00_battery.c
>> +++ b/drivers/power/bq27x00_battery.c
>> @@ -1106,6 +1106,7 @@ static void __exit bq27x00_battery_exit(void)
>>  {
>>  	bq27x00_battery_platform_exit();
>>  	bq27x00_battery_i2c_exit();
>> +	idr_destroy(&battery_id);
>>  }
>>  module_exit(bq27x00_battery_exit);
>
> Hello, I see that none power supply kernel driver is calling 
> idr_destroy() at module exit time. So if this patch is needed for 
> bq27x00_battery module, then it is needed also for other charger/battery 
> modules...

You're right. I'll post a follow up for this with (this time hopefully)
all battery drivers included.
diff mbox

Patch

diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index b6b9837..99180d2 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -1106,6 +1106,7 @@  static void __exit bq27x00_battery_exit(void)
 {
 	bq27x00_battery_platform_exit();
 	bq27x00_battery_i2c_exit();
+	idr_destroy(&battery_id);
 }
 module_exit(bq27x00_battery_exit);