Skip to content

Commit

Permalink
media: staging: media: zoran: calculate the right buffer number for z…
Browse files Browse the repository at this point in the history
…oran_reap_stat_com

[ Upstream commit e3b86f4 ]

On the case tmp_dcim=1, the index of buffer is miscalculated.
This generate a NULL pointer dereference later.

So let's fix the calcul and add a check to prevent this to reappear.

Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
montjoie authored and gregkh committed Apr 8, 2022
1 parent 1e501ec commit 20811bb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/staging/media/zoran/zoran_device.c
Expand Up @@ -814,7 +814,7 @@ static void zoran_reap_stat_com(struct zoran *zr)
if (zr->jpg_settings.tmp_dcm == 1)
i = (zr->jpg_dma_tail - zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
else
i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2 + 1;
i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2;

stat_com = le32_to_cpu(zr->stat_com[i]);
if ((stat_com & 1) == 0) {
Expand All @@ -826,6 +826,11 @@ static void zoran_reap_stat_com(struct zoran *zr)
size = (stat_com & GENMASK(22, 1)) >> 1;

buf = zr->inuse[i];
if (!buf) {
spin_unlock_irqrestore(&zr->queued_bufs_lock, flags);
pci_err(zr->pci_dev, "No buffer at slot %d\n", i);
return;
}
buf->vbuf.vb2_buf.timestamp = ktime_get_ns();

if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
Expand Down

0 comments on commit 20811bb

Please sign in to comment.