diff mbox

[2/2] media: dvb_vb2: limit reqbufs size to a sane value

Message ID 250e67e6e82643336d047e41780fbb72dc33687d.1514466421.git.mchehab@s-opensource.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mauro Carvalho Chehab Dec. 28, 2017, 1:09 p.m. UTC
It is not a good idea to let users to request a very high buffer
size.

So, add an upper limit.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
---
 drivers/media/dvb-core/dvb_vb2.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox

Patch

diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c
index ccb99cfed2b3..d9fafeeb0d04 100644
--- a/drivers/media/dvb-core/dvb_vb2.c
+++ b/drivers/media/dvb-core/dvb_vb2.c
@@ -19,6 +19,8 @@ 
 #include "dvbdev.h"
 #include "dvb_vb2.h"
 
+#define DVB_V2_MAX_SIZE 	(4096 * 188)
+
 static int vb2_debug;
 module_param(vb2_debug, int, 0644);
 
@@ -330,6 +332,12 @@  int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, struct dmx_requestbuffers *req)
 {
 	int ret;
 
+	/* Adjust size to a sane value */
+	if (req->size > DVB_V2_MAX_SIZE)
+		req->size = DVB_V2_MAX_SIZE;
+
+	/* FIXME: round req->size to a 188 or 204 multiple */
+
 	ctx->buf_siz = req->size;
 	ctx->buf_cnt = req->count;
 	ret = vb2_core_reqbufs(&ctx->vb_q, VB2_MEMORY_MMAP, &req->count);