[PATCH 2/2] media: s2255: advance marker pointer and use unaligned reads in save_frame
From: Elkin Cruz
Date: Wed Nov 25 2026 - 17:22:21 EST
In save_frame(), pdword was initialized once from transfer_buffer before
the marker-search loop and never updated as jj incremented, repeatedly
inspecting offset 0 instead of scanning through the transfer buffer.
Derive pdata from pipe_info->transfer_buffer + jj on each iteration and
read the 32-bit little-endian marker and header fields via get_unaligned()
and get_unaligned_le32() since jj advances one byte at a time.
Fixes: 3fa0060526ea ("V4L/DVB: s2255drv: fixes for big endian arch")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Elkin Cruz <elkin@xxxxxxxxxx>
---
drivers/media/usb/s2255/s2255drv.c | 34 ++++++++++++++++--------------
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index 9ddc13c99a81..9b6979c811e2 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -31,6 +31,7 @@
#include <linux/videodev2.h>
#include <linux/mm.h>
#include <linux/vmalloc.h>
+#include <linux/unaligned.h>
#include <linux/usb.h>
#include <media/videobuf2-v4l2.h>
#include <media/videobuf2-vmalloc.h>
@@ -1716,23 +1717,24 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
if (frm->state == S2255_READ_IDLE) {
u32 jj;
unsigned int cc;
- __le32 *pdword; /*data from dsp is little endian */
- int payload;
+ u32 payload;
if (pipe_info->cur_transfer_size < 20)
return -EINVAL;
/* search for marker codes */
- pdata = pipe_info->transfer_buffer;
- pdword = (__le32 *)pdata;
for (jj = 0; jj <= (pipe_info->cur_transfer_size - 20); jj++) {
- switch (*pdword) {
+ __le32 marker, resp;
+
+ pdata = pipe_info->transfer_buffer + jj;
+ marker = get_unaligned((__le32 *)pdata);
+ switch (marker) {
case S2255_MARKER_FRAME:
dprintk(dev, 4, "marker @ offset: %u [%x %x]\n",
jj, pdata[0], pdata[1]);
offset = jj + PREFIX_SIZE;
bframe = 1;
- cc = le32_to_cpu(pdword[1]);
+ cc = get_unaligned_le32(pdata + 4);
if (cc >= MAX_CHANNELS) {
dprintk(dev, 0,
"bad channel\n");
@@ -1741,7 +1743,7 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
/* reverse it */
dev->cc = G_chnmap[cc];
vc = &dev->vc[dev->cc];
- payload = le32_to_cpu(pdword[3]);
+ payload = get_unaligned_le32(pdata + 12);
if (payload < PREFIX_SIZE ||
payload > vc->req_image_size) {
vc->bad_payload++;
@@ -1749,7 +1751,7 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
return -EINVAL;
}
vc->pkt_size = payload;
- vc->jpg_size = le32_to_cpu(pdword[4]);
+ vc->jpg_size = get_unaligned_le32(pdata + 16);
break;
case S2255_MARKER_RESPONSE:
if (pipe_info->cur_transfer_size - jj - 20 <
@@ -1757,14 +1759,15 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
jj = pipe_info->cur_transfer_size - 20;
else
jj += DEF_USB_BLOCK;
- pdata = pipe_info->transfer_buffer + jj;
- if (le32_to_cpu(pdword[1]) >= MAX_CHANNELS)
+ cc = get_unaligned_le32(pdata + 4);
+ if (cc >= MAX_CHANNELS)
break;
- cc = G_chnmap[le32_to_cpu(pdword[1])];
+ cc = G_chnmap[cc];
if (cc >= MAX_CHANNELS)
break;
vc = &dev->vc[cc];
- switch (pdword[2]) {
+ resp = get_unaligned((__le32 *)(pdata + 8));
+ switch (resp) {
case S2255_RESPONSE_SETMODE:
/* check if channel valid */
/* set mode ready */
@@ -1783,19 +1786,18 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
wake_up(&dev->fw_data->wait_fw);
break;
case S2255_RESPONSE_STATUS:
- vc->vidstatus = le32_to_cpu(pdword[3]);
+ vc->vidstatus =
+ get_unaligned_le32(pdata + 12);
vc->vidstatus_ready = 1;
wake_up(&vc->wait_vidstatus);
dprintk(dev, 5, "vstat %x chan %d\n",
- le32_to_cpu(pdword[3]), cc);
+ vc->vidstatus, cc);
break;
default:
pr_info("s2255 unknown resp\n");
}
- pdata++;
break;
default:
- pdata++;
break;
}
if (bframe)
--
2.56.1.839.g22a8290db9-goog