aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/quatech2.c
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2013-08-13 07:27:39 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-14 16:51:02 -0400
commitcbf30a914e89883457512f01c6434f70e6d57d4d (patch)
tree5c8c15d42981e6b5f7583e78ca8586617abc024d /drivers/usb/serial/quatech2.c
parent0448067150dc1e4034b018da253b0ed1c57d16c9 (diff)
USB: quatech2: fix port 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/quatech2.c')
-rw-r--r--drivers/usb/serial/quatech2.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c
index 79c9b2be2edb..a24d59ae4032 100644
--- a/drivers/usb/serial/quatech2.c
+++ b/drivers/usb/serial/quatech2.c
@@ -122,7 +122,7 @@ struct qt2_port_private {
122 spinlock_t urb_lock; 122 spinlock_t urb_lock;
123 bool urb_in_use; 123 bool urb_in_use;
124 struct urb *write_urb; 124 struct urb *write_urb;
125 char write_buffer[QT2_WRITE_BUFFER_SIZE]; 125 char *write_buffer;
126 126
127 spinlock_t lock; 127 spinlock_t lock;
128 u8 shadowLSR; 128 u8 shadowLSR;
@@ -755,21 +755,29 @@ static int qt2_port_probe(struct usb_serial_port *port)
755 spin_lock_init(&port_priv->urb_lock); 755 spin_lock_init(&port_priv->urb_lock);
756 port_priv->port = port; 756 port_priv->port = port;
757 757
758 port_priv->write_buffer = kmalloc(QT2_WRITE_BUFFER_SIZE, GFP_KERNEL);
759 if (!port_priv->write_buffer)
760 goto err_buf;
761
758 port_priv->write_urb = usb_alloc_urb(0, GFP_KERNEL); 762 port_priv->write_urb = usb_alloc_urb(0, GFP_KERNEL);
759 if (!port_priv->write_urb) { 763 if (!port_priv->write_urb)
760 kfree(port_priv); 764 goto err_urb;
761 return -ENOMEM; 765
762 }
763 bEndpointAddress = serial->port[0]->bulk_out_endpointAddress; 766 bEndpointAddress = serial->port[0]->bulk_out_endpointAddress;
764 usb_fill_bulk_urb(port_priv->write_urb, serial->dev, 767 usb_fill_bulk_urb(port_priv->write_urb, serial->dev,
765 usb_sndbulkpipe(serial->dev, bEndpointAddress), 768 usb_sndbulkpipe(serial->dev, bEndpointAddress),
766 port_priv->write_buffer, 769 port_priv->write_buffer,
767 sizeof(port_priv->write_buffer), 770 QT2_WRITE_BUFFER_SIZE,
768 qt2_write_bulk_callback, port); 771 qt2_write_bulk_callback, port);
769 772
770 usb_set_serial_port_data(port, port_priv); 773 usb_set_serial_port_data(port, port_priv);
771 774
772 return 0; 775 return 0;
776err_urb:
777 kfree(port_priv->write_buffer);
778err_buf:
779 kfree(port_priv);
780 return -ENOMEM;
773} 781}
774 782
775static int qt2_port_remove(struct usb_serial_port *port) 783static int qt2_port_remove(struct usb_serial_port *port)
@@ -778,6 +786,7 @@ static int qt2_port_remove(struct usb_serial_port *port)
778 786
779 port_priv = usb_get_serial_port_data(port); 787 port_priv = usb_get_serial_port_data(port);
780 usb_free_urb(port_priv->write_urb); 788 usb_free_urb(port_priv->write_urb);
789 kfree(port_priv->write_buffer);
781 kfree(port_priv); 790 kfree(port_priv);
782 791
783 return 0; 792 return 0;