Skip to content

Commit

Permalink
ipack: ipoctal: fix module reference leak
Browse files Browse the repository at this point in the history
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: [email protected]      # 3.18
Cc: Federico Vaga <[email protected]>
Acked-by: Samuel Iglesias Gonsalvez <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
jhovold authored and gregkh committed Sep 27, 2021
1 parent 445c813 commit bb8a4fc
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions drivers/ipack/devices/ipoctal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bb8a4fc

Please sign in to comment.