Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp491487imm; Thu, 31 May 2018 04:23:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKQPO6Q9q3+SEMq/0H3US8OvtPk8fLR7QpDZDZD/2FAX8aUsrs3TNsO+kufbigeP4MLiUNX X-Received: by 2002:a17:902:3381:: with SMTP id b1-v6mr6610018plc.248.1527765835622; Thu, 31 May 2018 04:23:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527765835; cv=none; d=google.com; s=arc-20160816; b=a7KGP+LzYeslCH0iouVd99C0YryOAlxbo8t3FsmgN8fg8KJoD02iTkKVL5rqoZEl/P xbqPknEItBxXg424CBgeFhC/vI2UV37fCFQkzftK1Sy39iS4nT53l6G/OH1P3GL1fESA gvn6JXl3rYxk5ioy7aKvGq9iY/v2DyCa1O+LI3X7qF9WCWMTkwQrZmrxZBWQuNEETkHA Di0fUO7wwNjzJfGSEytjxRXjHIQR9pW8hMDxu02v1sn5za4GToRDZfO2j2sRP61Ovmfs DpNDRRP1meujsB7HCdMg7DUJD1e4Dpgm61f1Haa2Otl82Qs49oUWoh6E7+6KqdRC3SYy swKw== 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=FtDkoVRrqBdp+jejH5L7BYtQ6HyjrOe9SPETsEa+jzY=; b=KmwqF5u2p2ishE9N6BcIjv4S/yZdXma6DI78Cy1QIg8l64xee/WlzNaeYbLYkAGOVA DSFSPx0zYYN40WIIvLrLBEqU1f+ldi23+MVJ7SASw07KEqWPLiLa6kCPX6cHLCYwSDKU AzGqPeWP/g2+pv8JQgWfaK2vszn0/LSKtxsdHz/IAo++JZAHkOjSF6ARrW/qZ+2+Ub00 RMaomF3pqYMkLKmiUSXgkBT6DmWO0jR/R4faG5Cl//e7n4I+UIM9UiLqVXAWnXln1Gx8 GfTTHtiTRlkcd6i5BZ1YInKpteOZWPv+bCVey4bvhOlLJ7CMCtnRiQRJKE8ptyQGbdde x1cw== 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 r10-v6si26736849pgp.363.2018.05.31.04.23.41; Thu, 31 May 2018 04:23:55 -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 S1754882AbeEaLXD (ORCPT + 99 others); Thu, 31 May 2018 07:23:03 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:8175 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754856AbeEaLWx (ORCPT ); Thu, 31 May 2018 07:22:53 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 70C6B5215B58E; Thu, 31 May 2018 19:22:35 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 19:22:29 +0800 From: Yisheng Xie To: CC: , Yisheng Xie , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Subject: [PATCH v2 20/21] powerpc/xmon: use match_string() helper Date: Thu, 31 May 2018 19:11:25 +0800 Message-ID: <1527765086-19873-21-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1527765086-19873-1-git-send-email-xieyisheng1@huawei.com> References: <1527765086-19873-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 instead of open coded variant. Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Yisheng Xie --- arch/powerpc/xmon/xmon.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c index a0842f1..872ac8c 100644 --- a/arch/powerpc/xmon/xmon.c +++ b/arch/powerpc/xmon/xmon.c @@ -3161,7 +3161,7 @@ static void proccall(void) } #define N_PTREGS 44 -static char *regnames[N_PTREGS] = { +static const char *regnames[N_PTREGS] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", @@ -3196,18 +3196,17 @@ static void proccall(void) regname[i] = c; } regname[i] = 0; - for (i = 0; i < N_PTREGS; ++i) { - if (strcmp(regnames[i], regname) == 0) { - if (xmon_regs == NULL) { - printf("regs not available\n"); - return 0; - } - *vp = ((unsigned long *)xmon_regs)[i]; - return 1; - } + i = match_string(regnames, N_PTREGS, regname); + if (i < 0) { + printf("invalid register name '%%%s'\n", regname); + return 0; } - printf("invalid register name '%%%s'\n", regname); - return 0; + if (xmon_regs == NULL) { + printf("regs not available\n"); + return 0; + } + *vp = ((unsigned long *)xmon_regs)[i]; + return 1; } /* skip leading "0x" if any */ -- 1.7.12.4