diff options
Diffstat (limited to 'drivers/media/video/pvrusb2/pvrusb2-ctrl.c')
-rw-r--r-- | drivers/media/video/pvrusb2/pvrusb2-ctrl.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c index c77de859cc8e..f569b00201dd 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 | ||
29 | static 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. */ |
30 | int pvr2_ctrl_set_value(struct pvr2_ctrl *cptr,int val) | 51 | int 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; |
@@ -498,16 +510,13 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr, | |||
498 | LOCK_TAKE(cptr->hdw->big_lock); do { | 510 | LOCK_TAKE(cptr->hdw->big_lock); do { |
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 | ((*valptr < cptr->info->def.type_int.min_value) || | 514 | ret = pvr2_ctrl_range_check(cptr,*valptr); |
503 | (*valptr > cptr->info->def.type_int.max_value))) { | ||
504 | ret = -ERANGE; | ||
505 | } | 515 | } |
506 | if (maskptr) *maskptr = ~0; | 516 | if (maskptr) *maskptr = ~0; |
507 | } else if (cptr->info->type == pvr2_ctl_bool) { | 517 | } else if (cptr->info->type == pvr2_ctl_bool) { |
508 | ret = parse_token( | 518 | ret = parse_token(ptr,len,valptr,boolNames, |
509 | ptr,len,valptr,boolNames, | 519 | ARRAY_SIZE(boolNames)); |
510 | sizeof(boolNames)/sizeof(boolNames[0])); | ||
511 | if (ret == 1) { | 520 | if (ret == 1) { |
512 | *valptr = *valptr ? !0 : 0; | 521 | *valptr = *valptr ? !0 : 0; |
513 | } else if (ret == 0) { | 522 | } else if (ret == 0) { |