summaryrefslogtreecommitdiff
path: root/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
diff options
context:
space:
mode:
authorMike Isely <isely@pobox.com>2006-12-27 20:28:54 -0600
committerMike Isely <isely@pobox.com>2006-12-27 20:28:54 -0600
commit77e20d6a82bf9fddc65869883b6a5b4c54e75ec2 (patch)
tree843824c7845bcb48dc2b00345ef45626754574e7 /linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
parent99f9ef930137ebd1f212ab52256394694fecfcdc (diff)
downloadmediapointer-dvb-s2-77e20d6a82bf9fddc65869883b6a5b4c54e75ec2.tar.gz
mediapointer-dvb-s2-77e20d6a82bf9fddc65869883b6a5b4c54e75ec2.tar.bz2
pvrusb2: Newer frequency range checking
From: Mike Isely <isely@pobox.com> Implement new method for doing integer range checking, so that we can more intelligently range-check radio and tv ranges at once. Signed-off-by: Mike Isely <isely@pobox.com>
Diffstat (limited to 'linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c')
-rw-r--r--linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
index 307e4d789..3bff4e8aa 100644
--- a/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
+++ b/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
@@ -31,6 +31,27 @@
#endif
+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 {
+ int lim;
+ lim = cptr->info->def.type_int.min_value;
+ if (cptr->info->get_min_value) {
+ cptr->info->get_min_value(cptr,&lim);
+ }
+ if (val < lim) return -ERANGE;
+ lim = cptr->info->def.type_int.max_value;
+ if (cptr->info->get_max_value) {
+ cptr->info->get_max_value(cptr,&lim);
+ }
+ if (val > lim) return -ERANGE;
+ }
+ return 0;
+}
+
+
/* Set the given control. */
int pvr2_ctrl_set_value(struct pvr2_ctrl *cptr,int val)
{
@@ -48,17 +69,8 @@ int pvr2_ctrl_set_mask_value(struct pvr2_ctrl *cptr,int mask,int val)
if (cptr->info->type == pvr2_ctl_bitmask) {
mask &= cptr->info->def.type_bitmask.valid_bits;
} else if (cptr->info->type == pvr2_ctl_int) {
- int lim;
- lim = cptr->info->def.type_int.min_value;
- if (cptr->info->get_min_value) {
- cptr->info->get_min_value(cptr,&lim);
- }
- if (val < lim) break;
- lim = cptr->info->def.type_int.max_value;
- if (cptr->info->get_max_value) {
- cptr->info->get_max_value(cptr,&lim);
- }
- if (val > lim) break;
+ 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;
@@ -504,18 +516,7 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr,
if (cptr->info->type == pvr2_ctl_int) {
ret = parse_token(ptr,len,valptr,NULL,0);
if (ret >= 0) {
- int min, max;
- min = cptr->info->def.type_int.min_value;
- if (cptr->info->get_min_value) {
- cptr->info->get_min_value(cptr,&min);
- }
- max = cptr->info->def.type_int.max_value;
- if (cptr->info->get_max_value) {
- cptr->info->get_max_value(cptr,&max);
- }
- if ((*valptr < min) || (*valptr > max)) {
- ret = -ERANGE;
- }
+ ret = pvr2_ctrl_range_check(cptr,*valptr);
}
if (maskptr) *maskptr = ~0;
} else if (cptr->info->type == pvr2_ctl_bool) {