diff options
author | Mike Isely <isely@pobox.com> | 2008-02-03 15:16:43 -0600 |
---|---|---|
committer | Mike Isely <isely@pobox.com> | 2008-02-03 15:16:43 -0600 |
commit | 5d58c6ee93fb3a28009f441ec50991f7ab4e4e72 (patch) | |
tree | 64b79a4a03494edfe14000c3789defe44cd90fee | |
parent | fbd47589f48e72b36d80af60f452bae4d2887e07 (diff) | |
download | mediapointer-dvb-s2-5d58c6ee93fb3a28009f441ec50991f7ab4e4e72.tar.gz mediapointer-dvb-s2-5d58c6ee93fb3a28009f441ec50991f7ab4e4e72.tar.bz2 |
pvrusb2: Improve control validation for enumerations
From: Mike Isely <isely@pobox.com>
When an enumeration control is changed, the pvrusb2 driver assumed
that the enumeration values were continuous. That is no longer true;
this change allows for properly input validation even when not all
enumeration values are legal (which can happen with input selection
based on what the hardware supports).
Signed-off-by: Mike Isely <isely@pobox.com>
-rw-r--r-- | linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c index cdbd92ed0..32e43e9d1 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c @@ -35,6 +35,9 @@ static int pvr2_ctrl_range_check(struct pvr2_ctrl *cptr,int val) { if (cptr->info->check_value) { if (!cptr->info->check_value(cptr,val)) return -ERANGE; + } else if (cptr->info->type == pvr2_ctl_enum) { + if (val < 0) return -ERANGE; + if (val >= cptr->info->def.type_enum.count) return -ERANGE; } else { int lim; lim = cptr->info->def.type_int.min_value; @@ -68,13 +71,10 @@ int pvr2_ctrl_set_mask_value(struct pvr2_ctrl *cptr,int mask,int val) if (cptr->info->set_value != 0) { if (cptr->info->type == pvr2_ctl_bitmask) { mask &= cptr->info->def.type_bitmask.valid_bits; - } else if (cptr->info->type == pvr2_ctl_int) { + } else if ((cptr->info->type == pvr2_ctl_int)|| + (cptr->info->type == pvr2_ctl_enum)) { ret = pvr2_ctrl_range_check(cptr,val); if (ret < 0) break; - } else if (cptr->info->type == pvr2_ctl_enum) { - if (val >= cptr->info->def.type_enum.count) { - break; - } } else if (cptr->info->type != pvr2_ctl_bool) { break; } @@ -209,8 +209,7 @@ int pvr2_ctrl_get_valname(struct pvr2_ctrl *cptr,int val, if (cptr->info->type == pvr2_ctl_enum) { const char **names; names = cptr->info->def.type_enum.value_names; - if ((val >= 0) && - (val < cptr->info->def.type_enum.count)) { + if (pvr2_ctrl_range_check(cptr,val) == 0) { if (names[val]) { *blen = scnprintf( bptr,bmax,"%s", @@ -533,10 +532,8 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr, ptr,len,valptr, cptr->info->def.type_enum.value_names, cptr->info->def.type_enum.count); - if ((ret >= 0) && - ((*valptr < 0) || - (*valptr >= cptr->info->def.type_enum.count))) { - ret = -ERANGE; + if (ret >= 0) { + ret = pvr2_ctrl_range_check(cptr,*valptr); } if (maskptr) *maskptr = ~0; } else if (cptr->info->type == pvr2_ctl_bitmask) { |