From b96efcf7b062b79bf6d6739cc4eaa3cbe4258286 Mon Sep 17 00:00:00 2001 From: Masamichi Takagi Date: Sun, 26 Jan 2020 12:30:09 +0000 Subject: [PATCH] smp_ihk_release_cpu: Fix error handling * Range-check CPU ID * Error-return when trying to online onlined CPU Change-Id: I437d3046333e54e7525d41c2d2ab1006846d003e --- linux/driver/smp/smp-driver.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/linux/driver/smp/smp-driver.c b/linux/driver/smp/smp-driver.c index 94159305..b53ec86f 100644 --- a/linux/driver/smp/smp-driver.c +++ b/linux/driver/smp/smp-driver.c @@ -3716,6 +3716,13 @@ static int smp_ihk_release_cpu(ihk_device_t ihk_dev, unsigned long arg) memset(&cpus_to_online, 0, sizeof(cpus_to_online)); for (i = 0; i < req.num_cpus; i++) { + if (req_cpus[i] < 0 || req_cpus[i] >= nr_cpu_ids) { + pr_info("%s: error: CPU %d is out of range\n", + __func__, req_cpus[i]); + + ret = -EINVAL; + goto out; + } cpumask_set_cpu(req_cpus[i], &cpus_to_online); } @@ -3740,7 +3747,10 @@ static int smp_ihk_release_cpu(ihk_device_t ihk_dev, unsigned long arg) } if (cpu_online(cpu)) { - continue; + printk("IHK-SMP: error: CPU %d is online\n", + cpu); + ret = -EINVAL; + goto err; } if (ihk_smp_cpus[cpu].status != IHK_SMP_CPU_AVAILABLE) {