omap3: sr: fix memory leak and simplify the code
Subsystems (3)
PATCH 1/2 omap3: sr: fix memory leak and simplify the code
From: Artem Bityutskiy <[email protected]>
This patch fixes the following problem indicated by kmemleak:
kmemleak: unreferenced object 0xdf93c280 (size 64): kmemleak: backtrace: kmemleak: [<c00df6d4>] create_object+0x104/0x200 kmemleak: [<c00d7638>] kmem_cache_alloc+0xe4/0xf4 kmemleak: [<c000fc38>] omap_devinit_smartreflex+0x44/0x244 kmemleak: [<c003a33c>] do_one_initcall+0x5c/0x1b8 kmemleak: [<c00083fc>] kernel_init+0x94/0x110 kmemleak: [<c003ba04>] kernel_thread_exit+0x0/0x8
The reason is that 'omap_devinit_smartreflex()' allocates 'sr_data', then passes it to 'omap_device_build()', which 'kmemdup()'s it and uses the copy. But 'omap_devinit_smartreflex()' never frees 'sr_data'.
This patch make 'sr_data' to be a stack variable, which eliminates the memory leak and simplifies the code a bit.
--- arch/arm/mach-omap2/sr_device.c | 27 +++++++++------------------ 1 files changed, 9 insertions(+), 18 deletions(-)
arch/arm/mach-omap2/sr_device.c +9 -18
@@ -129,7 +129,7 @@ static int __init omap_devinit_smartreflex(void)char *name ="smartreflex" ; do { - struct omap_smartreflex_data *sr_data; + struct omap_smartreflex_data sr_data; struct omap_smartreflex_dev_data *sr_dev_data; struct omap_device *od; struct omap_hwmod *oh;
@@ -140,15 +140,7 @@ static int __init omap_devinit_smartreflex(void)if (!oh)break ; - sr_data =kzalloc (sizeof (struct omap_smartreflex_data ), -GFP_KERNEL ); sr_dev_data = (struct omap_smartreflex_dev_data *)oh->dev_attr; -if (!sr_data) { -pr_warning ("%s: could not find hwmod data for %d\n" , - __func__, i +1 ); -kfree (sr_data); -return -ENOMEM ; - }/* * OMAP3430 ES3.1 chips by default come with Efuse burnt
@@ -159,26 +151,25 @@ static int __init omap_devinit_smartreflex(void)*/ if (cpu_is_omap343x ()) {if (omap_rev () ==OMAP3430_REV_ES3_1 ) - sr_data->enable_on_init = true; + sr_data.enable_on_init = true;else - sr_data->enable_on_init = false; + sr_data.enable_on_init = false; }else { - sr_data->enable_on_init = false; + sr_data.enable_on_init = false; } - sr_data->device_enable = omap_device_enable; - sr_data->device_shutdown = omap_device_shutdown; - sr_data->device_idle = omap_device_idle; + sr_data.device_enable = omap_device_enable; + sr_data.device_shutdown = omap_device_shutdown; + sr_data.device_idle = omap_device_idle;omap_get_voltage_table (i, &sr_dev_data->volt_data, &sr_dev_data->volts_supported); -sr_set_nvalues (sr_dev_data, sr_data); +sr_set_nvalues (sr_dev_data, &sr_data); - od =omap_device_build (name, i, oh, sr_data,sizeof (*sr_data), + od =omap_device_build (name, i, oh, &sr_data,sizeof (sr_data), omap_sr_latency,ARRAY_SIZE (omap_sr_latency),0 );if (IS_ERR (od)) {pr_warning ("%s: Could not build omap_device %s:%s\n" , __func__, name, oh->name); -kfree (sr_data); } i++; }while (1 );
Signature · 1 line
1.7.1.1
PATCH 2/2 omap3: sr: improve errors handling
From: Artem Bityutskiy <[email protected]>
Do not forget to check the 'platform_device_add_data()' error code in 'omap_device_build_ss()'.
--- arch/arm/plat-omap/omap_device.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
arch/arm/plat-omap/omap_device.c +3 -1
@@ -414,7 +414,9 @@ struct omap_device *omap_device_build_ss(const char *pdev_name, int pdev_id, od->pdev.num_resources = res_count; od->pdev.resource = res; -platform_device_add_data (&od->pdev, pdata, pdata_len); + ret =platform_device_add_data (&od->pdev, pdata, pdata_len); +if (ret) + goto odbs_exit4; od->pm_lats = pm_lats; od->pm_lats_cnt = pm_lats_cnt;
Signature · 1 line
1.7.1.1
Re: [PATCH 2/2] omap3: sr: improve errors handling
Artem Bityutskiy had written, on 07/09/2010 08:20 AM, the following:
Quoted 6 lines
From: Artem Bityutskiy <[email protected]>
Do not forget to check the '
platform_device_add_data()' error code in 'omap_device_build_ss()'.Signed-off-by Artem Bityutskiy <[email protected]>
Quoted 19 lines
--- arch/arm/plat-omap/omap_device.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)arch/arm/plat-omap/omap_device.c +3
-1@@ -414,7 +414,9 @@ struct omap_device *omap_device_build_ss(const char *pdev_name, int pdev_id, od->pdev.num_resources = res_count; od->pdev.resource = res; -platform_device_add_data (&od->pdev, pdata, pdata_len); + ret =platform_device_add_data (&od->pdev, pdata, pdata_len); +if (ret) + goto odbs_exit4; od->pm_lats = pm_lats; od->pm_lats_cnt = pm_lats_cnt;
Signature · 2 lines
Regards, Nishanth Menon
RE: [PATCH 2/2] omap3: sr: improve errors handling
In reply to Artem BityutskiyQuoted 9 lines
Quoted 9 lines
-----Original Message-----
From: Artem Bityutskiy [mailto:[email protected]]
Sent: Friday, July 09, 2010 6:50 PM
To: [email protected]
Cc: Menon, Nishanth; Kevin Hilman; Gopinath, Thara; Peter p2 De Schrijver
Subject: [PATCH 2/2] omap3: sr: improve errors handling
Quoted 4 lines
Quoted 4 lines
From: Artem Bityutskiy <[email protected]>
Do not forget to check the '
platform_device_add_data()' error code in 'omap_device_build_ss()'.
Hello Artem,
Can we have a better subject and description. The subject esp has got nothing to do with the fix.
Regards
Thara
Quoted 23 lines
Quoted 23 lines
Signed-off-by Artem Bityutskiy <[email protected]>---
arch/arm/plat-omap/omap_device.c| 4 +++-1 files changed, 3 insertions(+), 1 deletions(-)arch/arm/plat-omap/omap_device.c +3
-2@@ -414,7 +414,9 @@ struct omap_device *omap_device_build_ss(const char *pdev_name, int pdev_id, od->pdev.num_resources = res_count; od->pdev.resource = res; -platform_device_add_data (&od->pdev, pdata, pdata_len); + ret =platform_device_add_data (&od->pdev, pdata, pdata_len); +if (ret) + goto odbs_exit4; od->pm_lats = pm_lats; od->pm_lats_cnt = pm_lats_cnt; --1.7.1.1
RE: [PATCH 2/2] omap3: sr: improve errors handling
Quoted 10 lines · Thara
Quoted 10 lines
Quoted 10 lines
-----Original Message-----
From: Artem Bityutskiy [mailto:[email protected]]
Sent: Friday, July 09, 2010 6:50 PM
To: [email protected]
Cc: Menon, Nishanth; Kevin Hilman; Gopinath, Thara; Peter p2 De Schrijver
Subject: [PATCH 2/2] omap3: sr: improve errors handlingFrom: Artem Bityutskiy <[email protected]>
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Do not forget to check the '
platform_device_add_data()' error code in 'omap_device_build_ss()'.Hello Artem,
Can we have a better subject and description. The subject esp has got nothing to do with the fix.
Hmm, I do not see why you think so. I think the subject is fine - the patch improves error handling in the SR code. Then description says how exactly it improves it - it makes the code to not forget to check the return code, and it tells in which function and which return code.
So the logic is:
1. The subject line is a short description which gives the idea what the commit is about. So, my subject line says:
1.1. It is about omap3 (which is true)
1.2. It is about sr (which is true)
1.3. It improves error handling (which is also true)
So the subject line is descriptive enough. It does not have to provide all glory details.
Then the description provides the details.
Signature · 7 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий) -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/2] omap3: sr: improve errors handling
Artem Bityutskiy had written, on 07/09/2010 10:44 AM, the following:
Quoted 22 lines · Thara
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Artem Bityutskiy [mailto:[email protected]]
Sent: Friday, July 09, 2010 6:50 PM
To: [email protected]
Cc: Menon, Nishanth; Kevin Hilman; Gopinath, Thara; Peter p2 De Schrijver
Subject: [PATCH 2/2] omap3: sr: improve errors handlingQuoted 8 lines
Quoted 4 lines
Quoted 4 lines
From: Artem Bityutskiy <[email protected]>
Do not forget to check the '
platform_device_add_data()' error code in 'omap_device_build_ss()'.Hello Artem,
Can we have a better subject and description. The subject esp has got nothing to do with the fix.
Hmm, I do not see why you think so. I think the subject is fine - the patch improves error handling in the SR code. Then description says how exactly it improves it - it makes the code to not forget to check the return code, and it tells in which function and which return code.
Quoted 6 lines
So the logic is:
1. The subject line is a short description which gives the idea what the commit is about. So, my subject line says:
1.1. It is about omap3 (which is true)
1.2. It is about sr (which is true)
I think Thara's contention is that this is omap_device related- yeah SR is one of the users of omap_device, but there are much more folks using omap_device in l-o today.
Quoted 7 lines
1.3. It improves error handling (which is also true)
So the subject line is descriptive enough. It does not have to provide all glory details.
Then the description provides the details.
Signature · 2 lines
Regards, Nishanth Menon
Re: [PATCH 2/2] omap3: sr: improve errors handling
Quoted 9 lines · Nishanth Menon
Quoted 6 lines
So the logic is:
1. The subject line is a short description which gives the idea what the commit is about. So, my subject line says:
1.1. It is about omap3 (which is true)
1.2. It is about sr (which is true)I think Thara's contention is that this is
omap_devicerelated- yeah SR is one of the users ofomap_device, but there are much more folks usingomap_devicein l-o today.
I see. I'll try to come up with a better prefix, but if you suggest me a good subject line, I'll be grateful :-)
Signature · 7 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий) -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 2/2] omap3: sr: improve errors handling
Quoted 12 lines
-----Original Message-----
From: Artem Bityutskiy [mailto:[email protected]]
Sent: Friday, July 09, 2010 10:51 AMQuoted 3 lines · Nishanth Menon
Quoted 3 lines
So the logic is:
1. The subject line is a short description which gives the idea what
the
Quoted 3 lines
Quoted 3 lines
commit is about. So, my subject line says:
1.1. It is about omap3 (which is true)
1.2. It is about sr (which is true)
Quoted 6 lines
Quoted 3 lines
I think Thara's contention is that this is
omap_devicerelated- yeah SR is one of the users ofomap_device, but there are much more folks usingomap_devicein l-o today.I see. I'll try to come up with a better prefix, but if you suggest me a good subject line, I'll be grateful :-)
Subject: omap: device: improve errors handling
Do not forget to check the 'platform_device_add_data()' error code in 'omap_device_build_ss()'.
How does that sound?
RE: [PATCH 2/2] omap3: sr: improve errors handling
Quoted 19 lines · Nishanth
Quoted 12 lines
-----Original Message-----
From: Artem Bityutskiy [mailto:[email protected]]
Sent: Friday, July 09, 2010 10:51 AMQuoted 3 lines · Nishanth Menon
Quoted 3 lines
So the logic is:
1. The subject line is a short description which gives the idea what
the
Quoted 3 lines
Quoted 3 lines
commit is about. So, my subject line says:
1.1. It is about omap3 (which is true)
1.2. It is about sr (which is true)Quoted 6 lines
Quoted 3 lines
I think Thara's contention is that this is
omap_devicerelated- yeah SR is one of the users ofomap_device, but there are much more folks usingomap_devicein l-o today.I see. I'll try to come up with a better prefix, but if you suggest me a good subject line, I'll be grateful :-)
Quoted 6 lines
Subject: omap: device: improve errors handling
Do not forget to check the '
platform_device_add_data()' error code in 'omap_device_build_ss()'.How does that sound?
Good, thank you! I'll re-send the patch tomorrow unless you change the subject yourself :-)
Signature · 7 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий) -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/2] omap3: sr: improve errors handling
In reply to Artem BityutskiyQuoted 6 lines · Artem Bityutskiy
From: Artem Bityutskiy <[email protected]>
Do not forget to check the '
platform_device_add_data()' error code in 'omap_device_build_ss()'.Signed-off-by Artem Bityutskiy <[email protected]>
Please, discard this patch, I'll send a new one with amended subject.
Signature · 7 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий) -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 17 lines · Artem Bityutskiy
From: Artem Bityutskiy <[email protected]>
This patch fixes the following problem indicated by kmemleak:
kmemleak: unreferenced object 0xdf93c280 (size 64): kmemleak: backtrace: kmemleak: [<c00df6d4>] create_object+0x104/0x200 kmemleak: [<c00d7638>] kmem_cache_alloc+0xe4/0xf4 kmemleak: [<c000fc38>] omap_devinit_smartreflex+0x44/0x244 kmemleak: [<c003a33c>] do_one_initcall+0x5c/0x1b8 kmemleak: [<c00083fc>] kernel_init+0x94/0x110 kmemleak: [<c003ba04>] kernel_thread_exit+0x0/0x8The reason is that '
omap_devinit_smartreflex()' allocates 'sr_data', then passes it to 'omap_device_build()', which 'kmemdup()'s it and uses the copy. But 'omap_devinit_smartreflex()' never frees 'sr_data'.
Quoted 7 lines
This patch make '
sr_data' to be a stack variable, which eliminates the memory leak and simplifies the code a bit.Signed-off-by Artem Bityutskiy <[email protected]>--- arch/arm/mach-omap2/sr_device.c | 27 +++++++++------------------ 1 files changed, 9 insertions(+), 18 deletions(-)
Note, I only compile-tested both of the patches, so be careful.
Signature · 7 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий) -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html