aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
diff options
context:
space:
mode:
authorMike Isely <isely@pobox.com>2006-12-27 21:28:54 -0500
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-02-21 10:34:33 -0500
commit5549f54f46c2375761f42cd2741364316e3b2a13 (patch)
treebd4d19a7ba79824c4eb0d9c4f27c07b5a4acf82c /drivers/media/video/pvrusb2/pvrusb2-ctrl.c
parent2083230084cee50580ee730cd26669704f7939b9 (diff)
V4L/DVB (5050): Pvrusb2: Newer frequency range checking
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> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/pvrusb2/pvrusb2-ctrl.c')
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ctrl.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
index 5c9cf1523e23..f8f4e2f311ab 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
@@ -26,6 +26,27 @@
26#include <linux/mutex.h> 26#include <linux/mutex.h>
27 27
28 28
29static int pvr2_ctrl_range_check(struct pvr2_ctrl *cptr,int val)
30{
31 if (cptr->info->check_value) {
32 if (!cptr->info->check_value(cptr,val)) return -ERANGE;
33 } else {
34 int lim;
35 lim = cptr->info->def.type_int.min_value;
36 if (cptr->info->get_min_value) {
37 cptr->info->get_min_value(cptr,&lim);
38 }
39 if (val < lim) return -ERANGE;
40 lim = cptr->info->def.type_int.max_value;
41 if (cptr->info->get_max_value) {
42 cptr->info->get_max_value(cptr,&lim);
43 }
44 if (val > lim) return -ERANGE;
45 }
46 return 0;
47}
48
49
29/* Set the given control. */ 50/* Set the given control. */
30int pvr2_ctrl_set_value(struct pvr2_ctrl *cptr,int val) 51int pvr2_ctrl_set_value(struct pvr2_ctrl *cptr,int val)
31{ 52{
@@ -43,17 +64,8 @@ int pvr2_ctrl_set_mask_value(struct pvr2_ctrl *cptr,int mask,int val)
43 if (cptr->info->type == pvr2_ctl_bitmask) { 64 if (cptr->info->type == pvr2_ctl_bitmask) {
44 mask &= cptr->info->def.type_bitmask.valid_bits; 65 mask &= cptr->info->def.type_bitmask.valid_bits;
45 } else if (cptr->info->type == pvr2_ctl_int) { 66 } else if (cptr->info->type == pvr2_ctl_int) {
46 int lim; 67 ret = pvr2_ctrl_range_check(cptr,val);
47 lim = cptr->info->def.type_int.min_value; 68 if (ret < 0) break;
48 if (cptr->info->get_min_value) {
49 cptr->info->get_min_value(cptr,&lim);
50 }
51 if (val < lim) break;
52 lim = cptr->info->def.type_int.max_value;
53 if (cptr->info->get_max_value) {
54 cptr->info->get_max_value(cptr,&lim);
55 }
56 if (val > lim) break;
57 } else if (cptr->info->type == pvr2_ctl_enum) { 69 } else if (cptr->info->type == pvr2_ctl_enum) {
58 if (val >= cptr->info->def.type_enum.count) { 70 if (val >= cptr->info->def.type_enum.count) {
59 break; 71 break;
@@ -499,18 +511,7 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr,
499 if (cptr->info->type == pvr2_ctl_int) { 511 if (cptr->info->type == pvr2_ctl_int) {
500 ret = parse_token(ptr,len,valptr,NULL,0); 512 ret = parse_token(ptr,len,valptr,NULL,0);
501 if (ret >= 0) { 513 if (ret >= 0) {
502 int min, max; 514 ret = pvr2_ctrl_range_check(cptr,*valptr);
503 min = cptr->info->def.type_int.min_value;
504 if (cptr->info->get_min_value) {
505 cptr->info->get_min_value(cptr,&min);
506 }
507 max = cptr->info->def.type_int.max_value;
508 if (cptr->info->get_max_value) {
509 cptr->info->get_max_value(cptr,&max);
510 }
511 if ((*valptr < min) || (*valptr > max)) {
512 ret = -ERANGE;
513 }
514 } 515 }
515 if (maskptr) *maskptr = ~0; 516 if (maskptr) *maskptr = ~0;
516 } else if (cptr->info->type == pvr2_ctl_bool) { 517 } else if (cptr->info->type == pvr2_ctl_bool) {