Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

TTY: isicom, fix tty buffers memory leak

After commit "TTY: move tty buffers to tty_port", the tty buffers are
not freed in some drivers. This is because tty_port_destructor is not
called whenever a tty_port is freed. This was an assumption I counted
with but was unfortunately untrue. So fix the drivers to fulfil this
assumption.

This one is special as we need more work to be done. Previously,
the tty_port was initialized at module load time, but to be able to
destroy the port and init it again, we now do the initialization in
probe and destroy in remove. I.e. at more appropriate places for that.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby and committed by
Greg Kroah-Hartman
d0f59141 de274bfe

+12 -9
+12 -9
drivers/tty/isicom.c
··· 1610 1610 if (retval < 0) 1611 1611 goto errunri; 1612 1612 1613 - for (index = 0; index < board->port_count; index++) 1614 - tty_port_register_device(&board->ports[index].port, 1615 - isicom_normal, board->index * 16 + index, 1616 - &pdev->dev); 1613 + for (index = 0; index < board->port_count; index++) { 1614 + struct tty_port *tport = &board->ports[index].port; 1615 + tty_port_init(tport); 1616 + tport->ops = &isicom_port_ops; 1617 + tport->close_delay = 50 * HZ/100; 1618 + tport->closing_wait = 3000 * HZ/100; 1619 + tty_port_register_device(tport, isicom_normal, 1620 + board->index * 16 + index, &pdev->dev); 1621 + } 1617 1622 1618 1623 return 0; 1619 1624 ··· 1640 1635 struct isi_board *board = pci_get_drvdata(pdev); 1641 1636 unsigned int i; 1642 1637 1643 - for (i = 0; i < board->port_count; i++) 1638 + for (i = 0; i < board->port_count; i++) { 1644 1639 tty_unregister_device(isicom_normal, board->index * 16 + i); 1640 + tty_port_destroy(&board->ports[i].port); 1641 + } 1645 1642 1646 1643 free_irq(board->irq, board); 1647 1644 pci_release_region(pdev, 3); ··· 1662 1655 isi_card[idx].ports = port; 1663 1656 spin_lock_init(&isi_card[idx].card_lock); 1664 1657 for (channel = 0; channel < 16; channel++, port++) { 1665 - tty_port_init(&port->port); 1666 - port->port.ops = &isicom_port_ops; 1667 1658 port->magic = ISICOM_MAGIC; 1668 1659 port->card = &isi_card[idx]; 1669 1660 port->channel = channel; 1670 - port->port.close_delay = 50 * HZ/100; 1671 - port->port.closing_wait = 3000 * HZ/100; 1672 1661 port->status = 0; 1673 1662 /* . . . */ 1674 1663 }