Skip to content

Commit

Permalink
Bluetooth: uart-ldisc: Fix memory leak and remove destruct cb
Browse files Browse the repository at this point in the history
We currently leak the hci_uart object if HCI_UART_PROTO_SET is never set
because the hci-destruct callback will then never be called.  This fix
removes the hci-destruct callback and frees the driver internal private
hci_uart object directly on tty-close. We call hci_unregister_dev() here
so the hci-core will never call our callbacks again (except destruct).
Therefore, we can safely free the driver internal data right away and
set the destruct callback to NULL.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
  • Loading branch information
David Herrmann authored and Johan Hedberg committed Feb 13, 2012
1 parent dabbaab commit 797fe79
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions drivers/bluetooth/hci_ldisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,6 @@ static int hci_uart_send_frame(struct sk_buff *skb)
return 0;
}

static void hci_uart_destruct(struct hci_dev *hdev)
{
if (!hdev)
return;

BT_DBG("%s", hdev->name);
kfree(hdev->driver_data);
}

/* ------ LDISC part ------ */
/* hci_uart_tty_open
*
Expand Down Expand Up @@ -316,6 +307,8 @@ static void hci_uart_tty_close(struct tty_struct *tty)
hci_free_dev(hdev);
}
}

kfree(hu);
}
}

Expand Down Expand Up @@ -397,7 +390,6 @@ static int hci_uart_register_dev(struct hci_uart *hu)
hdev->close = hci_uart_close;
hdev->flush = hci_uart_flush;
hdev->send = hci_uart_send_frame;
hdev->destruct = hci_uart_destruct;
hdev->parent = hu->tty->dev;

hdev->owner = THIS_MODULE;
Expand Down

0 comments on commit 797fe79

Please sign in to comment.