Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp227308imm; Mon, 21 May 2018 05:12:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqUXVSPdhqpygtWWa2qMa40tgnMOhqc0u5XFk+xL21iWsbIJvC/J/bWQqAW+ZszNzQ3KUOQ X-Received: by 2002:a17:902:2804:: with SMTP id e4-v6mr20061685plb.153.1526904772409; Mon, 21 May 2018 05:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526904772; cv=none; d=google.com; s=arc-20160816; b=j12nQlHVl/ylMg9WTu8voTVgCccuom/3w59BXrVk5BnitGAFq8lbBYYJ3ccbBkrpd1 9CURKgKlQJzbOw7fvWKwoVE3ias5Ik4LEK3Mhdk31FGVlDhf45nAWoD8RF3riIrdYzHy T/ZxPjI3Vvu7ZIc/4ha3lupXdnXi6wjoEi52EmYOA/MVAw3N3zr6PWpwMwu3UCPEH3cJ gWC/QWoGN+q5l1PP0ghHtcEnvQC5haMIqjwD1OgVpfrzxGExfQMDkCRnrQgDmUrx8xVI r1iYLqaufIdc8cG9oI3Rg1K65qBN2PKJYoVz1vSQU3AcsAsJ5Uv8bBkUTQ85gmZlctqI geYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=Bi01YA1TQCZQe+YW0vzba9XhJtZON5GDtMc8P1Le04A=; b=I9MwcZ15xAMmWjfIRqkgBH6+dQWE9cgkHtVYH2dEuN30SZFKdZ+oVIIg1AWdO9HVFg D4jzHfqG4v4qBX9lcYG2qaBAyMaVb2ko8qH+Ow+TQ6F7hMbh3R3x2m9evwshGJtumq22 zdqDTvhKfuNtAaOlzXXkJ30O1B2EOmpp/DaJlMQw82vuc5DngGM2E03tW6zgSDcK7vnI JbDp4TrBOt7GPcGBTEYVONd0XOlQQ1As+bI23l4FXy+qHeZsFD3zwDHGKyNsAF0cYJpn lBw2q42X1Cl8j66pLBCCF3E0toTHkBa/IoS922KE59asGY/o2i7T+1mtwIovUjKlIYR5 8rBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e8-v6si11005588pgq.173.2018.05.21.05.12.37; Mon, 21 May 2018 05:12:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753051AbeEUMJ3 (ORCPT + 99 others); Mon, 21 May 2018 08:09:29 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:38665 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751614AbeEUMJF (ORCPT ); Mon, 21 May 2018 08:09:05 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 432A27266C87D; Mon, 21 May 2018 20:09:01 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.382.0; Mon, 21 May 2018 20:08:55 +0800 From: Yisheng Xie To: CC: Yisheng Xie , Srinivas Pandruvada , Len Brown , "Rafael J. Wysocki" , Viresh Kumar , Subject: [PATCH 15/33] cpufreq: intel_pstate: use match_string() helper Date: Mon, 21 May 2018 19:57:52 +0800 Message-ID: <1526903890-35761-16-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com> References: <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org match_string() returns the index of an array for a matching string, which can be used intead of open coded variant. Cc: Srinivas Pandruvada Cc: Len Brown Cc: "Rafael J. Wysocki" Cc: Viresh Kumar Cc: linux-pm@vger.kernel.org Signed-off-by: Yisheng Xie --- drivers/cpufreq/intel_pstate.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 17e566af..d701e26 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -645,21 +645,18 @@ static ssize_t store_energy_performance_preference( { struct cpudata *cpu_data = all_cpu_data[policy->cpu]; char str_preference[21]; - int ret, i = 0; + int ret; ret = sscanf(buf, "%20s", str_preference); if (ret != 1) return -EINVAL; - while (energy_perf_strings[i] != NULL) { - if (!strcmp(str_preference, energy_perf_strings[i])) { - intel_pstate_set_energy_pref_index(cpu_data, i); - return count; - } - ++i; - } + ret = match_string(energy_perf_strings, -1, str_preference); + if (ret < 0) + return ret; - return -EINVAL; + intel_pstate_set_energy_pref_index(cpu_data, ret); + return count; } static ssize_t show_energy_performance_preference( -- 1.7.12.4