Skip to content

Commit e6bde73

Browse files
mitatorvalds
authored andcommitted
cpu-hotplug: return better errno on cpu hotplug failure
Currently, onlining or offlining a CPU failure by one of the cpu notifiers error always cause -EINVAL error. (i.e. writing 0 or 1 to /sys/devices/system/cpu/cpuX/online gets EINVAL) To get better error reporting rather than always getting -EINVAL, This changes cpu_notify() to return -errno value with notifier_to_errno() and fix the callers. Now that cpu notifiers can return encapsulate errno value. Currently, all cpu hotplug notifiers return NOTIFY_OK, NOTIFY_BAD, or NOTIFY_DONE. So cpu_notify() can returns 0 or -EPERM with this change for now. (notifier_to_errno(NOTIFY_OK) == 0, notifier_to_errno(NOTIFY_DONE) == 0, notifier_to_errno(NOTIFY_BAD) == -EPERM) Forthcoming patches convert several cpu notifiers to return encapsulate errno value with notifier_from_errno(). Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e9fb763 commit e6bde73

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎kernel/cpu.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,12 @@ int __ref register_cpu_notifier(struct notifier_block *nb)
137137
static int __cpu_notify(unsigned long val, void *v, int nr_to_call,
138138
int *nr_calls)
139139
{
140-
return __raw_notifier_call_chain(&cpu_chain, val, v, nr_to_call,
140+
int ret;
141+
142+
ret = __raw_notifier_call_chain(&cpu_chain, val, v, nr_to_call,
141143
nr_calls);
144+
145+
return notifier_to_errno(ret);
142146
}
143147

144148
static int cpu_notify(unsigned long val, void *v)
@@ -151,7 +155,7 @@ static void cpu_notify_nofail(unsigned long val, void *v)
151155
int err;
152156

153157
err = cpu_notify(val, v);
154-
BUG_ON(err == NOTIFY_BAD);
158+
BUG_ON(err);
155159
}
156160

157161
#ifdef CONFIG_HOTPLUG_CPU
@@ -232,14 +236,13 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
232236
cpu_hotplug_begin();
233237
set_cpu_active(cpu, false);
234238
err = __cpu_notify(CPU_DOWN_PREPARE | mod, hcpu, -1, &nr_calls);
235-
if (err == NOTIFY_BAD) {
239+
if (err) {
236240
set_cpu_active(cpu, true);
237241

238242
nr_calls--;
239243
__cpu_notify(CPU_DOWN_FAILED | mod, hcpu, nr_calls, NULL);
240244
printk("%s: attempt to take down CPU %u failed\n",
241245
__func__, cpu);
242-
err = -EINVAL;
243246
goto out_release;
244247
}
245248

@@ -304,11 +307,10 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
304307

305308
cpu_hotplug_begin();
306309
ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls);
307-
if (ret == NOTIFY_BAD) {
310+
if (ret) {
308311
nr_calls--;
309312
printk("%s: attempt to bring up CPU %u failed\n",
310313
__func__, cpu);
311-
ret = -EINVAL;
312314
goto out_notify;
313315
}
314316

0 commit comments

Comments
 (0)