Skip to contentSkip to conversation

PATCH: Trivial kzalloc opportunity

PATCH Alan Cox 4 participants 4 messages Aug 16, 2006 Char and misc drivers

lore
Share & tools
lore

Alan Cox

author
#0 lore raw
drivers/char/tty_io.c +1 -7
diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.18-rc4-mm1/drivers/char/tty_io.c linux-2.6.18-rc4-mm1/drivers/char/tty_io.c
@@ -160,17 +160,11 @@
  *	been initialized in any way but has been zeroed
  *
  *	Locking: none
- *	FIXME: use kzalloc
  */
 
 static struct tty_struct *alloc_tty_struct(void)
 {
-	struct tty_struct *tty;
-
-	tty = kmalloc(sizeof(struct tty_struct), GFP_KERNEL);
-	if (tty)
-		memset(tty, 0, sizeof(struct tty_struct));
-	return tty;
+	return (struct tty_struct *)kzalloc(sizeof(struct tty_struct), GFP_KERNEL);
 }
 
 static void tty_buffer_free_all(struct tty_struct *);
#1 lore raw

drivers/char/tty_io.c line 167

Quoted 1 line
drivers/char/tty_io.c +1 -0
+	return (struct tty_struct *)kzalloc(sizeof(struct tty_struct), GFP_KERNEL);

Why the cast here? kzalloc() returns void *

- R.

#2 lore raw
In reply to Alan Cox
Quoted 13 lines · Alan Cox

diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.18-rc4-mm1/drivers/char/tty_io.c linux-2.6.18-rc4-mm1/drivers/char/tty_io.c

drivers/char/tty_io.c +0 -1
@@ -160,17 +160,11 @@
  *	been initialized in any way but has been zeroed
  *
  *	Locking: none
- *	FIXME: use kzalloc
  */
 
 static struct tty_struct *alloc_tty_struct(void)

drivers/char/tty_io.c line 169

Quoted 10 lines
drivers/char/tty_io.c +1 -6
 {
-	struct tty_struct *tty;
-
-	tty = kmalloc(sizeof(struct tty_struct), GFP_KERNEL);
-	if (tty)
-		memset(tty, 0, sizeof(struct tty_struct));
-	return tty;
+	return (struct tty_struct *)kzalloc(sizeof(struct tty_struct), GFP_KERNEL);
 }
 

makes you wonder why this function even exists... (and why there is a typecast in it ;)

Signature · 1 line
if you want to mail me at work (you don't), use arjan (at) linux.intel.com