]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/video/pvrusb2/pvrusb2-ctrl.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6
[linux-2.6-omap-h63xx.git] / drivers / media / video / pvrusb2 / pvrusb2-ctrl.c
index f569b00201ddb09924e854cf84f4977795fee729..91a42f2473a7ff7718d163233c38e39b3efd3b5f 100644 (file)
@@ -30,6 +30,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;
@@ -60,16 +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) {
+                       } 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;
                        }
@@ -204,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",
@@ -265,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;
 }
 
 
@@ -410,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]);
@@ -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) {