Skip to contentSkip to conversation

tty: handle NULL parameters in free_tty_struct()

PATCH In review Dan Carpenter 3 participants 3 messages Jul 20, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tty: handle NULL parameters in free_tty_struct()

We sometimes pass NULL pointers to free_tty_struct(). One example where it can happen is in the error handling code in pty_common_install().

drivers/tty/tty_io.c +2 -0
index ca7c25d..e49b839 100644
@@ -181,6 +181,8 @@ struct tty_struct *alloc_tty_struct(void)
 
 void free_tty_struct(struct tty_struct *tty)
 {
+	if (!tty)
+		return;
 	if (tty->dev)
 		put_device(tty->dev);
 	kfree(tty->write_buf);
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · On Fri, 20 Jul 2012 10:06:34 +0300 Dan Carpenter <[email protected]>…

We sometimes pass NULL pointers to free_tty_struct(). One example where it can happen is in the error handling code in pty_common_install().

We probably shouldn't be passing NULLs there but making free_tty_struct(NULL) a no-op matches the kfree and other behaviours and is robust.

#2 lore raw
Quoted 6 lines · Alan Cox
Quoted 3 lines · On Fri, 20 Jul 2012 10:06:34 +0300 Dan Carpenter <[email protected]>…

We sometimes pass NULL pointers to free_tty_struct(). One example where it can happen is in the error handling code in pty_common_install().

Quoted 7 lines
Quoted 1 line

We probably shouldn't be passing NULLs there but making free_tty_struct(NULL) a no-op matches the kfree and other behaviours and is robust.

Yes, this was unintended. Good catch, Dan.

thanks,

Signature · 2 lines
js
suse labs