[PATCH] powerpc/perfctr: Check oprofile_cpu_type for NULL before using it
Michael Ellerman
michael at ellerman.id.au
Thu Aug 6 21:03:06 EST 2009
On Thu, 2009-08-06 at 14:02 +1000, Benjamin Herrenschmidt wrote:
> If the current CPU doesn't support performance counters,
> cur_cpu_spec->oprofile_cpu_type can be NULL. The current
> perfctr modules don't test for that case and would thus
> crash.
> + if (!cur_cpu_spec->oprofile_cpu_type ||
..
> + if (!cur_cpu_spec->oprofile_cpu_type ||
..
> + if (!cur_cpu_spec->oprofile_cpu_type ||
..
> + if (!cur_cpu_spec->oprofile_cpu_type ||
..
> + if (!cur_cpu_spec->oprofile_cpu_type ||
..
> + if (!cur_cpu_spec->oprofile_cpu_type ||
..
> + if (!cur_cpu_spec->oprofile_cpu_type ||
Typing it seven times didn't make you think "how about a helper?" :)
Perhaps:
diff --git a/arch/powerpc/include/asm/cputable.h b/arch/powerpc/include/asm/cput
index 80f315e..956cbc3 100644
--- a/arch/powerpc/include/asm/cputable.h
+++ b/arch/powerpc/include/asm/cputable.h
@@ -123,6 +123,11 @@ struct cpu_spec {
extern struct cpu_spec *cur_cpu_spec;
+static inline int oprofile_cpu_type_matches(const char *s)
+{
+ return s && (strcmp(cur_cpu_spec->oprofile_cpu_type, s) == 0);
+}
+
extern unsigned int __start___ftr_fixup, __stop___ftr_fixup;
extern struct cpu_spec *identify_cpu(unsigned long offset, unsigned int pvr);
And then callsites become:
static int init_mpc7450_pmu(void)
{
if (!oprofile_cpu_type_matches("ppc/7450"))
return -ENODEV;
cheers
More information about the Linuxppc-dev
mailing list