From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6791CC433EF for ; Tue, 26 Apr 2022 09:40:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E91646B0073; Tue, 26 Apr 2022 05:39:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E41436B0074; Tue, 26 Apr 2022 05:39:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D30F26B0075; Tue, 26 Apr 2022 05:39:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id C4D036B0073 for ; Tue, 26 Apr 2022 05:39:59 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9986560DB1 for ; Tue, 26 Apr 2022 09:39:59 +0000 (UTC) X-FDA: 79398533718.24.783B3C0 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf19.hostedemail.com (Postfix) with ESMTP id 6D9D11A0041 for ; Tue, 26 Apr 2022 09:39:55 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id B996C1F380; Tue, 26 Apr 2022 09:39:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1650965997; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/7V6avl/Taxkxq9jRUXbRTBaIMWYoELnXIpQtCKh1xI=; b=j1ldpkIhJCSJFnZt/VETy+Zd9UALftvtxyqHAOOUipcj7XN2FG5mgWRrWgxXhzrWbiYOKL 7BuXdDafAVudfJwpG+zpskDCIwJO36oSu6qMrKKowJwLwOvbutrSW35E3euNoAwqIMaWlO TfAYckKO9tgV9q+Jh7nu2kq54SjyTuY= Received: from suse.cz (unknown [10.100.224.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 7AC552C1EC; Tue, 26 Apr 2022 09:39:57 +0000 (UTC) Date: Tue, 26 Apr 2022 11:39:57 +0200 From: Petr Mladek To: Jagdish Gediya Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, ying.huang@intel.com, dave.hansen@intel.com, Andrew Morton , Andy Shevchenko , Richard Fitzgerald Subject: Re: [PATCH v2] lib/kstrtox.c: Add "false"/"true" support to kstrtobool Message-ID: References: <20220426064001.14241-1-jvgediya@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220426064001.14241-1-jvgediya@linux.ibm.com> X-Rspamd-Queue-Id: 6D9D11A0041 X-Stat-Signature: 6fxurftjk5yx59sr3s91i8kqs59z6kq3 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=j1ldpkIh; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf19.hostedemail.com: domain of pmladek@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=pmladek@suse.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1650965995-539126 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue 2022-04-26 12:10:01, Jagdish Gediya wrote: > At many places in kernel, It is necessary to convert sysfs input > to corrosponding bool value e.g. "false" or "0" need to be converted > to bool false, "true" or "1" need to be converted to bool true, > places where such conversion is needed currently check the input > string manually, kstrtobool can be utilized at such places but > currently kstrtobool doesn't have support to "false"/"true". > > Add "false"/"true" support to kstrtobool while string conversion > to bool. Modify existing manual sysfs conversions to use kstrtobool(). It looks reasonable. I would just do it slightly other way, see below. > This patch doesn't have any functionality change. This is not true. All kstrtobool() callers will react differently on the "true"/"false" input. > Cc: Andrew Morton > Cc: Andy Shevchenko > Cc: Richard Fitzgerald > Cc: Petr Mladek > Signed-off-by: Jagdish Gediya > --- > change in v2: > Modified kstrtobool to handle "false"/"true". Removed > new function sysfs_strbool introduced in v1. > > lib/kstrtox.c | 7 +++++++ > mm/migrate.c | 6 +----- > mm/swap_state.c | 6 +----- > 3 files changed, 9 insertions(+), 10 deletions(-) > > diff --git a/lib/kstrtox.c b/lib/kstrtox.c > index 886510d248e5..3a5e29557838 100644 > --- a/lib/kstrtox.c > +++ b/lib/kstrtox.c > @@ -377,6 +377,13 @@ int kstrtobool(const char *s, bool *res) > } > break; > default: > + if (!strncmp(s, "true", 4)) { > + *res = true; > + return 0; > + } else if (!strncmp(s, "false", 5)) { > + *res = false; > + return 0; It should be enough to check the first letter like we do in the other cases. I mean to set true when s[0] is 'T' or 't' and false when s[0] is 'F' or 'f'. Also please update comment above the function definition. > + } > break; > } > Best Regards, Petr