Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1436608

Re: kstrtojunk

Path csiph.com!xmission!eternal-september.org!feeder.eternal-september.org!aioe.org!gothmog.csi.it!bofh.it!news.nic.it!robomod
From Alexey Dobriyan <adobriyan@gmail.com>
Newsgroups linux.kernel
Subject Re: kstrtojunk
Date Mon, 04 Jul 2016 23:30:01 +0200
Message-ID <rRjBf-2mL-11@gated-at.bofh.it> (permalink)
References <rQ3oW-528-13@gated-at.bofh.it> <rQ798-7jz-31@gated-at.bofh.it>
X-Original-To Kees Cook <keescook@chromium.org>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=42LSjkGgunKYN8pPbKHLXa3c6OJX8VGOSW+hgI4/ZDc=; b=RmA9isCFvho68nnltKqqbHhVIXYz9fEaYAqh1fqa+3xbt4X6k1h7MfvooGJ9cfTXJc Tol1R9V4XRuWyiH6uz049kuThMBGNSfA0pESQfNPIGS/8tiSZMgX/ntbu1Haaru9q7O9 z6vwsMon5b51sD+OLsNXLhFr0fTC0vHDd48kgQ3kSFVrA8B+QcoIGmLEW9DDDnuVj19d aofAH+FLBTMfkhpJUI6bX6tSP8ekz5F01NHjn34AZqhm4GImULT8QzXWWfFRttsy2+VN VTkZ94d1bURVbO2znf/mLTzp20algfPU6D5+J8n6h71fh6I9uPuaNPSqTZFIysNlXyhr MF2w==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=42LSjkGgunKYN8pPbKHLXa3c6OJX8VGOSW+hgI4/ZDc=; b=QghO5lO7z4CgZLiOJLmXCS17DMp8iupZBlVtUVSM9LqI2cbabGsxvz9mydaxr9Qh7b kEF4FzqWdsF8fGT73dHHhf/vHfSLDKj0CZJ6XeyU5Cm2YK15wFV+CVxCWQlsr+QiF+6F iHrn/xbTwiJPGif2bl1480BGSdX/tZjqahT4X3uL1uqOD0lCItQvYTb9Ab2DO+qL8/QK 8lBV7rFcEOVXpfmxGN0ov95y9E2e0XCcd6Z+hDmKL3Qrpv7PsXdWWyhUNLFvnga5woIs uEFkBC0ZDT3r1T8tLGeLMuYNB2fiiFAVaKI7g8D1ujSGv27dvEm5ICYCZDPjEhrNT6u2 0U4A==
X-Gm-Message-State ALyK8tKGqZ3X00R/CiwNMlud0eoSV1z2wglYsgT+hPUgIMPWPJYvNQlxNMHfKfaeb2e23Q==
X-Received by 10.25.141.75 with SMTP id p72mr2735056lfd.86.1467667593203; Mon, 04 Jul 2016 14:26:33 -0700 (PDT)
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.5.24 (2015-08-30)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 46
Organization linux.* mail to news gateway
X-Original-Cc Andrew Morton <akpm@linux-foundation.org>, Linux Kernel <linux-kernel@vger.kernel.org>
X-Original-Date Tue, 5 Jul 2016 00:26:30 +0300
X-Original-Message-ID <20160704212629.GA20890@p183.telecom.by>
X-Original-References <CACVxJT-yNiWMQyqJR5LjQYkUCdZrzUee0q+jBrpuWR-uaoB-fg@mail.gmail.com> <CAGXu5jKgy4E5oWwU_GC3-CafLDQqAVJ4p1w=W_=9kJ1JaQGJJQ@mail.gmail.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1436608

Show key headers only | View raw


On Fri, Jul 01, 2016 at 09:57:19AM -0400, Kees Cook wrote:
> On Fri, Jul 1, 2016 at 5:53 AM, Alexey Dobriyan <adobriyan@gmail.com> wrote:
> > Could you please stop converting to kstrtobool()?
> >
> > commit a81a5a17d44b26521fb1199f8ccf27f4af337a67
> > Author: Kees Cook <keescook@chromium.org>
> > Date:   Thu Mar 17 14:22:57 2016 -0700
> >
> >     lib: add "on"/"off" support to kstrtobool
> >
> > Especially after doing patches like this?
> >
> > How on earth this was accepted?
> >
> > Now the kernel is supposed to know about every pair of words
> > with the opposite meaning and accept them.
> >
> > If kstrtobool() is ever going to be added it should accept
> > only '0' and '1' characters because kernel is not there
> > to second guess (same logic applies to whitespace trimming
> > for proc/sysfs files).
> >
> > Another point is that in C/C++ any value other than 0
> > is true in for bool but kstrtobool() doesn't accept, say '2'
> > as true. This is why it wasn't added in the first place.
> >
> > It is amazing to see how people think that every 2 common
> > lines of code should be generalized and pushed into lib/.
> 
> There were plenty of common use-cases of the 0/1/no/yes/off/on usage.

The mistake was to allow y/n/Y/N/yes/no/on/off in the first place.
Supporting anything but 0/1 by core code legitimizes those usages.
But since y/n/Y/N/... can't be removed, it is a mistake to move them
to core code, let it rot.

> I was specifically asked to use a common function, and this seemed
> like the cleanest approach. kstrtobool already took y/n, and hasn't
> ever handled "2" to mean "true", and is clearly documented. There's no
> reason it couldn't be adjusted to do that, though.

Other things:
* "!s" check, other functions don't do that,
* doesn't handle \n,
* can't spell "off" right,
* no tests,

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

kstrtojunk Alexey Dobriyan <adobriyan@gmail.com> - 2016-07-01 12:00 +0200
  Re: kstrtojunk Kees Cook <keescook@chromium.org> - 2016-07-01 16:00 +0200
    Re: kstrtojunk Alexey Dobriyan <adobriyan@gmail.com> - 2016-07-04 23:30 +0200

csiph-web