diff mbox

powerpc/perfctr: Check oprofile_cpu_type for NULL before using it

Message ID 1249556586.4800.79.camel@concordia (mailing list archive)
State Not Applicable
Headers show

Commit Message

Michael Ellerman Aug. 6, 2009, 11:03 a.m. UTC
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:



And then callsites become:

 static int init_mpc7450_pmu(void)
 {
        if (!oprofile_cpu_type_matches("ppc/7450"))
                return -ENODEV;


cheers

Comments

Benjamin Herrenschmidt Aug. 6, 2009, 12:26 p.m. UTC | #1
On Thu, 2009-08-06 at 21:03 +1000, Michael Ellerman wrote:
> 
> Typing it seven times didn't make you think "how about a helper?" :)

Copy/paste works fine :-) Seriously, I did think about it, but a couple
of cases test more than one string so a totally trivial helper wouldn't
do and I couldn't be bothered doing anything more complicated while
under influenza :-) You are welcome to do something nicer for .32.

BTW. While at it, I think we should move that stuff to a separate
subdir too.

Cheers,
Ben.
diff mbox

Patch

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);