Commit cb7f00ba authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

greybus: uart: add missing serial-state sanity check

Add dedicated serial-state request handler and add the missing sanity
check on the incoming request.
Reviewed-by: default avatarRui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Reviewed-by: default avatarBryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 066f950c
...@@ -103,13 +103,32 @@ static int gb_uart_receive_data(struct gb_tty *gb_tty, ...@@ -103,13 +103,32 @@ static int gb_uart_receive_data(struct gb_tty *gb_tty,
return 0; return 0;
} }
static int gb_uart_request_recv(u8 type, struct gb_operation *op) static int gb_uart_serial_state_handler(struct gb_operation *op)
{ {
struct gb_connection *connection = op->connection; struct gb_connection *connection = op->connection;
struct gb_tty *gb_tty = connection->private; struct gb_tty *gb_tty = connection->private;
struct gb_message *request = op->request; struct gb_message *request = op->request;
struct gb_uart_serial_state_request *serial_state; struct gb_uart_serial_state_request *serial_state;
int ret = 0;
if (request->payload_size < sizeof(*serial_state)) {
dev_err(&connection->bundle->dev,
"short serial-state event received (%zu < %zu)\n",
request->payload_size, sizeof(*serial_state));
return -EINVAL;
}
serial_state = request->payload;
gb_tty->ctrlin = serial_state->control;
return 0;
}
static int gb_uart_request_recv(u8 type, struct gb_operation *op)
{
struct gb_connection *connection = op->connection;
struct gb_tty *gb_tty = connection->private;
struct gb_message *request = op->request;
int ret;
switch (type) { switch (type) {
case GB_UART_TYPE_RECEIVE_DATA: case GB_UART_TYPE_RECEIVE_DATA:
...@@ -117,8 +136,7 @@ static int gb_uart_request_recv(u8 type, struct gb_operation *op) ...@@ -117,8 +136,7 @@ static int gb_uart_request_recv(u8 type, struct gb_operation *op)
request->payload); request->payload);
break; break;
case GB_UART_TYPE_SERIAL_STATE: case GB_UART_TYPE_SERIAL_STATE:
serial_state = request->payload; ret = gb_uart_serial_state_handler(op);
gb_tty->ctrlin = serial_state->control;
break; break;
default: default:
dev_err(&connection->bundle->dev, dev_err(&connection->bundle->dev,
......
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