From patchwork Tue Apr 26 18:02:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagdish Gediya X-Patchwork-Id: 12827694 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 07D07C433F5 for ; Tue, 26 Apr 2022 18:02:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C8B46B0073; Tue, 26 Apr 2022 14:02:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7776A6B0074; Tue, 26 Apr 2022 14:02:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F0E36B0078; Tue, 26 Apr 2022 14:02:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 4F7196B0073 for ; Tue, 26 Apr 2022 14:02:43 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 29E36120D33 for ; Tue, 26 Apr 2022 18:02:43 +0000 (UTC) X-FDA: 79399800606.23.F833971 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf08.hostedemail.com (Postfix) with ESMTP id 87F3B160046 for ; Tue, 26 Apr 2022 18:02:36 +0000 (UTC) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 23QGhSx6013516; Tue, 26 Apr 2022 18:02:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=+iKxtjbBize+7FxPvSlI7lCl5sC17EfaqBFmnZDb4nY=; b=diA2FIo15pkTixgnHW6wQxN8SNUlGL86t21KBga70E1htrApin6PuU/hvfjwfOKAPQOu 3eHdT7kkyJZWvKqTHS3nFtq7b9cBo/M6CaipEel9pjid787biP2mDXknMYyTSvKYfIHC jHMODrW00Kv/vnwc3QSmZQrmekm17uoUIZLPSGVlPlPWhnQb3pst/WaFEcb2N50ColMc 8vn2GfwnxUKapSnwWYCgQClNISrLZSL1gMdV3DvoGT8BJQ1EUP25R5+MDBFcUAY+8V5y LJ3xVZABGpmCtmHmYT6jHpfSlksmjfL16d6KHpZtMJbOfPLHVIHa9R2v1IPsAnaXxTXM rg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3fpj9rmwav-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Apr 2022 18:02:17 +0000 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 23QHokM9004047; Tue, 26 Apr 2022 18:02:17 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3fpj9rmw9p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Apr 2022 18:02:17 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23QHx9ei010471; Tue, 26 Apr 2022 18:02:14 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03ams.nl.ibm.com with ESMTP id 3fm938vs6y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Apr 2022 18:02:14 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23QI2C9x58982832 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Apr 2022 18:02:12 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3C92DAE051; Tue, 26 Apr 2022 18:02:12 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E938AAE045; Tue, 26 Apr 2022 18:02:07 +0000 (GMT) Received: from li-6e1fa1cc-351b-11b2-a85c-b897023bb5f3.ibm.com.com (unknown [9.43.119.104]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 26 Apr 2022 18:02:07 +0000 (GMT) From: Jagdish Gediya To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: willy@infradead.org, ying.huang@intel.com, dave.hansen@intel.com, Jonathan.Cameron@huawei.com, adobriyan@gmail.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, rf@opensource.cirrus.com, pmladek@suse.com, Jagdish Gediya Subject: [PATCH v3 1/2] lib/kstrtox.c: Add "false"/"true" support to kstrtobool() Date: Tue, 26 Apr 2022 23:32:02 +0530 Message-Id: <20220426180203.70782-1-jvgediya@linux.ibm.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 5tLog6bKdJuMqYCBHq6hi2V1b8ShjwCE X-Proofpoint-ORIG-GUID: Iqhq7bIJmgmGZ1M2ZP_P4ywfi-dB0c6f X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-26_05,2022-04-26_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 phishscore=0 impostorscore=0 clxscore=1011 adultscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204260115 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 87F3B160046 X-Stat-Signature: fj8x1wftn1wtraq5epj5s84yf6th68f5 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=diA2FIo1; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf08.hostedemail.com: domain of jvgediya@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=jvgediya@linux.ibm.com X-Rspam-User: X-HE-Tag: 1650996156-770044 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: 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 it doesn't have support to accept "false"/"true". Add support to accept "false"/"true" as valid string in kstrtobool(). Signed-off-by: Jagdish Gediya Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Andy Shevchenko --- Chnages in v2: - kstrtobool to kstrtobool() in commit message. - Split single patch into 2 - Remove strcmp usage from kstrtobool() and instead compare 1st character only. Changes in v3: - Covert -> Convert in patch 2 subject - Collected Reviewed-by: Matthew Wilcox (Oracle) lib/kstrtox.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/kstrtox.c b/lib/kstrtox.c index 886510d248e5..465e31e4d70d 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c @@ -340,7 +340,7 @@ EXPORT_SYMBOL(kstrtos8); * @s: input string * @res: result * - * This routine returns 0 iff the first character is one of 'Yy1Nn0', or + * This routine returns 0 if the first character is one of 'YyTt1NnFf0', or * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL. Value * pointed to by res is updated upon finding a match. */ @@ -353,11 +353,15 @@ int kstrtobool(const char *s, bool *res) switch (s[0]) { case 'y': case 'Y': + case 't': + case 'T': case '1': *res = true; return 0; case 'n': case 'N': + case 'f': + case 'F': case '0': *res = false; return 0;