]> err.no Git - linux-2.6/blobdiff - drivers/media/video/pvrusb2/pvrusb2-ctrl.c
V4L/DVB (7779): pvrusb2-dvb: quiet down noise in kernel log for feed debug
[linux-2.6] / drivers / media / video / pvrusb2 / pvrusb2-ctrl.c
index 5c9cf1523e236a0b4e2b2f5752b62c36f8ab575c..91a42f2473a7ff7718d163233c38e39b3efd3b5f 100644 (file)
 #include <linux/mutex.h>
 
 
+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;
+               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)
 {
@@ -39,25 +63,13 @@ int pvr2_ctrl_set_mask_value(struct pvr2_ctrl *cptr,int mask,int val)
        int ret = 0;
        if (!cptr) return -EINVAL;
        LOCK_TAKE(cptr->hdw->big_lock); do {
-               if (cptr->info->set_value != 0) {
+               if (cptr->info->set_value) {
                        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;
-                       } else if (cptr->info->type == pvr2_ctl_enum) {
-                               if (val >= cptr->info->def.type_enum.count) {
-                                       break;
-                               }
+                       } 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_bool) {
                                break;
                        }
@@ -192,8 +204,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",
@@ -253,7 +264,7 @@ unsigned int pvr2_ctrl_get_v4lflags(struct pvr2_ctrl *cptr)
 int pvr2_ctrl_is_writable(struct pvr2_ctrl *cptr)
 {
        if (!cptr) return 0;
-       return cptr->info->set_value != 0;
+       return cptr->info->set_value != NULL;
 }
 
 
@@ -398,7 +409,7 @@ static int parse_mtoken(const char *ptr,unsigned int len,
        int msk;
        *valptr = 0;
        for (idx = 0, msk = 1; valid_bits; idx++, msk <<= 1) {
-               if (!msk & valid_bits) continue;
+               if (!(msk & valid_bits)) continue;
                valid_bits &= ~msk;
                if (!names[idx]) continue;
                slen = strlen(names[idx]);
@@ -499,24 +510,12 @@ 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) {
-                       ret = parse_token(
-                               ptr,len,valptr,boolNames,
-                               sizeof(boolNames)/sizeof(boolNames[0]));
+                       ret = parse_token(ptr,len,valptr,boolNames,
+                                         ARRAY_SIZE(boolNames));
                        if (ret == 1) {
                                *valptr = *valptr ? !0 : 0;
                        } else if (ret == 0) {
@@ -528,10 +527,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) {