summaryrefslogtreecommitdiff
path: root/drivers/media/platform/coda/coda-jpeg.c
diff options
context:
space:
mode:
authorPhilipp Zabel <p.zabel@pengutronix.de>2014-10-08 20:09:27 +0400
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2014-10-28 20:41:07 +0300
commitedc16cb1159c03864c74fd0411ec5d0bcce845be (patch)
tree155809aa32a8723a91928e709f174162ab3f31c9 /drivers/media/platform/coda/coda-jpeg.c
parentd4bb75f6eee2f9cd7dc0787e3a8fb6bb3e430802 (diff)
downloadlinux-edc16cb1159c03864c74fd0411ec5d0bcce845be.tar.xz
[media] coda: drop JPEG buffers not framed by SOI and EOI markers
This patch adds a quick check for valid JPEG frames before feeding them into the bitstream buffer: Frames that do not begin with the JPEG start of image marker and end with the end of image marker are dropped. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Kamil Debski <k.debski@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/platform/coda/coda-jpeg.c')
-rw-r--r--drivers/media/platform/coda/coda-jpeg.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/media/platform/coda/coda-jpeg.c b/drivers/media/platform/coda/coda-jpeg.c
index 967b0159c8b9..8fa3e353f9e2 100644
--- a/drivers/media/platform/coda/coda-jpeg.c
+++ b/drivers/media/platform/coda/coda-jpeg.c
@@ -14,6 +14,9 @@
#include "coda.h"
+#define SOI_MARKER 0xffd8
+#define EOI_MARKER 0xffd9
+
/*
* Typical Huffman tables for 8-bit precision luminance and
* chrominance from JPEG ITU-T.81 (ISO/IEC 10918-1) Annex K.3
@@ -174,6 +177,16 @@ int coda_jpeg_write_tables(struct coda_ctx *ctx)
return 0;
}
+bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_buffer *vb)
+{
+ void *vaddr = vb2_plane_vaddr(vb, 0);
+ u16 soi = be16_to_cpup((__be16 *)vaddr);
+ u16 eoi = be16_to_cpup((__be16 *)(vaddr +
+ vb2_get_plane_payload(vb, 0) - 2));
+
+ return soi == SOI_MARKER && eoi == EOI_MARKER;
+}
+
/*
* Scale quantization table using nonlinear scaling factor
* u8 qtab[64], scale [50,190]