intel_pstate: fix race condition in intel_pstate_init()

There is a race condition in the intel pstate driver initialization:
the cpufreq_register_driver() function creates a timer that makes use of the
energy_divisor variable (intel_pstate_timer_func), the problem is that energy_divisor is initialized
*after* the call to cpufreq_register_driver().

This patch fixes the bug by initializing energy_divisor before the
call to cpufreq_register_driver().

 Intel pstate controlling: cpu 2
 divide error: 0000 [#1] SMP
 Modules linked in:
 CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.14.0-rc1-linux-mainline+ #7
 Hardware name: wortmann To be filled by O.E.M./P8B-M Series, BIOS 6103 12/06/2012
 task: ffff880223948000 ti: ffff880223944000 task.ti: ffff880223944000
 RIP: 0010:[<ffffffff81548b07>]  [<ffffffff81548b07>] intel_pstate_timer_func+0x2b7/0x430
 RSP: 0000:ffff880226e03d58  EFLAGS: 00010246
 RAX: 0000000006130063 RBX: ffff88022191b800 RCX: 0000000000000199
 RDX: 0000000000000000 RSI: 0000000000002000 RDI: 0000000000000199
 RBP: ffff880226e03dd8 R08: ffff88022191b850 R09: ffff880223948cc8
 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000002
 R13: 0000000006130063 R14: 0000003b3a91a54e R15: ffff880226e03da4
 FS:  0000000000000000(0000) GS:ffff880226e00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: ffff88022ffff000 CR3: 0000000001a0e000 CR4: 00000000000407f0
 Stack:
  ffff880226e03dd8 0000000000000246 0000000000000000 ffffffff8108a0c0
  0000000000000000 ffffffff82dc18d0 ffff880226e03d98 0000000000000246
  0000000026e03da8 0000000026e03e08 0000000000000038 ffff88022191b848
 Call Trace:
  <IRQ>
  [<ffffffff8108a0c0>] ? cascade+0xb0/0xb0
  [<ffffffff81548850>] ? intel_pstate_platform_pwr_mgmt_exists+0x1e0/0x1e0
  [<ffffffff8108a158>] call_timer_fn+0x98/0x260
  [<ffffffff8108a0c0>] ? cascade+0xb0/0xb0
  [<ffffffff816de600>] ? _raw_spin_unlock_irq+0x30/0x50
  [<ffffffff8108bc78>] run_timer_softirq+0x298/0x310
  [<ffffffff81100eef>] ? rcu_irq_exit+0x8f/0xe0
  [<ffffffff816debf3>] ? retint_restore_args+0x13/0x13
  [<ffffffff81548850>] ? intel_pstate_platform_pwr_mgmt_exists+0x1e0/0x1e0
  [<ffffffff81082584>] __do_softirq+0x144/0x4f0
  [<ffffffff81082ebd>] irq_exit+0x14d/0x180
  [<ffffffff816eb2da>] smp_apic_timer_interrupt+0x4a/0x60
  [<ffffffff816e9bf2>] apic_timer_interrupt+0x72/0x80
  <EOI>
  [<ffffffff810e2ff0>] ? mark_held_locks+0x90/0x150
  [<ffffffff810f5070>] ? vprintk_emit+0x1c0/0x610
  [<ffffffff816de660>] ? _raw_spin_unlock_irqrestore+0x40/0x80
  [<ffffffff816d74ea>] printk+0x77/0x79
  [<ffffffff815479bc>] ? core_get_turbo_pstate+0x3c/0x60
  [<ffffffff815481a5>] intel_pstate_init_cpu+0x395/0x3a0
  [<ffffffff815481cb>] intel_pstate_cpu_init+0x1b/0x100
  [<ffffffff81543933>] __cpufreq_add_dev+0x213/0x780
  [<ffffffff816cd6fe>] ? klist_next+0x8e/0x120
  [<ffffffff81543eb0>] cpufreq_add_dev+0x10/0x20
  [<ffffffff8145d921>] subsys_interface_register+0xb1/0xe0
  [<ffffffff810e345d>] ? trace_hardirqs_on+0xd/0x10
  [<ffffffff81541a1e>] cpufreq_register_driver+0xfe/0x2a0
  [<ffffffff81ddd383>] intel_pstate_init+0x14a/0x310
  [<ffffffff816d9cbe>] ? mutex_unlock+0xe/0x10
  [<ffffffff81ddd239>] ? intel_pstate_setup+0x2e/0x2e
  [<ffffffff810020da>] do_one_initcall+0xda/0x180
  [<ffffffff81d8ed9b>] ? kernel_init_freeable+0x31a/0x31a
  [<ffffffff81d8ea5e>] do_basic_setup+0x9d/0xc0
  [<ffffffff81d8ed9b>] ? kernel_init_freeable+0x31a/0x31a
  [<ffffffff81d8ed18>] kernel_init_freeable+0x297/0x31a
  [<ffffffff816cddce>] ? kernel_init+0xe/0xf0
  [<ffffffff810e3385>] ? trace_hardirqs_on_caller+0x105/0x1d0
  [<ffffffff816cddc0>] ? rest_init+0x170/0x170
  [<ffffffff816cddce>] kernel_init+0xe/0xf0
  [<ffffffff816e8e3c>] ret_from_fork+0x7c/0xb0
  [<ffffffff816cddc0>] ? rest_init+0x170/0x170
 Code: c8 00 00 00 48 89 df 01 d6 e8 b6 f1 ff ff eb 0e 0f 1f 40 00 29 d6 48 89 df e8 a6 f1 ff ff 4b 8d 04 a4 31 d2 4c 8d 04 c3 4c 89 e8 <48> f7 35 fa 8d 9b 01 45 8b b8 40 01 00 00 41 89 c1 49 8b 80 28
 RIP  [<ffffffff81548b07>] intel_pstate_timer_func+0x2b7/0x430
  RSP <ffff880226e03d58>
 tsc: Refined TSC clocksource calibration: 3092.975 MHz
 divide error: 0000 [#2] [    2.760064] ---[ end trace b87c91b37801378a ]---
 Kernel panic - not syncing: Fatal exception in interrupt

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
Acked-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Merge branch 'pm-cpufreq' into bleeding-edge

* pm-cpufreq:
  intel_pstate: fix race condition in intel_pstate_init()