From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754581AbdGJQMh (ORCPT ); Mon, 10 Jul 2017 12:12:37 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:33951 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753882AbdGJQMg (ORCPT ); Mon, 10 Jul 2017 12:12:36 -0400 Date: Mon, 10 Jul 2017 17:12:31 +0100 From: Okash Khawaja To: Andy Shevchenko Cc: Greg Kroah-Hartman , Jiri Slaby , Samuel Thibault , Alan Cox , "linux-kernel@vger.kernel.org" , William Hubbs , Chris Brannon , Kirk Reiser , speakup@linux-speakup.org, devel@driverdev.osuosl.org Subject: Re: [patch 1/3] tty: resolve tty contention between kernel and user space Message-ID: <20170710161231.GA417@sanghar> References: <20170708083803.GA23080@kroah.com> <20170709114153.157783481@gmail.com> <20170709114426.618570903@gmail.com> <20170710083105.GA719@sanghar> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 10, 2017 at 06:21:37PM +0300, Andy Shevchenko wrote: > On Mon, Jul 10, 2017 at 11:31 AM, Okash Khawaja wrote: > > On Sun, Jul 09, 2017 at 06:04:17PM +0300, Andy Shevchenko wrote: > >> On Sun, Jul 9, 2017 at 2:41 PM, Okash Khawaja wrote: > >> > >> > +struct tty_struct *tty_kopen(dev_t device) > >> > +{ > >> > + struct tty_struct *tty; > >> > + struct tty_driver *driver = NULL; > >> > + int index = -1; > >> > + > >> > + mutex_lock(&tty_mutex); > >> > + driver = tty_lookup_driver(device, NULL, &index); > >> > + if (IS_ERR(driver)) { > >> > >> > + mutex_unlock(&tty_mutex); > >> > + return ERR_CAST(driver); > >> > >> Hmm... perhaps > >> > >> tty = ERR_CAST(driver); > >> goto out_unlock; > >> > >> See below for further details. > >> > > Sorry missed this one out. Since tty_lookup_driver has failed, we don't > > need to down the refcount on driver. So we can return here, without > > going to out_unlock. > > Yeah, and my point is to use goto with the symmetric giveups of lock > and reference. Ah okay I see your point. Sure, I don't mind either way. However, this code closely follows tty_open_by_driver, so I have tried to keep the same pattern for sake of consistency :) Thanks, Okash