Skip to contentSkip to conversation

Staging: cx25821: off by on in cx25821_vidioc_s_input()

PATCH Superseded Dan Carpenter 2 participants 5 messages Oct 7, 2011 – Oct 13, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: cx25821: off by on in cx25821_vidioc_s_input()

If "i" is 2 then when we call cx25821_video_mux() we'd end up going past the end of the cx25821_boards[dev->board]->input[].

The INPUT() macro obfuscates what's going on in that function so it's a bit hard to follow.

---
I don't have this hardware, so I can't actually test this. Please review this carefully.

drivers/staging/cx25821/cx25821-video.c +1 -1
index 084fc08..acd7c4b 100644
@@ -1312,7 +1312,7 @@ int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
 			return err;
 	}
 
-	if (i > 2) {
+	if (i >= 2) {
 		dprintk(1, "%s(): -EINVAL\n", __func__);
 		return -EINVAL;
 	}
#1 lore raw

Hi Dan,

Em 07-10-2011 10:26, Dan Carpenter escreveu:

Quoted 16 lines

If "i" is 2 then when we call cx25821_video_mux() we'd end up going past the end of the cx25821_boards[dev->board]->input[].

The INPUT() macro obfuscates what's going on in that function so it's a bit hard to follow.

---
I don't have this hardware, so I can't actually test this. Please review this carefully.

drivers/staging/cx25821/cx25821-video.c +0 -0
index 084fc08..acd7c4b 100644

drivers/staging/cx25821/cx25821-video.c int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i) · line 1315

Quoted 5 lines
drivers/staging/cx25821/cx25821-video.c +1 -1
@@ -1312,7 +1312,7 @@ int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
 			return err;
 	}
 
-	if (i > 2) {
+	if (i >= 2) {

It would be better to add a NUM_INPUT macro (or something like that, defined together with the INPUT macro) that would do an ARRAY_SIZE(cx25821_boards) and use it here, instead of a "2" magic number.

Thanks,
Mauro

Quoted 7 lines
drivers/staging/cx25821/cx25821-video.c +0 -1
 		dprintk(1, "%s(): -EINVAL\n", __func__);
 		return -EINVAL;
 	}
--

To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 6 lines · Mauro Carvalho Chehab

drivers/staging/cx25821/cx25821-video.c int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i) · line 1315

Quoted 2 lines
drivers/staging/cx25821/cx25821-video.c +1 -1
-	if (i > 2) {
+	if (i >= 2) {

It would be better to add a NUM_INPUT macro (or something like that, defined together with the INPUT macro) that would do an ARRAY_SIZE(cx25821_boards) and use it here, instead of a "2" magic number.

You're right. The hard coded 2 is not helpful... Why not just an:

	if (i >= ARRAY_SIZE(cx25821_boards)) {...

I'll send a patch to do that.

regards,
dan carpenter

#3 lore raw

Never mind. I figured out what you meant. I've fixed my patch and I will send v2 this evening.

regards,
dan carpenter

#4 lore raw

PATCH v2 1/1 Staging: cx25821: off by one in cx25821_vidioc_s_input()

In reply to Mauro Carvalho Chehab

If "i" is 2 then when we call cx25821_video_mux() we'd end up going past the end of the cx25821_boards[dev->board]->input[].

The INPUT() macro obfuscates what's going on in that function so it's a bit hard to follow. And as Mauro points out the hard coded 2 is not very helpful.

---
v2: Use a define instead of the hard coded number 2

drivers/staging/cx25821/cx25821-video.c +1 -1
index 084fc08..4d6907c 100644
@@ -1312,7 +1312,7 @@ int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
 			return err;
 	}
 
-	if (i > 2) {
+	if (i >= CX25821_NR_INPUT) {
 		dprintk(1, "%s(): -EINVAL\n", __func__);
 		return -EINVAL;
 	}
drivers/staging/cx25821/cx25821.h +2 -1
index db2615b..2d2d009 100644
@@ -98,6 +98,7 @@
 #define CX25821_BOARD_CONEXANT_ATHENA10 1
 #define MAX_VID_CHANNEL_NUM     12
 #define VID_CHANNEL_NUM 8
+#define CX25821_NR_INPUT 2
 
 struct cx25821_fmt {
 	char *name;
@@ -196,7 +197,7 @@ struct cx25821_board {
 	unsigned char radio_addr;
 
 	u32 clk_freq;
-	struct cx25821_input input[2];
+	struct cx25821_input input[CX25821_NR_INPUT];
 };
 
 struct cx25821_subid {