arch: powerpc/fadump: Cleaning up inconsistent NULL checks
authorRickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Thu, 22 May 2014 22:03:16 +0000 (00:03 +0200)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Wed, 28 May 2014 03:35:39 +0000 (13:35 +1000)
Cleaning up inconsistent NULL checks.
There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/kernel/fadump.c

index 02667744fbb55c4ddbbd9eb22a208136fd2c1c29..d55e8986730a087f69f3596ca8bb85b398a92477 100644 (file)
@@ -646,7 +646,7 @@ static int __init fadump_build_cpu_notes(const struct fadump_mem_struct *fdm)
                }
                /* Lower 4 bytes of reg_value contains logical cpu id */
                cpu = reg_entry->reg_value & FADUMP_CPU_ID_MASK;
-               if (!cpumask_test_cpu(cpu, &fdh->cpu_online_mask)) {
+               if (fdh && !cpumask_test_cpu(cpu, &fdh->cpu_online_mask)) {
                        SKIP_TO_NEXT_CPU(reg_entry);
                        continue;
                }
@@ -663,9 +663,11 @@ static int __init fadump_build_cpu_notes(const struct fadump_mem_struct *fdm)
        }
        fadump_final_note(note_buf);
 
-       pr_debug("Updating elfcore header (%llx) with cpu notes\n",
+       if (fdh) {
+               pr_debug("Updating elfcore header (%llx) with cpu notes\n",
                                                        fdh->elfcorehdr_addr);
-       fadump_update_elfcore_header((char *)__va(fdh->elfcorehdr_addr));
+               fadump_update_elfcore_header((char *)__va(fdh->elfcorehdr_addr));
+       }
        return 0;
 
 error_out: