Re: [PATCH] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size.

From: Chen Yu
Date: Wed Mar 29 2023 - 21:51:45 EST


On 2023-03-29 at 12:26:10 -0400, Chris Hyser wrote:
> From: chris hyser <chris.hyser@xxxxxxxxxx>
>
> Commit 6419265899d9 ("sched/fair: Fix division by zero
> sysctl_numa_balancing_scan_size") prevented a divide by zero by using
> sysctl mechanisms to return EINVAL for a sysctl_numa_balancing_scan_size
> value of zero. When moved from a sysctl to a debugfs file, this checking
> was lost.
>
> This patch puts zero checking back in place.
>
> Signed-off-by: Chris Hyser <chris.hyser@xxxxxxxxxx>
> ---
> kernel/sched/debug.c | 50 +++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 49 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index 1637b65ba07a..dfd0fe6123ec 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -278,6 +278,54 @@ static const struct file_operations sched_dynamic_fops = {
>
> #endif /* CONFIG_PREEMPT_DYNAMIC */
>
> +#ifdef CONFIG_NUMA_BALANCING
> +
> +static ssize_t sched_numa_scan_write(struct file *filp, const char __user *ubuf,
> + size_t cnt, loff_t *ppos)
> +{
> + char buf[16];
> + unsigned int scan_size;
> +
> + if (cnt > 15)
> + cnt = 15;
> +
> + if (copy_from_user(&buf, ubuf, cnt))
> + return -EFAULT;
> + buf[cnt] = '\0';
> +
> + if (kstrtouint(buf, 10, &scan_size))
> + return -EINVAL;
error code of kstrtouint() includes -ERANGE other than -EINVAL, how
about return the error code directly?

thanks,
Chenyu