Skip to contentSkip to conversation

vb2: check for sane values from queue_setup

PATCH Superseded Johan Fjeldtvedt 2 participants 2 messages Sep 11, 2018

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vb2: check for sane values from queue_setup

Warn when driver sets 0 number of planes or 0 as plane sizes.

---
 drivers/media/common/videobuf2/videobuf2-core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/media/common/videobuf2/videobuf2-core.c +8 -0
index f32ec7342ef0..d3bc94477e6b 100644
@@ -662,6 +662,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 	unsigned int num_buffers, allocated_buffers, num_planes = 0;
 	unsigned plane_sizes[VB2_MAX_PLANES] = { };
 	int ret;
+	int i;
 
 	if (q->streaming) {
 		dprintk(1, "streaming active\n");
@@ -718,6 +719,13 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 	if (ret)
 		return ret;
 
+	/* Check that driver has set sane values */
+	WARN_ON(num_buffers == 0);
+
+	for (i = 0; i < num_buffers; i++) {
+		WARN_ON(plane_sizes[i] == 0);
+	}
+
 	/* Finally, allocate buffers and video memory */
 	allocated_buffers =
 		__vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes);
Signature · 1 line
2.17.1
#1 lore raw

Hi Johan,

Thank you for the patch, but I have some small comments:

Quoted 18 lines · Johan Fjeldtvedt

Warn when driver sets 0 number of planes or 0 as plane sizes.

---
 drivers/media/common/videobuf2/videobuf2-core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/media/common/videobuf2/videobuf2-core.c +1 -0
index f32ec7342ef0..d3bc94477e6b 100644
@@ -662,6 +662,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 	unsigned int num_buffers, allocated_buffers, num_planes = 0;
 	unsigned plane_sizes[VB2_MAX_PLANES] = { };
 	int ret;
+	int i;
 
 	if (q->streaming) {
 		dprintk(1, "streaming active\n");

drivers/media/common/videobuf2/videobuf2-core.c int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, · line 725

Quoted 7 lines
drivers/media/common/videobuf2/videobuf2-core.c +4 -0
@@ -718,6 +719,13 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 	if (ret)
 		return ret;
 
+	/* Check that driver has set sane values */
+	WARN_ON(num_buffers == 0);
+
+	for (i = 0; i < num_buffers; i++) {

Linux coding style is not to use curly brackets around single statements.

drivers/media/common/videobuf2/videobuf2-core.c int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, · line 726

Quoted 1 line
drivers/media/common/videobuf2/videobuf2-core.c +1 -0
+		WARN_ON(plane_sizes[i] == 0);

There is a general preference in the kernel to use !foo instead of 'foo == 0'

You can (and should) run the patch against checkpatch:

git diff | scripts/checkpatch.pl --strict

drivers/media/common/videobuf2/videobuf2-core.c int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, · line 731

Quoted 6 lines
drivers/media/common/videobuf2/videobuf2-core.c +2 -0
+	}
+
 	/* Finally, allocate buffers and video memory */
 	allocated_buffers =
 		__vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes);

Regards,

Hans