Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp538355imm; Thu, 31 May 2018 05:15:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJntsP//65kHRSj1k9F8ZM8I1yYHpPybMIa1YsWRcL1GP5e65U3pAEbz3aDoDaDBPlslKov X-Received: by 2002:a17:902:bb81:: with SMTP id m1-v6mr6752451pls.117.1527768935088; Thu, 31 May 2018 05:15:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527768935; cv=none; d=google.com; s=arc-20160816; b=onBjqC9LQ+dY/OiHPwI8ACsksGEiEF/yDN8nVOAoJFMQ9EeHjEZieGBaU6QL8DQRyX CLHhMxHfB9iCrmoH3U6fNkZ8EjDvzfjLjZDbBFlFxJ3lw/gwzERvCHQnuZvxcTWR4MsR 4WaCa36xXaPCGlKbDbNurBSPab3Fae3+8x9yookgxYGgBwJ1z0AX2AoJU2xlUKDg5913 axCE9mEgRMMk5dlBiqJhfCTBi0xcJBX6jXjAayXWOxLcdl6lEPoDUrf+ywxHyfpaca28 hsWQdPSxAfTdEzMM6q7bchDVSMZ9QIqdIqgATGTHRU+0/2dHk0pJVV+Q0ajdAtKuoyZv oECA== 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=6iL8IZuevVF7kT5lFvgfE/DDeAQ6EqAtqWW5NTaWqck=; b=RlO75kaHmahKrB0Ot9IM5M2zelaVt/wvF4hxhbIA/4UGXcC7KqPfyFuNArSbTc62vk e3m2O9Zshm17VWV8ytKhuYd6IN6l+6I3cIQln+Prxo70hwUEHTMrK9JAAx0B53GTla0Y qYmHBso0Rho3hdweJXNJFW0UrGMwx5IYUZ6Zg0J3a1U/zHgAiBhvKvb9J2Z0I47RXuv2 nHl+ivuI/JGXF5spxkJJzyh9uSFs0qXbajxEVeVcRkCFzgWM0HO9nWGDNFUh5lkTNZ4V 06MFkMAiixdEq18xTjJVbkhLlPI7nk1wQarD48ChMZYRyodet52opcY3KlptaV/TwArq 9u9g== 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 z12-v6si28855885pgu.115.2018.05.31.05.15.20; Thu, 31 May 2018 05:15:35 -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 S1754795AbeEaMOz (ORCPT + 99 others); Thu, 31 May 2018 08:14:55 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:8178 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754197AbeEaMOx (ORCPT ); Thu, 31 May 2018 08:14:53 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 25E6C91EA4F4E; Thu, 31 May 2018 20:14:40 +0800 (CST) Received: from [127.0.0.1] (10.177.29.40) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 20:14:41 +0800 Subject: Re: [PATCH v2 03/21] Staging: gdm724x: use match_string() helper To: Greg Kroah-Hartman References: <1527765086-19873-1-git-send-email-xieyisheng1@huawei.com> <1527765086-19873-4-git-send-email-xieyisheng1@huawei.com> <20180531114437.GA11598@kroah.com> CC: , , "Quytelda Kahja" , From: Yisheng Xie Message-ID: <22803947-32e5-6d71-31d3-0f732ee34cda@huawei.com> Date: Thu, 31 May 2018 20:12:59 +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: <20180531114437.GA11598@kroah.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 Hi Greg, On 2018/5/31 19:44, Greg Kroah-Hartman wrote: > On Thu, May 31, 2018 at 07:11:08PM +0800, Yisheng Xie wrote: >> 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; > > Very odd rewrite here. Why call this function if you think the initial > parameters are not correct? Are you sure about your test for > tty->index? Hmm, actually, I thought it no need to test tty->index here, but I not so sure about that so I kept it, I will remove this check next version. > > This should be cleaned up more please. Sure! Thanks Yisheng > > thanks, > > greg k-h > > . >