Skip to contentSkip to conversation

tty: remove redundant initialization in initialize_tty_struct()

PATCH In review Yan Hong 2 participants 5 messages Nov 23, 2012 – Dec 20, 2012 TTY layer and serial drivers

lore
Share & tools
lore

Yan Hong

author
#0 lore raw

PATCH 1/2 tty: remove redundant initialization in initialize_tty_struct()

tty_struct is already zeroed, no need to zero its field again.

---
Actually alloc_tty_struct() already zerod tty_struct. Logically speaking these two functions can be called independently, but they are always called in pair in current code. Maybe someday we can arrange only one of them zero the memory and let the other expect a zeroed tty_struct (and document this assumption).

 drivers/tty/tty_io.c |    2 --
 1 file changed, 2 deletions(-)
drivers/tty/tty_io.c +0 -2
index 2ea176b..e278edf 100644
@@ -2935,8 +2935,6 @@ void initialize_tty_struct(struct tty_struct *tty,
 	kref_init(&tty->kref);
 	tty->magic = TTY_MAGIC;
 	tty_ldisc_init(tty);
-	tty->session = NULL;
-	tty->pgrp = NULL;
 	tty->overrun_time = jiffies;
 	tty_buffer_init(tty);
 	mutex_init(&tty->legacy_mutex);
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 2/2 tty: remove useless initialization in tty_open

retval must be zero here, no need to set it to zero explicitly.

---
 drivers/tty/tty_io.c |    1 -
 1 file changed, 1 deletion(-)
drivers/tty/tty_io.c +0 -1
index e278edf..6d90e9b 100644
@@ -1928,7 +1928,6 @@ retry_open:
 
 	noctty = filp->f_flags & O_NOCTTY;
 	index  = -1;
-	retval = 0;
 
 	mutex_lock(&tty_mutex);
 	/* This is protected by the tty_mutex */
Signature · 1 line
1.7.9.5
#2 lore raw
In reply to Yan Hong
Quoted 1 line · On Fri, 23 Nov 2012 22:41:47 +0800 Yan Hong <[email protected]> wrote:

tty_struct is already zeroed, no need to zero its field again.

True but its asking for impossible to find bugs later if this changes

author
#3 lore raw

2012/11/23 Alan Cox <[email protected]>:

Quoted 6 lines
Quoted 1 line · On Fri, 23 Nov 2012 22:41:47 +0800 Yan Hong <[email protected]> wrote:

tty_struct is already zeroed, no need to zero its field again.

True but its asking for impossible to find bugs later if this changes

If it's true, we should have concern for all memset() usage. Is this case special?

Thanks

#4 lore raw
Quoted 10 lines · On Fri, 23 Nov 2012 23:04:52 +0800 Yan Hong <[email protected]> wrote:

2012/11/23 Alan Cox <[email protected]>:

Quoted 6 lines
Quoted 1 line · On Fri, 23 Nov 2012 22:41:47 +0800 Yan Hong <[email protected]> wrote:

tty_struct is already zeroed, no need to zero its field again.

True but its asking for impossible to find bugs later if this changes

If it's true, we should have concern for all memset() usage. Is this case special?

Slowly catchng up on stuff. The problem in this case is that the allocator and init methods are in different function. As you rightly observe they don't need to be. Perhaps a better patch would be told fold them together and remove the memset ?

Alan