Skip to content

Commit

Permalink
TTY: tty_buffer, warn on leaks
Browse files Browse the repository at this point in the history
When we leak some tty buffer, warn about that. For that we need to
account the memory used also in the tty_buffer_free_all function. On
other locations, the accounting is handled correctly.

Note that we do not account the free list, as that was accounted in
tty_buffer_free before put on the free list.

I have been using this patch for ages, so let's see if anybody else
encounters any issues.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jiri Slaby authored and Greg Kroah-Hartman committed Sep 18, 2018
1 parent 8632990 commit feacbec
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/tty/tty_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ void tty_buffer_free_all(struct tty_port *port)
struct tty_bufhead *buf = &port->buf;
struct tty_buffer *p, *next;
struct llist_node *llist;
unsigned int freed = 0;
int still_used;

while ((p = buf->head) != NULL) {
buf->head = p->next;
freed += p->size;
if (p->size > 0)
kfree(p);
}
Expand All @@ -132,7 +135,9 @@ void tty_buffer_free_all(struct tty_port *port)
buf->head = &buf->sentinel;
buf->tail = &buf->sentinel;

atomic_set(&buf->mem_used, 0);
still_used = atomic_xchg(&buf->mem_used, 0);
WARN(still_used != freed, "we still have not freed %d bytes!",
still_used - freed);
}

/**
Expand Down

0 comments on commit feacbec

Please sign in to comment.