Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp261089imm; Tue, 5 Jun 2018 19:25:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJq2Gx2WWTR2a7pWPNYD3v76FqdLHI4rUEQ2yrvpi3sDpj5ppG2ePruDzPdPt18RRBm8s1w X-Received: by 2002:a17:902:ba97:: with SMTP id k23-v6mr1205973pls.259.1528251902662; Tue, 05 Jun 2018 19:25:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528251902; cv=none; d=google.com; s=arc-20160816; b=OKYg9BHv+Pv0/i9Y6WgD/c5my8X2iKbHhLHz4CmX7MIQNKfkF6GxwR6E0noyab1Go+ AIuBHDAtutgLFY6Kmci4kjyBv881HXNYflQmV4FENU0B8HKWPwCTQPoFoHYKKIcQudiC oWIfF//yWpsG5VGv8lHPb5/7whlJ5VAWUByiUnG6ApjfUwYF3C9JTQI+0Rb7BYJyrhM9 wzWBcOrfQ27t5AKy1HnHEdteFHhIt6p2TZDAAxG4iF+vxgt69KVIXXp0naQ0pv9jjYH/ NrmvwJBDoFwCnFHzyBMrA/JVN0gndbK8do4ITLnwkkVbXthzWjNha5DEopkaaJ7a/1RX wwMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=pnMzhG5m6QCCn/XtytHzWw8WbiM6c6mFU37BFYoOmYo=; b=csoYppCWBnjHsNQ3FjoF/6o04Kz/+A2Rex97mZ3ifqtDA0g9skDPhXipVykTyLSw6r OuBXxGOLSLSuIboeVIzNvI+7Kl+d80LuiinMk+MnWJoiwVMVG/ACsr4oiHHamEWCfwe+ aRNBIt8upnyJuaGkbM4eHDRq5pVXQpF7bMvmPlYmzxVFeQjyykIQOF6BL2Er7DsXNDnL tKyQUjqDv8cbwM95iiYn3PlpsczTcA48xnoz4uO7sajx+Owmj+ykF0Ca1J4fuIFdzSML nMycDoHPJgFaH/V0yZ6CZl0C5GYOTM0grkLS5z10enbqXzG/y/yAMv+FAG8WqJO5TJaD 89Vg== 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 r28-v6si22058517pgu.408.2018.06.05.19.24.47; Tue, 05 Jun 2018 19:25:02 -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 S1752755AbeFFCYU (ORCPT + 99 others); Tue, 5 Jun 2018 22:24:20 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8699 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752424AbeFFCYT (ORCPT ); Tue, 5 Jun 2018 22:24:19 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9A1BA50217339; Wed, 6 Jun 2018 10:24:06 +0800 (CST) Received: from [127.0.0.1] (10.177.29.40) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.382.0; Wed, 6 Jun 2018 10:23:59 +0800 Subject: [PATCH v3 03/21] Staging: gdm724x: use match_string() helper To: References: <1527765086-19873-1-git-send-email-xieyisheng1@huawei.com> <1527765086-19873-4-git-send-email-xieyisheng1@huawei.com> CC: , Greg Kroah-Hartman , Quytelda Kahja , , Kefeng Wang From: Yisheng Xie Message-ID: <643c3ad1-55c0-4ad6-7305-4938b1280be6@huawei.com> Date: Wed, 6 Jun 2018 10:21:11 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <1527765086-19873-4-git-send-email-xieyisheng1@huawei.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.29.40] 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: Greg Kroah-Hartman Cc: Quytelda Kahja Cc: devel@driverdev.osuosl.org Signed-off-by: Yisheng Xie --- v3: - no need to check input tty's index - per Greg v2: - const DRIVER_STRING instead - per Andy drivers/staging/gdm724x/gdm_tty.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c index 3cdebb8..29ac6b5 100644 --- a/drivers/staging/gdm724x/gdm_tty.c +++ b/drivers/staging/gdm724x/gdm_tty.c @@ -43,7 +43,7 @@ static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR]; static DEFINE_MUTEX(gdm_table_lock); -static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"}; +static const char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"}; static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"}; static void gdm_port_destruct(struct tty_port *port) @@ -65,22 +65,14 @@ static int gdm_tty_install(struct tty_driver *driver, struct tty_struct *tty) { struct gdm *gdm = NULL; int ret; - int i; - int j; - - j = GDM_TTY_MINOR; - for (i = 0; i < TTY_MAX_COUNT; i++) { - if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) { - j = tty->index; - break; - } - } - if (j == GDM_TTY_MINOR) + ret = match_string(DRIVER_STRING, TTY_MAX_COUNT, + tty->driver->driver_name); + if (ret < 0) return -ENODEV; mutex_lock(&gdm_table_lock); - gdm = gdm_table[i][j]; + gdm = gdm_table[ret][tty->index]; if (!gdm) { mutex_unlock(&gdm_table_lock); return -ENODEV; -- 1.7.12.4