[PATCH 1/4] ark3116: Remove unnecessary kmalloc calls

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allocate memory on the stack instead of the heap, as only one byte is needed.

Signed-off-by: Mike McCormack <mikem@xxxxxxxxxx>
---
 drivers/usb/serial/ark3116.c |   42 ++++--------------------------------------
 1 files changed, 4 insertions(+), 38 deletions(-)

diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 131e61a..12d70e3 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -86,13 +86,7 @@ static inline void ARK3116_RCV_QUIET(struct usb_serial *serial,
 
 static int ark3116_attach(struct usb_serial *serial)
 {
-	char *buf;
-
-	buf = kmalloc(1, GFP_KERNEL);
-	if (!buf) {
-		dbg("error kmalloc -> out of mem?");
-		return -ENOMEM;
-	}
+	char buf[1];
 
 	if (is_irda(serial))
 		dbg("IrDA mode");
@@ -153,7 +147,6 @@ static int ark3116_attach(struct usb_serial *serial)
 	ARK3116_RCV(serial, 153, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
 	ARK3116_SND(serial, 154, 0xFE, 0x40, 0x0003, 0x0003);
 
-	kfree(buf);
 	return 0;
 }
 
@@ -176,7 +169,7 @@ static void ark3116_set_termios(struct tty_struct *tty,
 	unsigned int cflag = termios->c_cflag;
 	int baud;
 	int ark3116_baud;
-	char *buf;
+	char buf[1];
 	char config;
 
 	config = 0;
@@ -187,13 +180,6 @@ static void ark3116_set_termios(struct tty_struct *tty,
 	cflag = termios->c_cflag;
 	termios->c_cflag &= ~(CMSPAR|CRTSCTS);
 
-	buf = kmalloc(1, GFP_KERNEL);
-	if (!buf) {
-		dbg("error kmalloc");
-		*termios = *old_termios;
-		return;
-	}
-
 	/* set data bit count (8/7/6/5) */
 	if (cflag & CSIZE) {
 		switch (cflag & CSIZE) {
@@ -309,27 +295,17 @@ static void ark3116_set_termios(struct tty_struct *tty,
 		dbg("CRTSCTS not supported by chipset?!");
 
 	/* TEST ARK3116_SND(154, 0xFE, 0x40, 0xFFFF, 0x0006); */
-
-	kfree(buf);
-
-	return;
 }
 
 static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
 {
 	struct ktermios tmp_termios;
 	struct usb_serial *serial = port->serial;
-	char *buf;
+	char buf[1];
 	int result = 0;
 
 	dbg("%s - port %d", __func__, port->number);
 
-	buf = kmalloc(1, GFP_KERNEL);
-	if (!buf) {
-		dbg("error kmalloc -> out of mem?");
-		return -ENOMEM;
-	}
-
 	result = usb_serial_generic_open(tty, port);
 	if (result)
 		goto err_out;
@@ -364,7 +340,6 @@ static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
 		ark3116_set_termios(tty, port, &tmp_termios);
 
 err_out:
-	kfree(buf);
 
 	return result;
 }
@@ -406,7 +381,6 @@ static int ark3116_tiocmget(struct tty_struct *tty, struct file *file)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct usb_serial *serial = port->serial;
-	char *buf;
 	char temp;
 
 	/* seems like serial port status info (RTS, CTS, ...) is stored
@@ -415,16 +389,8 @@ static int ark3116_tiocmget(struct tty_struct *tty, struct file *file)
 	 * pcb connection point  7 = GND -> sets bit6 of response
 	 */
 
-	buf = kmalloc(1, GFP_KERNEL);
-	if (!buf) {
-		dbg("error kmalloc");
-		return -ENOMEM;
-	}
-
 	/* read register */
-	ARK3116_RCV_QUIET(serial, 0xFE, 0xC0, 0x0000, 0x0006, buf);
-	temp = buf[0];
-	kfree(buf);
+	ARK3116_RCV_QUIET(serial, 0xFE, 0xC0, 0x0000, 0x0006, &temp);
 
 	/* i do not really know if bit4=CTS and bit6=DSR... just a
 	 * quick guess!
-- 
1.5.6.5


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux