From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4378C433FE for ; Fri, 17 Sep 2021 11:50:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DAB561212 for ; Fri, 17 Sep 2021 11:50:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344014AbhIQLv3 (ORCPT ); Fri, 17 Sep 2021 07:51:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:34176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242141AbhIQLv0 (ORCPT ); Fri, 17 Sep 2021 07:51:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 12B0561216; Fri, 17 Sep 2021 11:50:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631879404; bh=TxgPXz4WXZuDpnJVd8ABFgDYlXPBManWmJ/lxQHqzUk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oxsBDQGjDK+BdHU9M2Lzgxi4CBS409EpWZTxNggxPhhot+mT1l98fTCeUmXzzPWZ5 DRH8+8Zh0MgXkwttHvQpZa70Qr6Qyl7AyzXCA5l6yrNcQVzoVYajsNS3IGoeYwnqg8 ADVdVYJ++IlOKy/ir3QiQkcR45g19qJhoBNmiRxtzjtIPchc7X9DvN/wHM6Kp0ZmZE IXEBRSg/DeD9bv8gn5VRMXstPB15Dgy6JLHiBXKjfKA1nuurFWtfXzAbNNcir489yX mcdeFnqSa+JRf4+gxIVjmSof8MPvAQTwke4lQ50jhpsdTlIiZCVMxBM6XueDLyd8NK 6zmdU5sGw+cLg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1mRCNZ-0001RZ-W2; Fri, 17 Sep 2021 13:50:06 +0200 From: Johan Hovold To: Samuel Iglesias Gonsalvez , Jens Taprogge , Greg Kroah-Hartman Cc: industrypack-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Federico Vaga Subject: [PATCH 5/6] ipack: ipoctal: fix module reference leak Date: Fri, 17 Sep 2021 13:46:21 +0200 Message-Id: <20210917114622.5412-6-johan@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210917114622.5412-1-johan@kernel.org> References: <20210917114622.5412-1-johan@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A reference to the carrier module was taken on every open but was only released once when the final reference to the tty struct was dropped. Fix this by taking the module reference and initialising the tty driver data when installing the tty. Fixes: 82a82340bab6 ("ipoctal: get carrier driver to avoid rmmod") Cc: stable@vger.kernel.org # 3.18 Cc: Federico Vaga Signed-off-by: Johan Hovold --- drivers/ipack/devices/ipoctal.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c index 61c41f535510..c709861198e5 100644 --- a/drivers/ipack/devices/ipoctal.c +++ b/drivers/ipack/devices/ipoctal.c @@ -82,22 +82,34 @@ static int ipoctal_port_activate(struct tty_port *port, struct tty_struct *tty) return 0; } -static int ipoctal_open(struct tty_struct *tty, struct file *file) +static int ipoctal_install(struct tty_driver *driver, struct tty_struct *tty) { struct ipoctal_channel *channel = dev_get_drvdata(tty->dev); struct ipoctal *ipoctal = chan_to_ipoctal(channel, tty->index); - int err; - - tty->driver_data = channel; + int res; if (!ipack_get_carrier(ipoctal->dev)) return -EBUSY; - err = tty_port_open(&channel->tty_port, tty, file); - if (err) - ipack_put_carrier(ipoctal->dev); + res = tty_standard_install(driver, tty); + if (res) + goto err_put_carrier; + + tty->driver_data = channel; + + return 0; + +err_put_carrier: + ipack_put_carrier(ipoctal->dev); + + return res; +} + +static int ipoctal_open(struct tty_struct *tty, struct file *file) +{ + struct ipoctal_channel *channel = tty->driver_data; - return err; + return tty_port_open(&channel->tty_port, tty, file); } static void ipoctal_reset_stats(struct ipoctal_stats *stats) @@ -661,6 +673,7 @@ static void ipoctal_cleanup(struct tty_struct *tty) static const struct tty_operations ipoctal_fops = { .ioctl = NULL, + .install = ipoctal_install, .open = ipoctal_open, .close = ipoctal_close, .write = ipoctal_write_tty, -- 2.32.0