linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] USB: serial: iuu_phoenix: fix DMA from stack
@ 2021-01-04 14:50 Johan Hovold
  2021-01-04 14:57 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2021-01-04 14:50 UTC (permalink / raw)
  To: Johan Hovold; +Cc: linux-usb, Dan Carpenter, stable

Stack-allocated buffers cannot be used for DMA (on all architectures) so
allocate the flush command buffer using kmalloc().

Fixes: 60a8fc017103 ("USB: add iuu_phoenix driver")
Cc: stable <stable@vger.kernel.org>     # 2.6.25
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/iuu_phoenix.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index f1201d4de297..e8f06b41a503 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -532,23 +532,29 @@ static int iuu_uart_flush(struct usb_serial_port *port)
 	struct device *dev = &port->dev;
 	int i;
 	int status;
-	u8 rxcmd = IUU_UART_RX;
+	u8 *rxcmd;
 	struct iuu_private *priv = usb_get_serial_port_data(port);
 
 	if (iuu_led(port, 0xF000, 0, 0, 0xFF) < 0)
 		return -EIO;
 
+	rxcmd = kmalloc(1, GFP_KERNEL);
+	if (!rxcmd)
+		return -ENOMEM;
+
+	rxcmd[0] = IUU_UART_RX;
+
 	for (i = 0; i < 2; i++) {
-		status = bulk_immediate(port, &rxcmd, 1);
+		status = bulk_immediate(port, rxcmd, 1);
 		if (status != IUU_OPERATION_OK) {
 			dev_dbg(dev, "%s - uart_flush_write error\n", __func__);
-			return status;
+			goto out_free;
 		}
 
 		status = read_immediate(port, &priv->len, 1);
 		if (status != IUU_OPERATION_OK) {
 			dev_dbg(dev, "%s - uart_flush_read error\n", __func__);
-			return status;
+			goto out_free;
 		}
 
 		if (priv->len > 0) {
@@ -556,12 +562,16 @@ static int iuu_uart_flush(struct usb_serial_port *port)
 			status = read_immediate(port, priv->buf, priv->len);
 			if (status != IUU_OPERATION_OK) {
 				dev_dbg(dev, "%s - uart_flush_read error\n", __func__);
-				return status;
+				goto out_free;
 			}
 		}
 	}
 	dev_dbg(dev, "%s - uart_flush_read OK!\n", __func__);
 	iuu_led(port, 0, 0xF000, 0, 0xFF);
+
+out_free:
+	kfree(rxcmd);
+
 	return status;
 }
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: serial: iuu_phoenix: fix DMA from stack
  2021-01-04 14:50 [PATCH] USB: serial: iuu_phoenix: fix DMA from stack Johan Hovold
@ 2021-01-04 14:57 ` Greg KH
  2021-01-04 15:31   ` Johan Hovold
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2021-01-04 14:57 UTC (permalink / raw)
  To: Johan Hovold; +Cc: linux-usb, Dan Carpenter, stable

On Mon, Jan 04, 2021 at 03:50:07PM +0100, Johan Hovold wrote:
> Stack-allocated buffers cannot be used for DMA (on all architectures) so
> allocate the flush command buffer using kmalloc().
> 
> Fixes: 60a8fc017103 ("USB: add iuu_phoenix driver")
> Cc: stable <stable@vger.kernel.org>     # 2.6.25
> Signed-off-by: Johan Hovold <johan@kernel.org>

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: serial: iuu_phoenix: fix DMA from stack
  2021-01-04 14:57 ` Greg KH
@ 2021-01-04 15:31   ` Johan Hovold
  0 siblings, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2021-01-04 15:31 UTC (permalink / raw)
  To: Greg KH; +Cc: Johan Hovold, linux-usb, Dan Carpenter, stable

On Mon, Jan 04, 2021 at 03:57:51PM +0100, Greg Kroah-Hartman wrote:
> On Mon, Jan 04, 2021 at 03:50:07PM +0100, Johan Hovold wrote:
> > Stack-allocated buffers cannot be used for DMA (on all architectures) so
> > allocate the flush command buffer using kmalloc().
> > 
> > Fixes: 60a8fc017103 ("USB: add iuu_phoenix driver")
> > Cc: stable <stable@vger.kernel.org>     # 2.6.25
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> 
> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Thanks for reviewing. Now applied.

Johan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-04 15:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-04 14:50 [PATCH] USB: serial: iuu_phoenix: fix DMA from stack Johan Hovold
2021-01-04 14:57 ` Greg KH
2021-01-04 15:31   ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).