Re: [PATCH] sysctl: handle table->maxlen properly for proc_dobool

From: Matthew Wilcox
Date: Thu May 19 2022 - 09:09:12 EST


On Thu, May 19, 2022 at 08:55:05PM +0800, Muchun Song wrote:
> @@ -428,6 +428,8 @@ static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp,
> int write, void *data)
> {
> if (write) {
> + if (*negp || (*lvalp != 0 && *lvalp != 1))
> + return -EINVAL;
> *(bool *)valp = *lvalp;
> } else {
> int val = *(bool *)valp;

Is this the right approach? Or should we do as C does and interpret
writing non-zero as true? ie:

*(bool *)valp = (bool)*lvalp;

(is that cast needed? It wouldn't be if it were an int, but bool is a
bit weird)