Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp3854419ioa; Tue, 26 Apr 2022 11:03:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTEmwz2nAZa+fHTWM8Wv/89KnO/j/8NOdjKi8m8XM+wDPDFMBKNc0ejhiUqsB6h5C3dNsF X-Received: by 2002:a63:de53:0:b0:3aa:8b0:b690 with SMTP id y19-20020a63de53000000b003aa08b0b690mr20941109pgi.580.1650996184994; Tue, 26 Apr 2022 11:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650996184; cv=none; d=google.com; s=arc-20160816; b=XL0siX2Zv7MoVD00Rq4P9b3IfZ6skWrAwIDXkbTn0kbC/vgBddUSlSU9qS3SfuZqru LJkcNEm1pwMkLtZg7O1HDRHdZyBP/ldmVCflDTexYAbx5rG25VruEBerN/a6hrHA1cri w1V6PGvEcIOjUyu+9ZQcW0SiXwh5i3srPEcSvPu7MmgMqcE1sa6B4oHrn5zRTaxvbkoB q/TSVCA6gdSRBHas0oE8mU3R5MLat63SS2V0ECiqrVvPHWCPv/lKcH3i+kdIh4ut50Lv pIRh0IHQY8woOz5u+I3gVtJHCwh4fCJ9lFQ+cM+dPQbucjPaA29rMSBzueR54DskJz+P wJLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/7V6avl/Taxkxq9jRUXbRTBaIMWYoELnXIpQtCKh1xI=; b=l6m51sjPnRJLXvPQes6LE5H2y0hucP+OMz5w8Hx2syTJxbkCGssdmvRlNGakTlMhUS xw3UH9v4w3cTF5i38C+wpTxWbJ4vKcCry4I11Ayu5HIehWM6Sw89mw1TjvFcld6IUiNO 6jt+7JQA4n/fNPVrV6rGhv/xeGrQeum+0f4UXQaxw3SUN2uP1ijvyjtoxkYvhTZ9Ozd0 WLjeSUXKS7hRzpXYhBq87LP4Wf5hx7Xe5tloN3YNmg6eZN9k+7RK+iUq78tF3uVAc4cK GP+b7b6f8TXVnMMLMWpa4ThUt/a5wimjB0uMwuWCP8NUyqRDez8EuGXGN+yr8XplWTBe tM3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=j1ldpkIh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f6-20020a056a0022c600b005087123810dsi20891013pfj.363.2022.04.26.11.02.49; Tue, 26 Apr 2022 11:03:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=j1ldpkIh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348598AbiDZKRE (ORCPT + 99 others); Tue, 26 Apr 2022 06:17:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348217AbiDZKQm (ORCPT ); Tue, 26 Apr 2022 06:16:42 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96CFD43EE5 for ; Tue, 26 Apr 2022 02:39:59 -0700 (PDT) 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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