Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/xmon: use match_string() helper

match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Yisheng Xie and committed by
Michael Ellerman
0abbf2bf 2479bfc9

+11 -12
+11 -12
arch/powerpc/xmon/xmon.c
··· 3173 3173 } 3174 3174 3175 3175 #define N_PTREGS 44 3176 - static char *regnames[N_PTREGS] = { 3176 + static const char *regnames[N_PTREGS] = { 3177 3177 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 3178 3178 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 3179 3179 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", ··· 3208 3208 regname[i] = c; 3209 3209 } 3210 3210 regname[i] = 0; 3211 - for (i = 0; i < N_PTREGS; ++i) { 3212 - if (strcmp(regnames[i], regname) == 0) { 3213 - if (xmon_regs == NULL) { 3214 - printf("regs not available\n"); 3215 - return 0; 3216 - } 3217 - *vp = ((unsigned long *)xmon_regs)[i]; 3218 - return 1; 3219 - } 3211 + i = match_string(regnames, N_PTREGS, regname); 3212 + if (i < 0) { 3213 + printf("invalid register name '%%%s'\n", regname); 3214 + return 0; 3220 3215 } 3221 - printf("invalid register name '%%%s'\n", regname); 3222 - return 0; 3216 + if (xmon_regs == NULL) { 3217 + printf("regs not available\n"); 3218 + return 0; 3219 + } 3220 + *vp = ((unsigned long *)xmon_regs)[i]; 3221 + return 1; 3223 3222 } 3224 3223 3225 3224 /* skip leading "0x" if any */