tty: remove redundant initialization in initialize_tty_struct()
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
@@ -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
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
@@ -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
Quoted 1 line · On Fri, 23 Nov 2012 22:41:47 +0800 Yan Hong <[email protected]> wrote:
tty_structis already zeroed, no need to zero its field again.
True but its asking for impossible to find bugs later if this changes
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_structis 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
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_structis 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