From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/3] ARM: oprofile: fix and simplify init/exit functions
Date: Sun, 29 Aug 2010 19:52:00 +0100 [thread overview]
Message-ID: <1283107921-21464-3-git-send-email-will.deacon@arm.com> (raw)
In-Reply-To: <1283107921-21464-2-git-send-email-will.deacon@arm.com>
Now that oprofile_arch_exit is only called when the OProfile module
is unloaded, it can assume that init completed successfully and not
have to worry about double frees or releasing NULL perf events.
This patch ensures that oprofile_arch_init fails gracefully on ARM
and simplifies the exit code based on the above.
Cc: Robert Richter <robert.richter@amd.com>
Cc: Matt Fleming <matt@console-pimps.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
arch/arm/oprofile/common.c | 47 +++++++++++++++++++++++--------------------
1 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/arch/arm/oprofile/common.c b/arch/arm/oprofile/common.c
index 0691176..c2c4a2e 100644
--- a/arch/arm/oprofile/common.c
+++ b/arch/arm/oprofile/common.c
@@ -275,7 +275,7 @@ out:
return ret;
}
-static void exit_driverfs(void)
+static void __exit exit_driverfs(void)
{
platform_device_unregister(oprofile_pdev);
platform_driver_unregister(&oprofile_driver);
@@ -359,14 +359,13 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
if (!counter_config) {
pr_info("oprofile: failed to allocate %d "
"counters\n", perf_num_counters);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto out;
}
ret = init_driverfs();
- if (ret) {
- kfree(counter_config);
- return ret;
- }
+ if (ret)
+ goto out;
for_each_possible_cpu(cpu) {
perf_events[cpu] = kcalloc(perf_num_counters,
@@ -374,9 +373,8 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
if (!perf_events[cpu]) {
pr_info("oprofile: failed to allocate %d perf events "
"for cpu %d\n", perf_num_counters, cpu);
- while (--cpu >= 0)
- kfree(perf_events[cpu]);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto out;
}
}
@@ -393,28 +391,33 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
else
pr_info("oprofile: using %s\n", ops->cpu_type);
+out:
+ if (ret) {
+ kfree(counter_config);
+ for_each_possible_cpu(cpu)
+ kfree(perf_events[cpu]);
+ }
+
return ret;
}
-void oprofile_arch_exit(void)
+void __exit oprofile_arch_exit(void)
{
int cpu, id;
struct perf_event *event;
- if (*perf_events) {
- exit_driverfs();
- for_each_possible_cpu(cpu) {
- for (id = 0; id < perf_num_counters; ++id) {
- event = perf_events[cpu][id];
- if (event != NULL)
- perf_event_release_kernel(event);
- }
- kfree(perf_events[cpu]);
+ for_each_possible_cpu(cpu) {
+ for (id = 0; id < perf_num_counters; ++id) {
+ event = perf_events[cpu][id];
+ if (event)
+ perf_event_release_kernel(event);
}
+
+ kfree(perf_events[cpu]);
}
- if (counter_config)
- kfree(counter_config);
+ kfree(counter_config);
+ exit_driverfs();
}
#else
int __init oprofile_arch_init(struct oprofile_operations *ops)
@@ -422,5 +425,5 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
pr_info("oprofile: hardware counters not available\n");
return -ENODEV;
}
-void oprofile_arch_exit(void) {}
+void __exit oprofile_arch_exit(void) {}
#endif /* CONFIG_HW_PERF_EVENTS */
--
1.6.3.3
next prev parent reply other threads:[~2010-08-29 18:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-29 18:51 [PATCH 0/3] stop OProfile calling arch_exit when arch_init fails Will Deacon
2010-08-29 18:51 ` [PATCH 1/3] oprofile: don't call arch exit code from init code on failure Will Deacon
2010-08-29 18:52 ` Will Deacon [this message]
2010-08-29 18:52 ` [PATCH 3/3] x86: oprofile: fix oprofile_arch_init behaviour " Will Deacon
2010-08-30 9:09 ` Robert Richter
2010-08-31 8:54 ` Will Deacon
2010-08-31 9:05 ` Robert Richter
2010-08-31 9:31 ` Will Deacon
2010-08-31 9:47 ` Robert Richter
2010-08-31 10:30 ` [PATCH] oprofile, x86: fix init_sysfs error handling Robert Richter
2010-09-01 9:51 ` Ingo Molnar
2010-09-01 13:07 ` Robert Richter
2010-08-31 11:01 ` [PATCH 0/3] stop OProfile calling arch_exit when arch_init fails Robert Richter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1283107921-21464-3-git-send-email-will.deacon@arm.com \
--to=will.deacon@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).