[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAMZfGtWw0Jm0fr=m38djPtCpTkVPvqku5vjCmOmGgDtOHZn9Aw@mail.gmail.com>
Date: Thu, 19 May 2022 22:10:54 +0800
From: Muchun Song <songmuchun@...edance.com>
To: Matthew Wilcox <willy@...radead.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
Xiongchun duan <duanxiongchun@...edance.com>,
Muchun Song <smuchun@...il.com>,
Luis Chamberlain <mcgrof@...nel.org>,
Kees Cook <keescook@...omium.org>,
Iurii Zaikin <yzaikin@...gle.com>
Subject: Re: [PATCH] sysctl: handle table->maxlen properly for proc_dobool
On Thu, May 19, 2022 at 9:09 PM Matthew Wilcox <willy@...radead.org> wrote:
>
> 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:
All right. We could obey the C rule here.
>
> *(bool *)valp = (bool)*lvalp;
>
> (is that cast needed? It wouldn't be if it were an int, but bool is a
> bit weird)
>
If the cast is weird. How about:
*(bool *)valp = *lvalp ? true : false;
Thanks.
Powered by blists - more mailing lists