Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64b4055c authored by Naresh Malladi's avatar Naresh Malladi Committed by Maulik Shah
Browse files

drivers: cpuidle: lpm-levels: Check for negative sleep times



A negative sleep time could be interpreted as a large positive
sleep time when its casted to a unsigned type. This could result
in CPU sleeping for a longer than expected duration resulting in
missed interrupts.

Change-Id: I472f355c8ba392ab46d53fceddb448f7e35c178e
Signed-off-by: default avatarMahesh Sivasubramanian <msivasub@codeaurora.org>
Signed-off-by: default avatarMaulik Shah <mkshah@codeaurora.org>
Signed-off-by: default avatarNaresh Malladi <namall@codeaurora.org>
parent c619a7c2
Loading
Loading
Loading
Loading
+3 −4
Original line number Original line Diff line number Diff line
@@ -571,22 +571,21 @@ static int cpu_power_select(struct cpuidle_device *dev,
	int best_level = -1;
	int best_level = -1;
	uint32_t latency_us = pm_qos_request_for_cpu(PM_QOS_CPU_DMA_LATENCY,
	uint32_t latency_us = pm_qos_request_for_cpu(PM_QOS_CPU_DMA_LATENCY,
							dev->cpu);
							dev->cpu);
	uint32_t sleep_us =
	s64 sleep_us = ktime_to_us(tick_nohz_get_sleep_length());
		(uint32_t)(ktime_to_us(tick_nohz_get_sleep_length()));
	uint32_t modified_time_us = 0;
	uint32_t modified_time_us = 0;
	uint32_t next_event_us = 0;
	uint32_t next_event_us = 0;
	int i, idx_restrict;
	int i, idx_restrict;
	uint32_t lvl_latency_us = 0;
	uint32_t lvl_latency_us = 0;
	uint64_t predicted = 0;
	uint64_t predicted = 0;
	uint32_t htime = 0, idx_restrict_time = 0;
	uint32_t htime = 0, idx_restrict_time = 0;
	uint32_t next_wakeup_us = sleep_us;
	uint32_t next_wakeup_us = (uint32_t)sleep_us;
	uint32_t *min_residency = get_per_cpu_min_residency(dev->cpu);
	uint32_t *min_residency = get_per_cpu_min_residency(dev->cpu);
	uint32_t *max_residency = get_per_cpu_max_residency(dev->cpu);
	uint32_t *max_residency = get_per_cpu_max_residency(dev->cpu);


	if (!cpu)
	if (!cpu)
		return -EINVAL;
		return -EINVAL;


	if (sleep_disabled)
	if (sleep_disabled || sleep_us < 0)
		return 0;
		return 0;


	idx_restrict = cpu->nlevels + 1;
	idx_restrict = cpu->nlevels + 1;