Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp496061imm; Thu, 31 May 2018 04:29:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKPEiWw12qbh1QII8QcrltsfF2W1ZSupUwGpL1MFNpOisGA1jY99NYqn7w+fvwCuwK61LA5 X-Received: by 2002:a17:902:d90f:: with SMTP id c15-v6mr6577569plz.65.1527766167535; Thu, 31 May 2018 04:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527766167; cv=none; d=google.com; s=arc-20160816; b=XvPukr7ljEEXP6mWmFGuOfsDRMMs86CT32YoVV5i/UXzh9MqBPy6Gf8O0jgLgi4cvq 6NclXqamRBRrrEBbpx4aDKpcTeHnjJ4zQukI+myXx3H2Z1bl7VkPnNt8oj2HoRDeZr7t BtaEOjkto3tSPlOYca8FHbxy1Kw7SRep6M4yoYc6s7YTw1j0HenoK6tXtCSG40iuWFdN BDxqNfgA70C7gJLLhZXd3Bl730ww9HeFq26wPOBGSiqU6qTXTCs62b6dFKY8r4jdKose t0RDBSqgUqKqRunFmd8oznu4VivcXoUq6RXAQiNDf/86+PblBkpK/UVTAhMLXgrx/vxp LZGg== 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=mN6Fq+a/sY7xpABa/i9dqGNrCh1DoaAZTduQwSISDXA=; b=eqLA4vDURiZ2xvNv+PxJaPGiJNrI/PNByg5LT6kZIvbXtmJCAaykiKfVIUfkch5EVk CrBKXgiwQ3DONxj/KRFPw6PgQ7L3iE/hF1GBNI2/9txH62t65FpHRe+/b5Kl+68UVWX/ 2kdGjYRuvAGzfehCzDa77L6oz88efwuweMQcUStb+iKNwxnp+Qhlkcp70Zck55cS7WXB 1x2uvAVdJPf3/mcs33IKRssyaTllbvcs1S7BzjQEmdz/qIS9J0jwXZ3YBYFP2XTKu+Qc Rw/tD26z9bOXWR0DRjn0bxlTrNYWF/uNvFvOXl/QrAOHhSjQtptbyOEWOg4qS55GbRsi XCUg== 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 f21-v6si8264953pfh.33.2018.05.31.04.29.13; Thu, 31 May 2018 04:29:27 -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 S1754938AbeEaL1B (ORCPT + 99 others); Thu, 31 May 2018 07:27:01 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8225 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754571AbeEaLWl (ORCPT ); Thu, 31 May 2018 07:22:41 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 0B220209CD4F; Thu, 31 May 2018 19:22:25 +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:18 +0800 From: Yisheng Xie To: CC: , Yisheng Xie , "Greg Kroah-Hartman" , Quytelda Kahja , Subject: [PATCH v2 03/21] Staging: gdm724x: use match_string() helper Date: Thu, 31 May 2018 19:11:08 +0800 Message-ID: <1527765086-19873-4-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: Greg Kroah-Hartman Cc: Quytelda Kahja Cc: devel@driverdev.osuosl.org Signed-off-by: Yisheng Xie --- 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..397ecaa 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 || tty->index == GDM_TTY_MINOR) 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