Skip to content

Commit 9fa33eb

Browse files
digetxgregkh
authored andcommitted
cpuidle: tegra: Correctly handle result of arm_cpuidle_simple_enter()
[ Upstream commit 1170433 ] The enter() callback of CPUIDLE drivers returns index of the entered idle state on success or a negative value on failure. The negative value could any negative value, i.e. it doesn't necessarily needs to be a error code. That's because CPUIDLE core only cares about the fact of failure and not about the reason of the enter() failure. Like every other enter() callback, the arm_cpuidle_simple_enter() returns the entered idle-index on success. Unlike some of other drivers, it never fails. It happened that TEGRA_C1=index=err=0 in the code of cpuidle-tegra driver, and thus, there is no problem for the cpuidle-tegra driver created by the typo in the code which assumes that the arm_cpuidle_simple_enter() returns a error code. The arm_cpuidle_simple_enter() also may return a -ENODEV error if CPU_IDLE is disabled in a kernel's config, but all CPUIDLE drivers are disabled if CPU_IDLE is disabled, including the cpuidle-tegra driver. So we can't ever see the error code from arm_cpuidle_simple_enter() today. Of course the code may get some changes in the future and then the typo may transform into a real bug, so let's correct the typo! The tegra_cpuidle_state_enter() is now changed to make it return the entered idle-index on success and negative error code on fail, which puts it on par with the arm_cpuidle_simple_enter(), making code consistent in regards to the error handling. This patch fixes a minor typo in the code, it doesn't fix any bugs. Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Reviewed-by: Jon Hunter <jonathanh@nvidia.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 0740ee0 commit 9fa33eb

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

drivers/cpuidle/cpuidle-tegra.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static int tegra_cpuidle_coupled_barrier(struct cpuidle_device *dev)
172172
static int tegra_cpuidle_state_enter(struct cpuidle_device *dev,
173173
int index, unsigned int cpu)
174174
{
175-
int ret;
175+
int err;
176176

177177
/*
178178
* CC6 state is the "CPU cluster power-off" state. In order to
@@ -183,9 +183,9 @@ static int tegra_cpuidle_state_enter(struct cpuidle_device *dev,
183183
* CPU cores, GIC and L2 cache).
184184
*/
185185
if (index == TEGRA_CC6) {
186-
ret = tegra_cpuidle_coupled_barrier(dev);
187-
if (ret)
188-
return ret;
186+
err = tegra_cpuidle_coupled_barrier(dev);
187+
if (err)
188+
return err;
189189
}
190190

191191
local_fiq_disable();
@@ -194,23 +194,23 @@ static int tegra_cpuidle_state_enter(struct cpuidle_device *dev,
194194

195195
switch (index) {
196196
case TEGRA_C7:
197-
ret = tegra_cpuidle_c7_enter();
197+
err = tegra_cpuidle_c7_enter();
198198
break;
199199

200200
case TEGRA_CC6:
201-
ret = tegra_cpuidle_cc6_enter(cpu);
201+
err = tegra_cpuidle_cc6_enter(cpu);
202202
break;
203203

204204
default:
205-
ret = -EINVAL;
205+
err = -EINVAL;
206206
break;
207207
}
208208

209209
cpu_pm_exit();
210210
tegra_pm_clear_cpu_in_lp2();
211211
local_fiq_enable();
212212

213-
return ret;
213+
return err ?: index;
214214
}
215215

216216
static int tegra_cpuidle_adjust_state_index(int index, unsigned int cpu)
@@ -236,21 +236,27 @@ static int tegra_cpuidle_enter(struct cpuidle_device *dev,
236236
int index)
237237
{
238238
unsigned int cpu = cpu_logical_map(dev->cpu);
239-
int err;
239+
int ret;
240240

241241
index = tegra_cpuidle_adjust_state_index(index, cpu);
242242
if (dev->states_usage[index].disable)
243243
return -1;
244244

245245
if (index == TEGRA_C1)
246-
err = arm_cpuidle_simple_enter(dev, drv, index);
246+
ret = arm_cpuidle_simple_enter(dev, drv, index);
247247
else
248-
err = tegra_cpuidle_state_enter(dev, index, cpu);
248+
ret = tegra_cpuidle_state_enter(dev, index, cpu);
249249

250-
if (err && (err != -EINTR || index != TEGRA_CC6))
251-
pr_err_once("failed to enter state %d err: %d\n", index, err);
250+
if (ret < 0) {
251+
if (ret != -EINTR || index != TEGRA_CC6)
252+
pr_err_once("failed to enter state %d err: %d\n",
253+
index, ret);
254+
index = -1;
255+
} else {
256+
index = ret;
257+
}
252258

253-
return err ? -1 : index;
259+
return index;
254260
}
255261

256262
static int tegra114_enter_s2idle(struct cpuidle_device *dev,

0 commit comments

Comments
 (0)