Skip to contentSkip to conversation

tvaudio: remove bogus check

PATCH In review Vitaly Wool 3 participants 4 messages Mar 2, 2009 – Mar 3, 2009 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tvaudio: remove bogus check

Hello Mauro,

below is the patch that removes the subaddr check against ARRAY_SIZE(chip->shadow.bytes).
Regardless of anything, the 'bytes' array is 64 bytes large so this check disables easy standard programming (TDA9874A_ESP) which has a number of 255 which is hardly the intended behavior.

As a matter of fact, we can think of separate check for this case like

	if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes) ||
	    subaddr != 0xFF) {
		... /* weird register, refuse */
	}

but I'm not sure if there are no other special cases so for now I suggest to just disable it.

drivers/media/video/tvaudio.c | 17 +----------------

1 file changed, 1 insertion(+), 16 deletions(-)
drivers/media/video/tvaudio.c +0 -0
Index: linux-next/drivers/media/video/tvaudio.c
===================================================================
@@ -169,13 +169,6 @@
			return -1;
		}
	} else {

- if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
- v4l2_info(sd,
- "Tried to access a non-existent register: %d\n",
- subaddr);
- return -EINVAL;
- }
-

		v4l2_dbg(1, debug, sd, "chip_write: reg%d=0x%x\n",
			subaddr, val);
		chip->shadow.bytes[subaddr+1] = val;
@@ -198,16 +191,8 @@
	if (mask != 0) {
		if (subaddr < 0) {
			val = (chip->shadow.bytes[1] & ~mask) | (val & mask);

- } else {
- if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
- v4l2_info(sd,
- "Tried to access a non-existent register: %d\n",
- subaddr);
- return -EINVAL;
- }
-
+ } else

			val = (chip->shadow.bytes[subaddr+1] & ~mask) | (val & mask);
-		}
	}
	return chip_write(chip, subaddr, val);
}

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#1 lore raw

Hello, Vitaly

Now the main development maillist of V4L is [email protected]. Posting to that maillist also helps patchwork.kernel.org to handle patches correctly.

Mauro, what is the status of [email protected]? Is that user maillist, or is it deprecated mail that should be disabled ?

Quoted 62 lines · Vitaly Wool

Hello Mauro,

below is the patch that removes the subaddr check against ARRAY_SIZE(chip->shadow.bytes). Regardless of anything, the 'bytes' array is 64 bytes large so this check disables easy standard programming (TDA9874A_ESP) which has a number of 255 which is hardly the intended behavior.

As a matter of fact, we can think of separate check for this case like

	if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes) ||
	    subaddr != 0xFF) {
		... /* weird register, refuse */
	}

but I'm not sure if there are no other special cases so for now I suggest to just disable it.

 drivers/media/video/tvaudio.c |   17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

Index: linux-next/drivers/media/video/tvaudio.c
===================================================================

drivers/media/video/tvaudio.c +1 -17
@@ -169,13 +169,6 @@
 			return -1;
 		}
 	} else {
-		if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
-			v4l2_info(sd,
-				"Tried to access a non-existent register: %d\n",
-				subaddr);
-			return -EINVAL;
-		}
-
 		v4l2_dbg(1, debug, sd, "chip_write: reg%d=0x%x\n",
 			subaddr, val);
 		chip->shadow.bytes[subaddr+1] = val;
@@ -198,16 +191,8 @@
 	if (mask != 0) {
 		if (subaddr < 0) {
 			val = (chip->shadow.bytes[1] & ~mask) | (val & mask);
-		} else {
-			if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
-				v4l2_info(sd,
-					"Tried to access a non-existent register: %d\n",
-					subaddr);
-				return -EINVAL;
-			}
-
+		} else
 			val = (chip->shadow.bytes[subaddr+1] & ~mask) | (val & mask);
-		}
 	}
 	return chip_write(chip, subaddr, val);
 }
 
 
--

video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

Signature · 6 lines
Best regards, Klimov Alexey

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
#2 lore raw
In reply to Vitaly Wool
Quoted 7 lines · On Mon, 02 Mar 2009 18:12:06 +0300 Vitaly Wool <[email protected]> wrote:

Hello Mauro,

below is the patch that removes the subaddr check against ARRAY_SIZE(chip->shadow.bytes). Regardless of anything, the 'bytes' array is 64 bytes large so this check disables easy standard programming (TDA9874A_ESP) which has a number of 255 which is hardly the intended behavior.

Quoted 7 lines

As a matter of fact, we can think of separate check for this case like

	if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes) ||
	    subaddr != 0xFF) {
		... /* weird register, refuse */
	}

but I'm not sure if there are no other special cases so for now I suggest to just disable it.

This patch is wrong, since it will allow the access of an inexistent position at the shadow array:

	chip->shadow.bytes[subaddr+1] = val;

The proper fix is to increase the size of the shadow.bytes array to properly handle the subaddr = 0xff. Something like:

-#define MAXREGS 64
+#define MAXREGS 256

Except for allocating a few more bytes, such patch won't have any other drawback.

Quoted 34 lines
 drivers/media/video/tvaudio.c |   17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

Index: linux-next/drivers/media/video/tvaudio.c
===================================================================

drivers/media/video/tvaudio.c +0 -11
@@ -169,13 +169,6 @@
 			return -1;
 		}
 	} else {
-		if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
-			v4l2_info(sd,
-				"Tried to access a non-existent register: %d\n",
-				subaddr);
-			return -EINVAL;
-		}
-
 		v4l2_dbg(1, debug, sd, "chip_write: reg%d=0x%x\n",
 			subaddr, val);
 		chip->shadow.bytes[subaddr+1] = val;
@@ -198,16 +191,8 @@
 	if (mask != 0) {
 		if (subaddr < 0) {
 			val = (chip->shadow.bytes[1] & ~mask) | (val & mask);
-		} else {
-			if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
-				v4l2_info(sd,
-					"Tried to access a non-existent register: %d\n",

drivers/media/video/tvaudio.c line 198

Quoted 10 lines
drivers/media/video/tvaudio.c +1 -5
-					subaddr);
-				return -EINVAL;
-			}
-
+		} else
 			val = (chip->shadow.bytes[subaddr+1] & ~mask) | (val & mask);
-		}
 	}
 	return chip_write(chip, subaddr, val);
 }

Cheers,
Mauro

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#3 lore raw

Hello Mauro,

Quoted 11 lines · Mauro Carvalho Chehab

This patch is wrong, since it will allow the access of an inexistent position at the shadow array:

	chip->shadow.bytes[subaddr+1] = val;

The proper fix is to increase the size of the shadow.bytes array to properly handle the subaddr = 0xff. Something like:

(quoted diff) +1 -1
-#define MAXREGS 64
+#define MAXREGS 256

Except for allocating a few more bytes, such patch won't have any other drawback.

agreed. Here's the update:

tvaudio.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/video/tvaudio.c +0 -0
Index: linux-next/drivers/media/video/tvaudio.c
===================================================================
@@ -54,7 +54,7 @@

/* ---------------------------------------------------------------------- */
/* our structs */

-#define MAXREGS 64
+#define MAXREGS 256

struct CHIPSTATE;
typedef int (*getvalue)(int);

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list