TTY: tty_buffer, warn on leaks
PATCH 1/1 TTY: tty_buffer, warn on leaks
When we leak something, warn about that. For that we need to account the memory used also in the free_all method. It is handled elsewhere correctly.
--- drivers/tty/tty_buffer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/tty/tty_buffer.c +8 -2
@@ -115,21 +115,27 @@ void tty_buffer_free_all(struct tty_port *port)struct tty_bufhead *buf = &port->buf;struct tty_buffer *p, *next;struct llist_node *llist; +int zero =0 ;while ((p = buf->head) !=NULL ) { buf->head = p->next; +atomic_sub (p->size, &buf->memory_used);if (p->size >0 )kfree (p); } llist =llist_del_all (&buf->free); -llist_for_each_entry_safe (p, next, llist, free) +llist_for_each_entry_safe (p, next, llist, free) { +atomic_sub (p->size, &buf->memory_used);kfree (p); + } +tty_buffer_reset (&buf->sentinel,0 ); buf->head = &buf->sentinel; buf->tail = &buf->sentinel; -atomic_set (&buf->memory_used,0 ); +atomic_xchg (&buf->memory_used, zero); +WARN_ON (zero !=0 ); }/**
Signature · 1 line
1.8.4.2
Quoted 3 lines · Jiri Slaby
When we leak something, warn about that. For that we need to account the memory used also in the
free_allmethod. It is handled elsewhere correctly.
Hi Jiri,
Good idea.
Quoted 10 lines
Signed-off-by Jiri Slaby <[email protected]>--- drivers/tty/tty_buffer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/tty/tty_buffer.c +0
-0
drivers/tty/tty_buffer.c void tty_buffer_free_all(struct tty_port *port) · line 122
Quoted 8 lines
drivers/tty/tty_buffer.c +2
-0@@ -115,21 +115,27 @@ void tty_buffer_free_all(struct tty_port *port)struct tty_bufhead *buf = &port->buf;struct tty_buffer *p, *next;struct llist_node *llist; +int zero =0 ;while ((p = buf->head) !=NULL ) { buf->head = p->next; +atomic_sub (p->size, &buf->memory_used);
buf->memory_used doesn't need to be treated atomically here, and doing so implies that it's necessary.
Accumulating p->size in a non-atomic local is probably better.
drivers/tty/tty_buffer.c void tty_buffer_free_all(struct tty_port *port) · line 128
Quoted 7 lines
drivers/tty/tty_buffer.c +2
-1if (p->size >0 )kfree (p); } llist =llist_del_all (&buf->free); -llist_for_each_entry_safe (p, next, llist, free) +llist_for_each_entry_safe (p, next, llist, free) { +atomic_sub (p->size, &buf->memory_used);
Same here.
drivers/tty/tty_buffer.c void tty_buffer_free_all(struct tty_port *port) · line 138
Quoted 11 lines
drivers/tty/tty_buffer.c +4
-1kfree (p); + } +tty_buffer_reset (&buf->sentinel,0 ); buf->head = &buf->sentinel; buf->tail = &buf->sentinel; -atomic_set (&buf->memory_used,0 ); +atomic_xchg (&buf->memory_used, zero); +WARN_ON (zero !=0 );
Then,
WARN_ON(atomic_read(&buf->memory_used) != <local accum>); atomic_set(&buf->memory_used, 0);
?
Regards,
Peter Hurley
Quoted 41 lines · Peter Hurley
Quoted 3 lines · Jiri Slaby
When we leak something, warn about that. For that we need to account the memory used also in the
free_allmethod. It is handled elsewhere correctly.Hi Jiri,
Good idea.
Quoted 10 lines
Signed-off-by Jiri Slaby <[email protected]>--- drivers/tty/tty_buffer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/tty/tty_buffer.c +0
-0drivers/tty/tty_buffer.c void tty_buffer_free_all(struct tty_port *port) · line 122
Quoted 8 lines
drivers/tty/tty_buffer.c +2
-0@@ -115,21 +115,27 @@ void tty_buffer_free_all(struct tty_port *port)struct tty_bufhead *buf = &port->buf;struct tty_buffer *p, *next;struct llist_node *llist; +int zero =0 ;while ((p = buf->head) !=NULL ) { buf->head = p->next; +atomic_sub (p->size, &buf->memory_used);
buf->memory_useddoesn't need to be treated atomically here, and doing so implies that it's necessary.Accumulating
p->sizein a non-atomic local is probably better.drivers/tty/tty_buffer.c void tty_buffer_free_all(struct tty_port *port) · line 128
Quoted 7 lines
drivers/tty/tty_buffer.c +2
-1if (p->size >0 )kfree (p); } llist =llist_del_all (&buf->free); -llist_for_each_entry_safe (p, next, llist, free) +llist_for_each_entry_safe (p, next, llist, free) { +atomic_sub (p->size, &buf->memory_used);
Quoted 1 line
Same here.
Sorry, I forgot: the buffers on the free list have already been accounted for in tty_buffer_free() so don't form part of the buf->mem_used total.
The buffer memory accounting was like that in 3.7 so I left it in.
static void tty_buffer_free(struct tty_port *port, struct tty_buffer *b)
{
struct tty_bufhead *buf = &port->buf;
/* Dumb strategy for now - should keep some stats */
WARN_ON(atomic_sub_return(b->size, &buf->mem_used) < 0);
if (b->size > MIN_TTYB_SIZE)
kfree(b);
else if (b->size > 0)
llist_add(&b->free, &buf->free);
}Regards,
Peter Hurley