Skip to content

Commit feacbec

Browse files
Jiri Slabygregkh
authored andcommitted
TTY: tty_buffer, warn on leaks
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>
1 parent 8632990 commit feacbec

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/tty/tty_buffer.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ void tty_buffer_free_all(struct tty_port *port)
118118
struct tty_bufhead *buf = &port->buf;
119119
struct tty_buffer *p, *next;
120120
struct llist_node *llist;
121+
unsigned int freed = 0;
122+
int still_used;
121123

122124
while ((p = buf->head) != NULL) {
123125
buf->head = p->next;
126+
freed += p->size;
124127
if (p->size > 0)
125128
kfree(p);
126129
}
@@ -132,7 +135,9 @@ void tty_buffer_free_all(struct tty_port *port)
132135
buf->head = &buf->sentinel;
133136
buf->tail = &buf->sentinel;
134137

135-
atomic_set(&buf->mem_used, 0);
138+
still_used = atomic_xchg(&buf->mem_used, 0);
139+
WARN(still_used != freed, "we still have not freed %d bytes!",
140+
still_used - freed);
136141
}
137142

138143
/**

0 commit comments

Comments
 (0)