ipack: ipoctal: fix module reference leak

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 <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>

authored by Johan Hovold and committed by Greg Kroah-Hartman bb8a4fcb 445c8132

Changed files
+21 -8
drivers
ipack
devices
+21 -8
drivers/ipack/devices/ipoctal.c
··· 82 82 return 0; 83 83 } 84 84 85 - static int ipoctal_open(struct tty_struct *tty, struct file *file) 85 + static int ipoctal_install(struct tty_driver *driver, struct tty_struct *tty) 86 86 { 87 87 struct ipoctal_channel *channel = dev_get_drvdata(tty->dev); 88 88 struct ipoctal *ipoctal = chan_to_ipoctal(channel, tty->index); 89 - int err; 90 - 91 - tty->driver_data = channel; 89 + int res; 92 90 93 91 if (!ipack_get_carrier(ipoctal->dev)) 94 92 return -EBUSY; 95 93 96 - err = tty_port_open(&channel->tty_port, tty, file); 97 - if (err) 98 - ipack_put_carrier(ipoctal->dev); 94 + res = tty_standard_install(driver, tty); 95 + if (res) 96 + goto err_put_carrier; 99 97 100 - return err; 98 + tty->driver_data = channel; 99 + 100 + return 0; 101 + 102 + err_put_carrier: 103 + ipack_put_carrier(ipoctal->dev); 104 + 105 + return res; 106 + } 107 + 108 + static int ipoctal_open(struct tty_struct *tty, struct file *file) 109 + { 110 + struct ipoctal_channel *channel = tty->driver_data; 111 + 112 + return tty_port_open(&channel->tty_port, tty, file); 101 113 } 102 114 103 115 static void ipoctal_reset_stats(struct ipoctal_stats *stats) ··· 673 661 674 662 static const struct tty_operations ipoctal_fops = { 675 663 .ioctl = NULL, 664 + .install = ipoctal_install, 676 665 .open = ipoctal_open, 677 666 .close = ipoctal_close, 678 667 .write = ipoctal_write_tty,