Skip to contentSkip to conversation

tty_io: Use kzalloc

PATCH Superseded Jean Delvare 3 participants 5 messages May 25, 2007 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tty_io: Use kzalloc

---
Andrew, can you please pick this? I couldn't find any maintainer for this driver. Thanks.

 drivers/char/tty_io.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/char/tty_io.c +3 -6
@@ -2009,11 +2009,10 @@ static int init_dev(struct tty_driver *d
 	}
 
 	if (!*ltp_loc) {
-		ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
+		ltp = (struct ktermios *) kzalloc(sizeof(struct ktermios),
 						 GFP_KERNEL);
 		if (!ltp)
 			goto free_mem_out;
-		memset(ltp, 0, sizeof(struct ktermios));
 	}
 
 	if (driver->type == TTY_DRIVER_TYPE_PTY) {
@@ -2043,10 +2042,9 @@ static int init_dev(struct tty_driver *d
 
 		if (!*o_ltp_loc) {
 			o_ltp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+				kzalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_ltp)
 				goto free_mem_out;
-			memset(o_ltp, 0, sizeof(struct ktermios));
 		}
 
 		/*
@@ -3732,9 +3730,8 @@ struct tty_driver *alloc_tty_driver(int 
 {
 	struct tty_driver *driver;
 
-	driver = kmalloc(sizeof(struct tty_driver), GFP_KERNEL);
+	driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL);
 	if (driver) {
-		memset(driver, 0, sizeof(struct tty_driver));
 		driver->magic = TTY_DRIVER_MAGIC;
 		driver->num = lines;
 		/* later we'll move allocation of tables here */
Signature · 1 line
Jean Delvare
#1 lore raw

Hi Jean,

drivers/char/tty_io.c static int init_dev(struct tty_driver *d · line 2013

Quoted 3 lines · Jean Delvare
drivers/char/tty_io.c +1 -1
-               ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
+               ltp = (struct ktermios *) kzalloc(sizeof(struct ktermios),
                                                 GFP_KERNEL);

When doing conversions like this, please drop the redundant casts too.

#2 lore raw
Quoted 8 lines · Pekka Enberg

Hi Jean,

drivers/char/tty_io.c static int init_dev(struct tty_driver *d · line 2013

Quoted 3 lines · Jean Delvare
drivers/char/tty_io.c +1 -1
-               ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
+               ltp = (struct ktermios *) kzalloc(sizeof(struct ktermios),
                                                 GFP_KERNEL);

When doing conversions like this, please drop the redundant casts too.

Good point, sorry for overlooking this. Updated patch follows.

Signature · 1 line
Jean Delvare
#3 lore raw

PATCH v2 1/1 tty_io: Use kzalloc

Also remove needless casts.

---
 drivers/char/tty_io.c |   11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/char/tty_io.c +3 -8
@@ -2009,11 +2009,9 @@ static int init_dev(struct tty_driver *d
 	}
 
 	if (!*ltp_loc) {
-		ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
-						 GFP_KERNEL);
+		ltp = kzalloc(sizeof(struct ktermios), GFP_KERNEL);
 		if (!ltp)
 			goto free_mem_out;
-		memset(ltp, 0, sizeof(struct ktermios));
 	}
 
 	if (driver->type == TTY_DRIVER_TYPE_PTY) {
@@ -2042,11 +2040,9 @@ static int init_dev(struct tty_driver *d
 		}
 
 		if (!*o_ltp_loc) {
-			o_ltp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+			o_ltp = kzalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_ltp)
 				goto free_mem_out;
-			memset(o_ltp, 0, sizeof(struct ktermios));
 		}
 
 		/*
@@ -3732,9 +3728,8 @@ struct tty_driver *alloc_tty_driver(int 
 {
 	struct tty_driver *driver;
 
-	driver = kmalloc(sizeof(struct tty_driver), GFP_KERNEL);
+	driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL);
 	if (driver) {
-		memset(driver, 0, sizeof(struct tty_driver));
 		driver->magic = TTY_DRIVER_MAGIC;
 		driver->num = lines;
 		/* later we'll move allocation of tables here */
Signature · 1 line
Jean Delvare
#4 lore raw
In reply to Jean Delvare
Quoted 25 lines · Jean Delvare

---
Andrew, can you please pick this? I couldn't find any maintainer for this driver. Thanks.

 drivers/char/tty_io.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/char/tty_io.c +1 -2
@@ -2009,11 +2009,10 @@ static int init_dev(struct tty_driver *d
 	}
 
 	if (!*ltp_loc) {
-		ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
+		ltp = (struct ktermios *) kzalloc(sizeof(struct ktermios),
 						 GFP_KERNEL);
 		if (!ltp)
 			goto free_mem_out;
-		memset(ltp, 0, sizeof(struct ktermios));
 	}
 
 	if (driver->type == TTY_DRIVER_TYPE_PTY) {
@@ -2043,10 +2042,9 @@ static int init_dev(struct tty_driver *d
 

drivers/char/tty_io.c static int init_dev(struct tty_driver *d · line 2050

Quoted 10 lines
drivers/char/tty_io.c +1 -2
 		if (!*o_ltp_loc) {
 			o_ltp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+				kzalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_ltp)
 				goto free_mem_out;
-			memset(o_ltp, 0, sizeof(struct ktermios));
 		}
 
 		/*

i believe you can drop the casts from those calls to kzalloc(), no?

rday

Signature · 7 lines
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://fsdev.net/wiki/index.php?title=Main_Page
========================================================================