Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754349AbdGJPVk (ORCPT ); Mon, 10 Jul 2017 11:21:40 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:36761 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753298AbdGJPVi (ORCPT ); Mon, 10 Jul 2017 11:21:38 -0400 MIME-Version: 1.0 In-Reply-To: <20170710083105.GA719@sanghar> References: <20170708083803.GA23080@kroah.com> <20170709114153.157783481@gmail.com> <20170709114426.618570903@gmail.com> <20170710083105.GA719@sanghar> From: Andy Shevchenko Date: Mon, 10 Jul 2017 18:21:37 +0300 Message-ID: Subject: Re: [patch 1/3] tty: resolve tty contention between kernel and user space To: Okash Khawaja 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1044 Lines: 34 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. -- With Best Regards, Andy Shevchenko