Skip to content

Commit 7cea848

Browse files
jhovoldgregkh
authored andcommitted
ipack: ipoctal: fix module reference leak
commit bb8a4fc upstream. 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: 82a8234 ("ipoctal: get carrier driver to avoid rmmod") Cc: stable@vger.kernel.org # 3.18 Cc: Federico Vaga <federico.vaga@cern.ch> Acked-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com> Signed-off-by: Johan Hovold <johan@kernel.org> Link: https://lore.kernel.org/r/20210917114622.5412-6-johan@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 843efca commit 7cea848

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

drivers/ipack/devices/ipoctal.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,34 @@ static int ipoctal_port_activate(struct tty_port *port, struct tty_struct *tty)
8484
return 0;
8585
}
8686

87-
static int ipoctal_open(struct tty_struct *tty, struct file *file)
87+
static int ipoctal_install(struct tty_driver *driver, struct tty_struct *tty)
8888
{
8989
struct ipoctal_channel *channel = dev_get_drvdata(tty->dev);
9090
struct ipoctal *ipoctal = chan_to_ipoctal(channel, tty->index);
91-
int err;
92-
93-
tty->driver_data = channel;
91+
int res;
9492

9593
if (!ipack_get_carrier(ipoctal->dev))
9694
return -EBUSY;
9795

98-
err = tty_port_open(&channel->tty_port, tty, file);
99-
if (err)
100-
ipack_put_carrier(ipoctal->dev);
96+
res = tty_standard_install(driver, tty);
97+
if (res)
98+
goto err_put_carrier;
99+
100+
tty->driver_data = channel;
101+
102+
return 0;
103+
104+
err_put_carrier:
105+
ipack_put_carrier(ipoctal->dev);
106+
107+
return res;
108+
}
109+
110+
static int ipoctal_open(struct tty_struct *tty, struct file *file)
111+
{
112+
struct ipoctal_channel *channel = tty->driver_data;
101113

102-
return err;
114+
return tty_port_open(&channel->tty_port, tty, file);
103115
}
104116

105117
static void ipoctal_reset_stats(struct ipoctal_stats *stats)
@@ -665,6 +677,7 @@ static void ipoctal_cleanup(struct tty_struct *tty)
665677

666678
static const struct tty_operations ipoctal_fops = {
667679
.ioctl = NULL,
680+
.install = ipoctal_install,
668681
.open = ipoctal_open,
669682
.close = ipoctal_close,
670683
.write = ipoctal_write_tty,

0 commit comments

Comments
 (0)