From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752302AbcGNIia (ORCPT ); Thu, 14 Jul 2016 04:38:30 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38385 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751736AbcGNIiT (ORCPT ); Thu, 14 Jul 2016 04:38:19 -0400 X-IBM-Helo: d28dlp02.in.ibm.com X-IBM-MailFrom: xinhui.pan@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Date: Thu, 14 Jul 2016 16:37:51 +0800 From: xinhui User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: "linux-kernel@vger.kernel.org" CC: Jiri Slaby , yanmin_zhang@linux.intel.com, alan@linux.intel.com, gregkh@linuxfoundation.org Subject: [PATCH V2 RESEND] tty/n_gsm.c: use gsm->num to remove mux itself from gsm_mux[] Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16071408-0056-0000-0000-0000029315DE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16071408-0057-0000-0000-00000ECB5F22 Message-Id: <57874F5F.5050000@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-07-14_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1607140095 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pan Xinhui There is one filed gsm->num to store mux's index of gsm_mux[]. So use gsm->num to remove itself from gsm_mux[] instead of the for-loop traverse in gsm_cleanup_mux(). Signed-off-by: Pan Xinhui Reviewed-by: Alan Cox --- change from V1: lock is also held for the if() --- drivers/tty/n_gsm.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 9aff371..697b31e 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2038,16 +2038,13 @@ static void gsm_cleanup_mux(struct gsm_mux *gsm) gsm->dead = 1; spin_lock(&gsm_mux_lock); - for (i = 0; i < MAX_MUX; i++) { - if (gsm_mux[i] == gsm) { - gsm_mux[i] = NULL; - break; - } - } - spin_unlock(&gsm_mux_lock); /* open failed before registering => nothing to do */ - if (i == MAX_MUX) + if (gsm_mux[gsm->num] != gsm) { + spin_unlock(&gsm_mux_lock); return; + } + gsm_mux[gsm->num] = NULL; + spin_unlock(&gsm_mux_lock); /* In theory disconnecting DLCI 0 is sufficient but for some modems this is apparently not the case. */ -- 1.9.1