Skip to contentSkip to conversation

media: ttusb-budget: fix ttusb_cmd() buffer copy direction

PATCH New Kery Qi 1 participant 1 message Jan 8 Media (V4L/DVB)

lore
Share & tools
lore

Kery Qi

author
#0 lore raw

PATCH 1/1 media: ttusb-budget: fix ttusb_cmd() buffer copy direction

ttusb_cmd() is supposed to send the caller-provided command buffer to the device and optionally copy the device reply back to the caller.

The current code copies from ttusb->send_buf into the caller buffer, then sends ttusb->send_buf unchanged, and finally copies the reply into ttusb->send_buf. This corrupts the caller's command, can transmit stale send_buf contents, and prevents callers from receiving the reply data.

Swap the memcpy() directions: copy the outgoing command into send_buf before usb_bulk_msg(), and when len_result is requested, copy the reply from last_result back into the caller buffer.

This matches how existing callers build stack buffers for requests and expect those buffers to be filled with the response on return.

---
 drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c +2 -2
index 946c763281cf..f4ce519114d6 100644
@@ -149,7 +149,7 @@ static int ttusb_cmd(struct ttusb *ttusb, u8 *data, int len, int len_result)
 	if (debug >= 3)
 		dprintk("> %*ph\n", len, data);
 
-	memcpy(data, ttusb->send_buf, len);
+	memcpy(ttusb->send_buf, data, len);
 
 	err = usb_bulk_msg(ttusb->dev, ttusb->bulk_out_pipe,
 			   ttusb->send_buf, len, &actual_len, 1000);
@@ -178,7 +178,7 @@ static int ttusb_cmd(struct ttusb *ttusb, u8 *data, int len, int len_result)
 	}
 
 	if (len_result)
-		memcpy(ttusb->send_buf, ttusb->last_result, len_result);
+		memcpy(data, ttusb->last_result, len_result);
 
 err:
 	mutex_unlock(&ttusb->semusb);
Signature · 1 line
2.34.1