Commit dd1c64ed authored by Bryan O'Donoghue's avatar Bryan O'Donoghue Committed by Greg Kroah-Hartman

greybus: uart: kmalloc for send_data once only

Make kmalloc for the send buffer a one time alloc based on the MTU for
a given greybus link.

The write_room for an gb_operation_sync then will be the size of the
buffer we use for a single operation.
Signed-off-by: default avatarBryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 563bd79b
...@@ -42,6 +42,8 @@ struct gb_tty_line_coding { ...@@ -42,6 +42,8 @@ struct gb_tty_line_coding {
struct gb_tty { struct gb_tty {
struct tty_port port; struct tty_port port;
void *buffer;
u32 buffer_payload_max;
struct gb_connection *connection; struct gb_connection *connection;
u16 cport_id; u16 cport_id;
unsigned int minor; unsigned int minor;
...@@ -76,15 +78,13 @@ static int send_data(struct gb_tty *tty, u16 size, const u8 *data) ...@@ -76,15 +78,13 @@ static int send_data(struct gb_tty *tty, u16 size, const u8 *data)
if (!data || !size) if (!data || !size)
return 0; return 0;
request = kmalloc(sizeof(*request) + size, GFP_KERNEL); if (size > tty->buffer_payload_max)
if (!request) size = tty->buffer_payload_max;
return -ENOMEM; request = tty->buffer;
request->size = cpu_to_le16(size); request->size = cpu_to_le16(size);
memcpy(&request->data[0], data, size); memcpy(&request->data[0], data, size);
ret = gb_operation_sync(tty->connection, GB_UART_TYPE_SEND_DATA, ret = gb_operation_sync(tty->connection, GB_UART_TYPE_SEND_DATA,
request, sizeof(*request) + size, NULL, 0); request, sizeof(*request) + size, NULL, 0);
kfree(request);
if (ret) if (ret)
return ret; return ret;
else else
...@@ -227,17 +227,13 @@ static int gb_tty_write(struct tty_struct *tty, const unsigned char *buf, ...@@ -227,17 +227,13 @@ static int gb_tty_write(struct tty_struct *tty, const unsigned char *buf,
static int gb_tty_write_room(struct tty_struct *tty) static int gb_tty_write_room(struct tty_struct *tty)
{ {
// struct gb_tty *gb_tty = tty->driver_data; struct gb_tty *gb_tty = tty->driver_data;
// FIXME - how much do we want to say we have room for? return gb_tty->buffer_payload_max;
return 0;
} }
static int gb_tty_chars_in_buffer(struct tty_struct *tty) static int gb_tty_chars_in_buffer(struct tty_struct *tty)
{ {
// struct gb_tty *gb_tty = tty->driver_data;
// FIXME - how many left to send?
return 0; return 0;
} }
...@@ -549,6 +545,19 @@ static int gb_uart_connection_init(struct gb_connection *connection) ...@@ -549,6 +545,19 @@ static int gb_uart_connection_init(struct gb_connection *connection)
if (!gb_tty) if (!gb_tty)
return -ENOMEM; return -ENOMEM;
gb_tty->buffer_payload_max =
gb_operation_get_payload_size_max(connection);
if (!gb_tty->buffer_payload_max) {
kfree(gb_tty);
return -EINVAL;
}
gb_tty->buffer = kzalloc(gb_tty->buffer_payload_max, GFP_KERNEL);
if (!gb_tty->buffer) {
kfree(gb_tty);
return -ENOMEM;
}
gb_tty->connection = connection; gb_tty->connection = connection;
connection->private = gb_tty; connection->private = gb_tty;
...@@ -600,6 +609,7 @@ static int gb_uart_connection_init(struct gb_connection *connection) ...@@ -600,6 +609,7 @@ static int gb_uart_connection_init(struct gb_connection *connection)
release_minor(gb_tty); release_minor(gb_tty);
error_version: error_version:
connection->private = NULL; connection->private = NULL;
kfree(gb_tty->buffer);
kfree(gb_tty); kfree(gb_tty);
return retval; return retval;
} }
...@@ -632,6 +642,7 @@ static void gb_uart_connection_exit(struct gb_connection *connection) ...@@ -632,6 +642,7 @@ static void gb_uart_connection_exit(struct gb_connection *connection)
tty_port_put(&gb_tty->port); tty_port_put(&gb_tty->port);
tty_port_destroy(&gb_tty->port); tty_port_destroy(&gb_tty->port);
kfree(gb_tty->buffer);
kfree(gb_tty); kfree(gb_tty);
/* If last device is gone, tear down the tty structures */ /* If last device is gone, tear down the tty structures */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment