Skip to content

Commit 3dd6b56

Browse files
committed
media: Don't let tvp5150_get_vbi() go out of vbi_ram_default array
As pointed by Dan, possible values for bits[3:0] of te Line Mode Registers can range from 0x0 to 0xf, but the check logic allow values ranging from 0x0 to 0xe. As static arrays are initialized with zero, using a value without an explicit initializer at the array won't cause any harm. Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent fdbeb96 commit 3dd6b56

File tree

1 file changed

+45
-43
lines changed

1 file changed

+45
-43
lines changed

drivers/media/i2c/tvp5150.c

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -505,80 +505,77 @@ static struct i2c_vbi_ram_value vbi_ram_default[] =
505505
/* FIXME: Current api doesn't handle all VBI types, those not
506506
yet supported are placed under #if 0 */
507507
#if 0
508-
{0x010, /* Teletext, SECAM, WST System A */
508+
[0] = {0x010, /* Teletext, SECAM, WST System A */
509509
{V4L2_SLICED_TELETEXT_SECAM,6,23,1},
510510
{ 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
511511
0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
512512
},
513513
#endif
514-
{0x030, /* Teletext, PAL, WST System B */
514+
[1] = {0x030, /* Teletext, PAL, WST System B */
515515
{V4L2_SLICED_TELETEXT_B,6,22,1},
516516
{ 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
517517
0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
518518
},
519519
#if 0
520-
{0x050, /* Teletext, PAL, WST System C */
520+
[2] = {0x050, /* Teletext, PAL, WST System C */
521521
{V4L2_SLICED_TELETEXT_PAL_C,6,22,1},
522522
{ 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
523523
0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
524524
},
525-
{0x070, /* Teletext, NTSC, WST System B */
525+
[3] = {0x070, /* Teletext, NTSC, WST System B */
526526
{V4L2_SLICED_TELETEXT_NTSC_B,10,21,1},
527527
{ 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
528528
0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
529529
},
530-
{0x090, /* Tetetext, NTSC NABTS System C */
530+
[4] = {0x090, /* Tetetext, NTSC NABTS System C */
531531
{V4L2_SLICED_TELETEXT_NTSC_C,10,21,1},
532532
{ 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
533533
0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
534534
},
535-
{0x0b0, /* Teletext, NTSC-J, NABTS System D */
535+
[5] = {0x0b0, /* Teletext, NTSC-J, NABTS System D */
536536
{V4L2_SLICED_TELETEXT_NTSC_D,10,21,1},
537537
{ 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
538538
0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
539539
},
540-
{0x0d0, /* Closed Caption, PAL/SECAM */
540+
[6] = {0x0d0, /* Closed Caption, PAL/SECAM */
541541
{V4L2_SLICED_CAPTION_625,22,22,1},
542542
{ 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
543543
0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
544544
},
545545
#endif
546-
{0x0f0, /* Closed Caption, NTSC */
546+
[7] = {0x0f0, /* Closed Caption, NTSC */
547547
{V4L2_SLICED_CAPTION_525,21,21,1},
548548
{ 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
549549
0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
550550
},
551-
{0x110, /* Wide Screen Signal, PAL/SECAM */
551+
[8] = {0x110, /* Wide Screen Signal, PAL/SECAM */
552552
{V4L2_SLICED_WSS_625,23,23,1},
553553
{ 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
554554
0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
555555
},
556556
#if 0
557-
{0x130, /* Wide Screen Signal, NTSC C */
557+
[9] = {0x130, /* Wide Screen Signal, NTSC C */
558558
{V4L2_SLICED_WSS_525,20,20,1},
559559
{ 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
560560
0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
561561
},
562-
{0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
562+
[10] = {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
563563
{V4l2_SLICED_VITC_625,6,22,0},
564564
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
565565
0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
566566
},
567-
{0x170, /* Vertical Interval Timecode (VITC), NTSC */
567+
[11] = {0x170, /* Vertical Interval Timecode (VITC), NTSC */
568568
{V4l2_SLICED_VITC_525,10,20,0},
569569
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
570570
0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
571571
},
572572
#endif
573-
{0x190, /* Video Program System (VPS), PAL */
573+
[12] = {0x190, /* Video Program System (VPS), PAL */
574574
{V4L2_SLICED_VPS,16,16,0},
575575
{ 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
576576
0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
577577
},
578578
/* 0x1d0 User programmable */
579-
580-
/* End of struct */
581-
{ (u16)-1 }
582579
};
583580

584581
static int tvp5150_write_inittab(struct v4l2_subdev *sd,
@@ -591,10 +588,10 @@ static int tvp5150_write_inittab(struct v4l2_subdev *sd,
591588
return 0;
592589
}
593590

594-
static int tvp5150_vdp_init(struct v4l2_subdev *sd,
595-
const struct i2c_vbi_ram_value *regs)
591+
static int tvp5150_vdp_init(struct v4l2_subdev *sd)
596592
{
597593
unsigned int i;
594+
int j;
598595

599596
/* Disable Full Field */
600597
tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0);
@@ -604,14 +601,17 @@ static int tvp5150_vdp_init(struct v4l2_subdev *sd,
604601
tvp5150_write(sd, i, 0xff);
605602

606603
/* Load Ram Table */
607-
while (regs->reg != (u16)-1) {
604+
for (j = 0; j < ARRAY_SIZE(vbi_ram_default); j++) {
605+
const struct i2c_vbi_ram_value *regs = &vbi_ram_default[j];
606+
607+
if (!regs->type.vbi_type)
608+
continue;
609+
608610
tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_HIGH, regs->reg >> 8);
609611
tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_LOW, regs->reg);
610612

611613
for (i = 0; i < 16; i++)
612614
tvp5150_write(sd, TVP5150_VDP_CONF_RAM_DATA, regs->values[i]);
613-
614-
regs++;
615615
}
616616
return 0;
617617
}
@@ -620,19 +620,23 @@ static int tvp5150_vdp_init(struct v4l2_subdev *sd,
620620
static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd,
621621
struct v4l2_sliced_vbi_cap *cap)
622622
{
623-
const struct i2c_vbi_ram_value *regs = vbi_ram_default;
624-
int line;
623+
int line, i;
625624

626625
dev_dbg_lvl(sd->dev, 1, debug, "g_sliced_vbi_cap\n");
627626
memset(cap, 0, sizeof *cap);
628627

629-
while (regs->reg != (u16)-1 ) {
630-
for (line=regs->type.ini_line;line<=regs->type.end_line;line++) {
628+
for (i = 0; i < ARRAY_SIZE(vbi_ram_default); i++) {
629+
const struct i2c_vbi_ram_value *regs = &vbi_ram_default[i];
630+
631+
if (!regs->type.vbi_type)
632+
continue;
633+
634+
for (line = regs->type.ini_line;
635+
line <= regs->type.end_line;
636+
line++) {
631637
cap->service_lines[0][line] |= regs->type.vbi_type;
632638
}
633639
cap->service_set |= regs->type.vbi_type;
634-
635-
regs++;
636640
}
637641
return 0;
638642
}
@@ -651,14 +655,13 @@ static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd,
651655
* MSB = field2
652656
*/
653657
static int tvp5150_set_vbi(struct v4l2_subdev *sd,
654-
const struct i2c_vbi_ram_value *regs,
655658
unsigned int type,u8 flags, int line,
656659
const int fields)
657660
{
658661
struct tvp5150 *decoder = to_tvp5150(sd);
659662
v4l2_std_id std = decoder->norm;
660663
u8 reg;
661-
int pos = 0;
664+
int i, pos = 0;
662665

663666
if (std == V4L2_STD_ALL) {
664667
dev_err(sd->dev, "VBI can't be configured without knowing number of lines\n");
@@ -671,19 +674,19 @@ static int tvp5150_set_vbi(struct v4l2_subdev *sd,
671674
if (line < 6 || line > 27)
672675
return 0;
673676

674-
while (regs->reg != (u16)-1) {
677+
for (i = 0; i < ARRAY_SIZE(vbi_ram_default); i++) {
678+
const struct i2c_vbi_ram_value *regs = &vbi_ram_default[i];
679+
680+
if (!regs->type.vbi_type)
681+
continue;
682+
675683
if ((type & regs->type.vbi_type) &&
676684
(line >= regs->type.ini_line) &&
677685
(line <= regs->type.end_line))
678686
break;
679-
680-
regs++;
681687
pos++;
682688
}
683689

684-
if (regs->reg == (u16)-1)
685-
return 0;
686-
687690
type = pos | (flags & 0xf0);
688691
reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI;
689692

@@ -696,8 +699,7 @@ static int tvp5150_set_vbi(struct v4l2_subdev *sd,
696699
return type;
697700
}
698701

699-
static int tvp5150_get_vbi(struct v4l2_subdev *sd,
700-
const struct i2c_vbi_ram_value *regs, int line)
702+
static int tvp5150_get_vbi(struct v4l2_subdev *sd, int line)
701703
{
702704
struct tvp5150 *decoder = to_tvp5150(sd);
703705
v4l2_std_id std = decoder->norm;
@@ -726,8 +728,8 @@ static int tvp5150_get_vbi(struct v4l2_subdev *sd,
726728
return 0;
727729
}
728730
pos = ret & 0x0f;
729-
if (pos < 0x0f)
730-
type |= regs[pos].type.vbi_type;
731+
if (pos < ARRAY_SIZE(vbi_ram_default))
732+
type |= vbi_ram_default[pos].type.vbi_type;
731733
}
732734

733735
return type;
@@ -788,7 +790,7 @@ static int tvp5150_reset(struct v4l2_subdev *sd, u32 val)
788790
tvp5150_write_inittab(sd, tvp5150_init_default);
789791

790792
/* Initializes VDP registers */
791-
tvp5150_vdp_init(sd, vbi_ram_default);
793+
tvp5150_vdp_init(sd);
792794

793795
/* Selects decoder input */
794796
tvp5150_selmux(sd);
@@ -1121,8 +1123,8 @@ static int tvp5150_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_f
11211123
for (i = 0; i <= 23; i++) {
11221124
svbi->service_lines[1][i] = 0;
11231125
svbi->service_lines[0][i] =
1124-
tvp5150_set_vbi(sd, vbi_ram_default,
1125-
svbi->service_lines[0][i], 0xf0, i, 3);
1126+
tvp5150_set_vbi(sd, svbi->service_lines[0][i],
1127+
0xf0, i, 3);
11261128
}
11271129
/* Enables FIFO */
11281130
tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 1);
@@ -1148,7 +1150,7 @@ static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_f
11481150

11491151
for (i = 0; i <= 23; i++) {
11501152
svbi->service_lines[0][i] =
1151-
tvp5150_get_vbi(sd, vbi_ram_default, i);
1153+
tvp5150_get_vbi(sd, i);
11521154
mask |= svbi->service_lines[0][i];
11531155
}
11541156
svbi->service_set = mask;

0 commit comments

Comments
 (0)