diff options
author | Johan Hovold <jhovold@gmail.com> | 2013-04-16 12:01:22 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-04-17 13:05:34 -0400 |
commit | a6c042f95031afbeb0b0fb77643bc9211a3f2e2e (patch) | |
tree | 8ba25be6478d618d1cfd5ae7c2e3a6375909a191 /drivers/usb/serial/omninet.c | |
parent | d91641b161594672242b3c5d8656ad3b2ef58f34 (diff) |
USB: omninet: refactor read-urb processing
Refactor read-urb processing, and add sanity checks on header and data
lengths.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/serial/omninet.c')
-rw-r--r-- | drivers/usb/serial/omninet.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c index 9dcaa7727de5..7aaf9692b334 100644 --- a/drivers/usb/serial/omninet.c +++ b/drivers/usb/serial/omninet.c | |||
@@ -158,11 +158,26 @@ static void omninet_close(struct usb_serial_port *port) | |||
158 | #define OMNINET_BULKOUTSIZE 64 | 158 | #define OMNINET_BULKOUTSIZE 64 |
159 | #define OMNINET_PAYLOADSIZE (OMNINET_BULKOUTSIZE - OMNINET_HEADERLEN) | 159 | #define OMNINET_PAYLOADSIZE (OMNINET_BULKOUTSIZE - OMNINET_HEADERLEN) |
160 | 160 | ||
161 | static void omninet_process_read_urb(struct urb *urb) | ||
162 | { | ||
163 | struct usb_serial_port *port = urb->context; | ||
164 | const struct omninet_header *hdr = urb->transfer_buffer; | ||
165 | const unsigned char *data; | ||
166 | size_t data_len; | ||
167 | |||
168 | if (urb->actual_length <= OMNINET_HEADERLEN || !hdr->oh_len) | ||
169 | return; | ||
170 | |||
171 | data = (char *)urb->transfer_buffer + OMNINET_HEADERLEN; | ||
172 | data_len = min_t(size_t, urb->actual_length - OMNINET_HEADERLEN, | ||
173 | hdr->oh_len); | ||
174 | tty_insert_flip_string(&port->port, data, data_len); | ||
175 | tty_flip_buffer_push(&port->port); | ||
176 | } | ||
177 | |||
161 | static void omninet_read_bulk_callback(struct urb *urb) | 178 | static void omninet_read_bulk_callback(struct urb *urb) |
162 | { | 179 | { |
163 | struct usb_serial_port *port = urb->context; | 180 | struct usb_serial_port *port = urb->context; |
164 | unsigned char *data = urb->transfer_buffer; | ||
165 | struct omninet_header *header = (struct omninet_header *) &data[0]; | ||
166 | int status = urb->status; | 181 | int status = urb->status; |
167 | int result; | 182 | int result; |
168 | 183 | ||
@@ -172,11 +187,7 @@ static void omninet_read_bulk_callback(struct urb *urb) | |||
172 | return; | 187 | return; |
173 | } | 188 | } |
174 | 189 | ||
175 | if (urb->actual_length && header->oh_len) { | 190 | omninet_process_read_urb(urb); |
176 | tty_insert_flip_string(&port->port, data + OMNINET_HEADERLEN, | ||
177 | header->oh_len); | ||
178 | tty_flip_buffer_push(&port->port); | ||
179 | } | ||
180 | 191 | ||
181 | /* Continue trying to always read */ | 192 | /* Continue trying to always read */ |
182 | result = usb_submit_urb(urb, GFP_ATOMIC); | 193 | result = usb_submit_urb(urb, GFP_ATOMIC); |