fbdev: imsttfb: Fix use after free bug in imsttfb_probe
[linux-block.git] / drivers / cpuidle / poll_state.c
CommitLineData
55716d26 1// SPDX-License-Identifier: GPL-2.0-only
34c2f65b
RW
2/*
3 * poll_state.c - Polling idle state
34c2f65b
RW
4 */
5
6#include <linux/cpuidle.h>
7#include <linux/sched.h>
a37b969a 8#include <linux/sched/clock.h>
34c2f65b
RW
9#include <linux/sched/idle.h>
10
4dc2375c 11#define POLL_IDLE_RELAX_COUNT 200
a37b969a 12
34c2f65b
RW
13static int __cpuidle poll_idle(struct cpuidle_device *dev,
14 struct cpuidle_driver *drv, int index)
15{
00717eb8
PZ
16 u64 time_start;
17
00717eb8 18 time_start = local_clock();
a37b969a 19
5f26bdce
RW
20 dev->poll_time_limit = false;
21
5e26aa93 22 raw_local_irq_enable();
34c2f65b 23 if (!current_set_polling_and_test()) {
4dc2375c 24 unsigned int loop_count = 0;
259231a0 25 u64 limit;
800fb34a 26
259231a0 27 limit = cpuidle_poll_time(drv, dev);
4dc2375c 28
a37b969a 29 while (!need_resched()) {
34c2f65b 30 cpu_relax();
4dc2375c
RW
31 if (loop_count++ < POLL_IDLE_RELAX_COUNT)
32 continue;
a37b969a 33
4dc2375c 34 loop_count = 0;
01bad1c6 35 if (local_clock() - time_start > limit) {
5f26bdce 36 dev->poll_time_limit = true;
a37b969a 37 break;
5f26bdce 38 }
a37b969a 39 }
34c2f65b 40 }
5e26aa93
PZ
41 raw_local_irq_disable();
42
34c2f65b
RW
43 current_clr_polling();
44
45 return index;
46}
47
1b39e3f8 48void cpuidle_poll_state_init(struct cpuidle_driver *drv)
34c2f65b
RW
49{
50 struct cpuidle_state *state = &drv->states[0];
51
52 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
53 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
54 state->exit_latency = 0;
55 state->target_residency = 0;
c1d51f68
RW
56 state->exit_latency_ns = 0;
57 state->target_residency_ns = 0;
34c2f65b
RW
58 state->power_usage = -1;
59 state->enter = poll_idle;
34c2f65b
RW
60 state->flags = CPUIDLE_FLAG_POLLING;
61}
1b39e3f8 62EXPORT_SYMBOL_GPL(cpuidle_poll_state_init);