From patchwork Sat Sep 15 05:12:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhong jiang X-Patchwork-Id: 10601395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4503161F for ; Sat, 15 Sep 2018 05:25:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B96262B5F7 for ; Sat, 15 Sep 2018 05:25:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD6472B611; Sat, 15 Sep 2018 05:25:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 260862B5F7 for ; Sat, 15 Sep 2018 05:25:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4339C8E0002; Sat, 15 Sep 2018 01:25:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3E3858E0001; Sat, 15 Sep 2018 01:25:07 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F9098E0002; Sat, 15 Sep 2018 01:25:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f70.google.com (mail-oi0-f70.google.com [209.85.218.70]) by kanga.kvack.org (Postfix) with ESMTP id 0A51C8E0001 for ; Sat, 15 Sep 2018 01:25:07 -0400 (EDT) Received: by mail-oi0-f70.google.com with SMTP id 20-v6so11813235ois.21 for ; Fri, 14 Sep 2018 22:25:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:mime-version; bh=PHQkmVIUnlKqsyC+nRjuGEQPraUqZHPstiHeZFYMp5g=; b=pB84bJLTBVlCNypi2licz+q1qSCM+neV3up4KzoUK9W5jSSZUMq2QnIk72OW3zCtfc ZIcNPoWY43UctJd1C1FU+O964XzfURe/7mnmQ3/fnWPEMYCIOQjxkY5/M95RjIsNvYdi y+TbuEBagKqwrV9lpSGhcEubA0f1N+IuqaNylnnm3cmPSRq8GbolOmpNj3UtTtUkeh2C IkGq1BRvXmsNrxTGMSHlBAyLaSgzlHf2e4Hj9K9d52d8LttiPjEZBrm6UZy3O3Rvgxru Cvfww5Jp2WU9CpUAfrGHt67vyjYrYtUHHZUe5CUbvP98jYvKVkLPWmSUWuJM+euXv2kv K5SQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of zhongjiang@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=zhongjiang@huawei.com X-Gm-Message-State: APzg51B738Kc670L/M1Uj18xWzuU5XjO4RkkUnVID1Oa4FMLTkvKURpE wCcts8fXoXBWxt5BmD7681w1V8OSU9lwJ7NR4VDR1GGZ93egd8uSHOYG2pQKJK3EtOIpgNaqmtu FwpOgID5gmN7rwYEmAJOF13ihNDmf27uBV9n426f4Ynk9L/G5n1idUEphMw6XP197wg== X-Received: by 2002:a9d:2aaa:: with SMTP id e39-v6mr6343743otb.381.1536989106779; Fri, 14 Sep 2018 22:25:06 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYVk9dQEH4BQ2DVuj7NBhjfPdfTazUwktIp3SqYeG1TYvjnm2LpAhpqgqtKd6AHRsrpQw1V X-Received: by 2002:a9d:2aaa:: with SMTP id e39-v6mr6343718otb.381.1536989105939; Fri, 14 Sep 2018 22:25:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536989105; cv=none; d=google.com; s=arc-20160816; b=NcXMteUtWp3ZwWB5ymf2LmTDXZBd/3tuZDRTkXFyS8mlyzFy+Mu5OD0U8hE9ggt9LI PUYbzqk1zvxCMJTULVP/qsBx5ePQMX4VUEGViB3YLOsRxnVaSe8AI+lYXkyZrYy7LHEn RzCouoeMtNzo/7VfK8BJO9s1ECOLqPl1zKjVGV+HJipGLk6qfdyVbsvTCyBqTokd5vLP JAz0lchbNcWJ39oHaP6wmObnw108OGgkefivP50sLnm/P5XM2AUdR7sShvl9BaqHZTSe PicHCsJuqW56csJsIdx5A6ux8RwNbh085R910gqPOeCg7i1HNtJKsHq8cTxGeul6Yvo/ SC7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:date:subject:cc:to:from; bh=PHQkmVIUnlKqsyC+nRjuGEQPraUqZHPstiHeZFYMp5g=; b=rueKldAIvD4pWEAIAvXOYJ33n/XWXbkneBBhtCcSWXpowhWiAqrEr9jAOxflPkan2O Uv9oHKHmEy6ozvJpWprpYfySR3u4r0ikv9u3s6FRwNOKq+TQzNQ8Lt102liNu4IrmleT VNQxXKncV0guBvZWnlwYBWEE/jKNbMEnOxjEFbhRGbN8zHkvCcE+fiRXeG3AH9IOzrix 3ohpnpr9+MKVm75LvsbVuO+oXP6HcFc8I2wQVh6xEXLZ4FJ5bHNQ7at8hkLTer2VlCbl PTtmmT8n+l7lXK4uJz+qTy9byDzNR0nzmEX9pVPpjAoCHl8Ng500zS3Pcu3b1zkrxdDa Ad3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of zhongjiang@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=zhongjiang@huawei.com Received: from huawei.com (szxga06-in.huawei.com. [45.249.212.32]) by mx.google.com with ESMTPS id x143-v6si4386104oia.376.2018.09.14.22.25.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 22:25:05 -0700 (PDT) Received-SPF: pass (google.com: domain of zhongjiang@huawei.com designates 45.249.212.32 as permitted sender) client-ip=45.249.212.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of zhongjiang@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=zhongjiang@huawei.com Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 8DE5F1D02826D; Sat, 15 Sep 2018 13:25:01 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.399.0; Sat, 15 Sep 2018 13:25:02 +0800 From: zhong jiang To: CC: , , , , , Subject: [PATCH] mm: use match_string() helper to simplify the code Date: Sat, 15 Sep 2018 13:12:45 +0800 Message-ID: <1536988365-50310-1-git-send-email-zhongjiang@huawei.com> X-Mailer: git-send-email 1.7.12.4 MIME-Version: 1.0 X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected 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: X-Virus-Scanned: ClamAV using ClamSMTP match_string() returns the index of an array for a matching string, which can be used intead of open coded implementation. Signed-off-by: zhong jiang --- mm/mempolicy.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 2e76a8f..cfd26d7 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2711,12 +2711,11 @@ void numa_default_policy(void) int mpol_parse_str(char *str, struct mempolicy **mpol) { struct mempolicy *new = NULL; - unsigned short mode; unsigned short mode_flags; nodemask_t nodes; char *nodelist = strchr(str, ':'); char *flags = strchr(str, '='); - int err = 1; + int err = 1, mode; if (nodelist) { /* NUL-terminate mode or flags string */ @@ -2731,12 +2730,8 @@ int mpol_parse_str(char *str, struct mempolicy **mpol) if (flags) *flags++ = '\0'; /* terminate mode string */ - for (mode = 0; mode < MPOL_MAX; mode++) { - if (!strcmp(str, policy_modes[mode])) { - break; - } - } - if (mode >= MPOL_MAX) + mode = match_string(policy_modes, MPOL_MAX, str); + if (mode < 0) goto out; switch (mode) {