Message ID | 20221114010734.314910-1-shaozhengchao@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1900423wru; Sun, 13 Nov 2022 17:07:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf5hYDQcQwKIjI7IxvzsRrJgjA1SCPCxf6JbtauB9G1ITvEp53WjcRuPCccvZlwPhPQlelW+ X-Received: by 2002:a65:49ca:0:b0:456:f7bd:a1 with SMTP id t10-20020a6549ca000000b00456f7bd00a1mr9986118pgs.79.1668388029098; Sun, 13 Nov 2022 17:07:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668388029; cv=none; d=google.com; s=arc-20160816; b=AiRbBL9gXxPUXz4xgHMqOgTc9MYMSG2b4DAUtOSh+2VsX+mTcR2s3gpJbT2TfmmsAd Ow0vmJnTJ5AkmbkNCjDKSJxz/j1Ijr7cZawcnarBcbruJEDciwE3bHgX2Mhl7KlnsYX8 He+A69/JcFog1l3F9IRwwlR6a0ZQFYV+hZCTGMiTyb7NBwKwkxWf+a5odve53tgHv6gw IS5TfGoJ0A4WhUirxLtOIUweXYdUh0YSOZhUUhL8zlpDn5UYNZc/lynIWS8fEwKTyhJL ZGbJgkK5iLIjhlJqWO6T1HdsVc1RXAlwvslodi+GdOareAiYLw16bM2PZdvKx8zM+Gj5 b2xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=5s4DjfhNr4jeyWm5lr09r4EGAD1RjKs2qI6ioqjZpy0=; b=dILnCq9BNEUCLLwqisKTTjmo0P8EFcRDWhqHSNkFL5HiB5sKxjucnvaZkibXXaoWQN U8g62FB5eOaAZ1l+XugzoILUnOUyTavvkzimVlszKsUuzCvTmGwKYirIkMKJ1B6iKlx5 yNdZ/9kdTCqhPEuaMNYDHz2HH7gZo8fjQ+Yb1zhiZ+w18NZ5KViV+hqsck+yMEzOOtjU SijXRS8sFlia3lqc0NLF0mT3xmaXaj9C59D8sOzzSfuXCJbHr3tzkc+CXZ9nb9qEinue /mqg42rpqWAOvgKyIBBPYO1B/PB+/tkDe4IB6Z1dhB9MfrXECvmkA6EClYONzFJ8Oc+Y TFHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a8-20020a637048000000b00470274bbc14si8339849pgn.676.2022.11.13.17.06.46; Sun, 13 Nov 2022 17:07:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235642AbiKNBAy (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Sun, 13 Nov 2022 20:00:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233069AbiKNBAx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 13 Nov 2022 20:00:53 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5752ADEDA for <linux-kernel@vger.kernel.org>; Sun, 13 Nov 2022 17:00:51 -0800 (PST) Received: from dggpeml500026.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N9WFK0BbnzHvqv; Mon, 14 Nov 2022 09:00:21 +0800 (CST) Received: from huawei.com (10.175.101.6) by dggpeml500026.china.huawei.com (7.185.36.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 14 Nov 2022 09:00:49 +0800 From: Zhengchao Shao <shaozhengchao@huawei.com> To: <linux-kernel@vger.kernel.org>, <gregkh@linuxfoundation.org>, <jirislaby@kernel.org> CC: <akpm@linux-foundation.org>, <paulkf@microgate.com>, <weiyongjun1@huawei.com>, <yuehaibing@huawei.com>, <shaozhengchao@huawei.com> Subject: [PATCH] tty: synclink_gt: release resources when synclink_gt driver open failed Date: Mon, 14 Nov 2022 09:07:34 +0800 Message-ID: <20221114010734.314910-1-shaozhengchao@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500026.china.huawei.com (7.185.36.106) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749431645829970303?= X-GMAIL-MSGID: =?utf-8?q?1749431645829970303?= |
Series |
tty: synclink_gt: release resources when synclink_gt driver open failed
|
|
Commit Message
shaozhengchao
Nov. 14, 2022, 1:07 a.m. UTC
When synclink_gt driver open failed, it doesn't release resources. Compile
tested only.
Fixes: d4c63b7c7450 ("synclink_gt fix module reference")
Fixes: 705b6c7b34f2 ("[PATCH] new driver synclink_gt")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
drivers/tty/synclink_gt.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
Comments
On 14. 11. 22, 2:07, Zhengchao Shao wrote: > When synclink_gt driver open failed, it doesn't release resources. But hdlc_close() does. Now, you call it (apart from the TTY layer) too. > Compile tested only. Hmm, NACK. > Fixes: d4c63b7c7450 ("synclink_gt fix module reference") > Fixes: 705b6c7b34f2 ("[PATCH] new driver synclink_gt") > Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com> > --- > drivers/tty/synclink_gt.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c > index 25e9befdda3a..4dea52486410 100644 > --- a/drivers/tty/synclink_gt.c > +++ b/drivers/tty/synclink_gt.c > @@ -1441,14 +1441,15 @@ static int hdlcdev_open(struct net_device *dev) > /* generic HDLC layer open processing */ > rc = hdlc_open(dev); > if (rc) > - return rc; > + goto err_open; > > /* arbitrate between network and tty opens */ > spin_lock_irqsave(&info->netlock, flags); > if (info->port.count != 0 || info->netcount != 0) { > DBGINFO(("%s hdlc_open busy\n", dev->name)); > spin_unlock_irqrestore(&info->netlock, flags); > - return -EBUSY; > + rc = -EBUSY; > + goto err_open_busy; > } > info->netcount=1; > spin_unlock_irqrestore(&info->netlock, flags); > @@ -1458,7 +1459,7 @@ static int hdlcdev_open(struct net_device *dev) > spin_lock_irqsave(&info->netlock, flags); > info->netcount=0; > spin_unlock_irqrestore(&info->netlock, flags); > - return rc; > + goto err_open_busy; > } > > /* assert RTS and DTR, apply hardware settings */ > @@ -1478,6 +1479,12 @@ static int hdlcdev_open(struct net_device *dev) > else > netif_carrier_off(dev); > return 0; > + > +err_open_busy: > + hdlc_close(dev); > +err_open: > + module_put(THIS_MODULE); > + return rc; > } > > /**
On Mon, Nov 14, 2022 at 09:07:34AM +0800, Zhengchao Shao wrote: > When synclink_gt driver open failed, it doesn't release resources. Compile > tested only. How was this found? Please always provide the proper required information about stuff like this as our documentation requires. thanks, greg k-h
This patch identifies two problems in the error path of hdlcdev_open(): 1. module_get/put pairing 2. hdlc_open/close pairing The module_get/put calls are not necessary. The synclink_gt driver is pinned on hardware enumeration which happens before registering as a generic hdlc device. I think this is cruft leftover from ancient code. The only other generic hdlc (network) driver I still see doing it is farsync.c. The best solution is removing the module_get/put calls and balancing hdlc_open() with hdlc_close() in the error path of hdlcdev_open(). I will submit a patch to do so after I’ve had a chance to test it. > On Nov 13, 2022, at 5:07 PM, Zhengchao Shao <shaozhengchao@huawei.com> wrote: > > When synclink_gt driver open failed, it doesn't release resources. Compile > tested only. > > Fixes: d4c63b7c7450 ("synclink_gt fix module reference") > Fixes: 705b6c7b34f2 ("[PATCH] new driver synclink_gt") > Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com> > --- > drivers/tty/synclink_gt.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c > index 25e9befdda3a..4dea52486410 100644 > --- a/drivers/tty/synclink_gt.c > +++ b/drivers/tty/synclink_gt.c > @@ -1441,14 +1441,15 @@ static int hdlcdev_open(struct net_device *dev) > /* generic HDLC layer open processing */ > rc = hdlc_open(dev); > if (rc) > - return rc; > + goto err_open; > > /* arbitrate between network and tty opens */ > spin_lock_irqsave(&info->netlock, flags); > if (info->port.count != 0 || info->netcount != 0) { > DBGINFO(("%s hdlc_open busy\n", dev->name)); > spin_unlock_irqrestore(&info->netlock, flags); > - return -EBUSY; > + rc = -EBUSY; > + goto err_open_busy; > } > info->netcount=1; > spin_unlock_irqrestore(&info->netlock, flags); > @@ -1458,7 +1459,7 @@ static int hdlcdev_open(struct net_device *dev) > spin_lock_irqsave(&info->netlock, flags); > info->netcount=0; > spin_unlock_irqrestore(&info->netlock, flags); > - return rc; > + goto err_open_busy; > } > > /* assert RTS and DTR, apply hardware settings */ > @@ -1478,6 +1479,12 @@ static int hdlcdev_open(struct net_device *dev) > else > netif_carrier_off(dev); > return 0; > + > +err_open_busy: > + hdlc_close(dev); > +err_open: > + module_put(THIS_MODULE); > + return rc; > } > > /** > -- > 2.17.1 >
On Tue, Nov 15, 2022 at 08:25:13AM -0800, Paul Fulghum wrote: > Zhengchao Shao <shaozhengchao@huawei.com <mailto:shaozhengchao@huawei.com>> identified by inspection bugs in the error path of hdlcdev_open() in synclink_gt.c > > The function did not fully unwind actions in the error path. The use of try_module_get()/module_put() is unnecessary, potentially hazardous and is removed. The synclink_gt driver is already pinned any point the net device is registered, a requirement for calling this entry point. > > The call hdlc_open() to init the generic HDLC layer is moved to after driver level init/checks and proper rollback of previous actions is added. This is a more sensible ordering as the most common error paths are at the driver level and the driver level rollbacks require less processing than hdlc_open()/hdlc_close(). > > This has been tested with supported hardware. > > Signed-off-by:Paul Fulghum <paulkf@microgate.com <mailto:paulkf@microgate.com>> > > > diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c > index 25e9befdda3a..72b76cdde534 100644 > --- a/drivers/tty/synclink_gt.c > +++ b/drivers/tty/synclink_gt.c > @@ -1433,16 +1433,8 @@ static int hdlcdev_open(struct net_device *dev) > int rc; > unsigned long flags; > > - if (!try_module_get(THIS_MODULE)) > - return -EBUSY; > - > DBGINFO(("%s hdlcdev_open\n", dev->name)); > > - /* generic HDLC layer open processing */ > - rc = hdlc_open(dev); > - if (rc) > - return rc; > - > /* arbitrate between network and tty opens */ > spin_lock_irqsave(&info->netlock, flags); > if (info->port.count != 0 || info->netcount != 0) { > @@ -1461,6 +1453,16 @@ static int hdlcdev_open(struct net_device *dev) > return rc; > } > > + /* generic HDLC layer open processing */ > + rc = hdlc_open(dev); > + if (rc) { > + shutdown(info); > + spin_lock_irqsave(&info->netlock, flags); > + info->netcount = 0; > + spin_unlock_irqrestore(&info->netlock, flags); > + return rc; > + } > + > /* assert RTS and DTR, apply hardware settings */ > info->signals |= SerialSignal_RTS | SerialSignal_DTR; > program_hw(info); > @@ -1506,7 +1508,6 @@ static int hdlcdev_close(struct net_device *dev) > info->netcount=0; > spin_unlock_irqrestore(&info->netlock, flags); > > - module_put(THIS_MODULE); > return 0; > } > > Hi, This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree. You are receiving this message because of the following common error(s) as indicated below: - Your patch was sent in HTML format, making it impossible to be applied, and it has been rejected from the mailing lists because of that. Please read the file, Documentation/email-clients.txt in order to fix this. If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers. thanks, greg k-h's patch email bot
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c index 25e9befdda3a..4dea52486410 100644 --- a/drivers/tty/synclink_gt.c +++ b/drivers/tty/synclink_gt.c @@ -1441,14 +1441,15 @@ static int hdlcdev_open(struct net_device *dev) /* generic HDLC layer open processing */ rc = hdlc_open(dev); if (rc) - return rc; + goto err_open; /* arbitrate between network and tty opens */ spin_lock_irqsave(&info->netlock, flags); if (info->port.count != 0 || info->netcount != 0) { DBGINFO(("%s hdlc_open busy\n", dev->name)); spin_unlock_irqrestore(&info->netlock, flags); - return -EBUSY; + rc = -EBUSY; + goto err_open_busy; } info->netcount=1; spin_unlock_irqrestore(&info->netlock, flags); @@ -1458,7 +1459,7 @@ static int hdlcdev_open(struct net_device *dev) spin_lock_irqsave(&info->netlock, flags); info->netcount=0; spin_unlock_irqrestore(&info->netlock, flags); - return rc; + goto err_open_busy; } /* assert RTS and DTR, apply hardware settings */ @@ -1478,6 +1479,12 @@ static int hdlcdev_open(struct net_device *dev) else netif_carrier_off(dev); return 0; + +err_open_busy: + hdlc_close(dev); +err_open: + module_put(THIS_MODULE); + return rc; } /**