Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752620AbbLNPlD (ORCPT ); Mon, 14 Dec 2015 10:41:03 -0500 Received: from lxorguk.ukuu.org.uk ([81.2.110.251]:36013 "EHLO lxorguk.ukuu.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751860AbbLNPlB (ORCPT ); Mon, 14 Dec 2015 10:41:01 -0500 Date: Mon, 14 Dec 2015 15:40:35 +0000 From: One Thousand Gnomes To: Pan Xinhui Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , yanmin_zhang@linux.intel.com, mnipxh@163.com Subject: Re: [PATCH resend ] tty/n_gsm.c: use gsm->num to remove mux itself from gsm_mux[] Message-ID: <20151214154035.15ebb75a@lxorguk.ukuu.org.uk> In-Reply-To: <566E6AD3.1060003@linux.vnet.ibm.com> References: <566E6AD3.1060003@linux.vnet.ibm.com> Organization: Intel Corporation X-Mailer: Claws Mail 3.12.0 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1536 Lines: 49 On Mon, 14 Dec 2015 15:08:03 +0800 Pan Xinhui wrote: > 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 > --- > drivers/tty/n_gsm.c | 14 +++++--------- > 1 files changed, 5 insertions(+), 9 deletions(-) > > diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c > index 9aff371..cf28054 100644 > --- a/drivers/tty/n_gsm.c > +++ b/drivers/tty/n_gsm.c > @@ -2037,18 +2037,14 @@ 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) > return; > > + spin_lock(&gsm_mux_lock); > + gsm_mux[gsm->num] = NULL; > + spin_unlock(&gsm_mux_lock); Its a highly theoretical and probably impossible corner case but I can't help thinking the lock should be held for the if () as well as NULLing this out. Alan -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/