diff options
author | Johan Hovold <jhovold@gmail.com> | 2013-08-13 07:27:38 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-08-14 16:51:02 -0400 |
commit | 0448067150dc1e4034b018da253b0ed1c57d16c9 (patch) | |
tree | d153fbeecc15db544d849d77bebb370d16fde42c /drivers/usb/serial | |
parent | bad41a5bf1775cdf6026d5a1b233bdc4853f27ca (diff) |
USB: quatech2: fix serial DMA-buffer allocations
Make sure serial DMA-buffers are allocated separately from containing
structure to prevent potential memory corruption on non-cache-coherent
systems.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/serial')
-rw-r--r-- | drivers/usb/serial/quatech2.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c index d99743290fc1..79c9b2be2edb 100644 --- a/drivers/usb/serial/quatech2.c +++ b/drivers/usb/serial/quatech2.c | |||
@@ -62,6 +62,7 @@ | |||
62 | #define MAX_BAUD_RATE 921600 | 62 | #define MAX_BAUD_RATE 921600 |
63 | #define DEFAULT_BAUD_RATE 9600 | 63 | #define DEFAULT_BAUD_RATE 9600 |
64 | 64 | ||
65 | #define QT2_READ_BUFFER_SIZE 512 /* size of read buffer */ | ||
65 | #define QT2_WRITE_BUFFER_SIZE 512 /* size of write buffer */ | 66 | #define QT2_WRITE_BUFFER_SIZE 512 /* size of write buffer */ |
66 | #define QT2_WRITE_CONTROL_SIZE 5 /* control bytes used for a write */ | 67 | #define QT2_WRITE_CONTROL_SIZE 5 /* control bytes used for a write */ |
67 | 68 | ||
@@ -112,7 +113,7 @@ struct qt2_serial_private { | |||
112 | unsigned char current_port; /* current port for incoming data */ | 113 | unsigned char current_port; /* current port for incoming data */ |
113 | 114 | ||
114 | struct urb *read_urb; /* shared among all ports */ | 115 | struct urb *read_urb; /* shared among all ports */ |
115 | char read_buffer[512]; | 116 | char *read_buffer; |
116 | }; | 117 | }; |
117 | 118 | ||
118 | struct qt2_port_private { | 119 | struct qt2_port_private { |
@@ -142,6 +143,7 @@ static void qt2_release(struct usb_serial *serial) | |||
142 | serial_priv = usb_get_serial_data(serial); | 143 | serial_priv = usb_get_serial_data(serial); |
143 | 144 | ||
144 | usb_free_urb(serial_priv->read_urb); | 145 | usb_free_urb(serial_priv->read_urb); |
146 | kfree(serial_priv->read_buffer); | ||
145 | kfree(serial_priv); | 147 | kfree(serial_priv); |
146 | } | 148 | } |
147 | 149 | ||
@@ -683,7 +685,7 @@ static int qt2_setup_urbs(struct usb_serial *serial) | |||
683 | usb_rcvbulkpipe(serial->dev, | 685 | usb_rcvbulkpipe(serial->dev, |
684 | port0->bulk_in_endpointAddress), | 686 | port0->bulk_in_endpointAddress), |
685 | serial_priv->read_buffer, | 687 | serial_priv->read_buffer, |
686 | sizeof(serial_priv->read_buffer), | 688 | QT2_READ_BUFFER_SIZE, |
687 | qt2_read_bulk_callback, serial); | 689 | qt2_read_bulk_callback, serial); |
688 | 690 | ||
689 | status = usb_submit_urb(serial_priv->read_urb, GFP_KERNEL); | 691 | status = usb_submit_urb(serial_priv->read_urb, GFP_KERNEL); |
@@ -718,6 +720,12 @@ static int qt2_attach(struct usb_serial *serial) | |||
718 | return -ENOMEM; | 720 | return -ENOMEM; |
719 | } | 721 | } |
720 | 722 | ||
723 | serial_priv->read_buffer = kmalloc(QT2_READ_BUFFER_SIZE, GFP_KERNEL); | ||
724 | if (!serial_priv->read_buffer) { | ||
725 | status = -ENOMEM; | ||
726 | goto err_buf; | ||
727 | } | ||
728 | |||
721 | usb_set_serial_data(serial, serial_priv); | 729 | usb_set_serial_data(serial, serial_priv); |
722 | 730 | ||
723 | status = qt2_setup_urbs(serial); | 731 | status = qt2_setup_urbs(serial); |
@@ -727,6 +735,8 @@ static int qt2_attach(struct usb_serial *serial) | |||
727 | return 0; | 735 | return 0; |
728 | 736 | ||
729 | attach_failed: | 737 | attach_failed: |
738 | kfree(serial_priv->read_buffer); | ||
739 | err_buf: | ||
730 | kfree(serial_priv); | 740 | kfree(serial_priv); |
731 | return status; | 741 | return status; |
732 | } | 742 | } |