Lines Matching +full:cluster +full:- +full:index

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2010-2021 Hans Verkuil <hverkuil-cisco@xs4all.nl>
8 #define pr_fmt(fmt) "v4l2-ctrls: " fmt
13 #include <media/v4l2-ctrls.h>
14 #include <media/v4l2-dev.h>
15 #include <media/v4l2-device.h>
16 #include <media/v4l2-event.h>
17 #include <media/v4l2-ioctl.h>
19 #include "v4l2-ctrls-priv.h"
28 * v4l2_ext_control index of the next control belonging to the
29 * same cluster, or 0 if there isn't any.
46 if (ctrl->is_ptr && !ctrl->is_string) in ptr_to_user()
47 return copy_to_user(c->ptr, ptr.p_const, c->size) ? in ptr_to_user()
48 -EFAULT : 0; in ptr_to_user()
50 switch (ctrl->type) { in ptr_to_user()
53 if (c->size < len + 1) { in ptr_to_user()
54 c->size = ctrl->elem_size; in ptr_to_user()
55 return -ENOSPC; in ptr_to_user()
57 return copy_to_user(c->string, ptr.p_char, len + 1) ? in ptr_to_user()
58 -EFAULT : 0; in ptr_to_user()
60 c->value64 = *ptr.p_s64; in ptr_to_user()
63 c->value = *ptr.p_s32; in ptr_to_user()
72 return ptr_to_user(c, ctrl, ctrl->p_cur); in cur_to_user()
79 return ptr_to_user(c, ctrl, ctrl->p_new); in new_to_user()
86 return ptr_to_user(c, ref->ctrl, ref->p_req); in req_to_user()
92 ctrl->type_ops->init(ctrl, 0, ctrl->p_new); in def_to_user()
94 return ptr_to_user(c, ctrl, ctrl->p_new); in def_to_user()
97 /* Helper function: copy the caller-provider value as the new control value */
103 ctrl->is_new = 0; in user_to_new()
104 if (ctrl->is_dyn_array && in user_to_new()
105 c->size > ctrl->p_array_alloc_elems * ctrl->elem_size) { in user_to_new()
106 void *old = ctrl->p_array; in user_to_new()
107 void *tmp = kvzalloc(2 * c->size, GFP_KERNEL); in user_to_new()
110 return -ENOMEM; in user_to_new()
111 memcpy(tmp, ctrl->p_new.p, ctrl->elems * ctrl->elem_size); in user_to_new()
112 memcpy(tmp + c->size, ctrl->p_cur.p, ctrl->elems * ctrl->elem_size); in user_to_new()
113 ctrl->p_new.p = tmp; in user_to_new()
114 ctrl->p_cur.p = tmp + c->size; in user_to_new()
115 ctrl->p_array = tmp; in user_to_new()
116 ctrl->p_array_alloc_elems = c->size / ctrl->elem_size; in user_to_new()
120 if (ctrl->is_ptr && !ctrl->is_string) { in user_to_new()
121 unsigned int elems = c->size / ctrl->elem_size; in user_to_new()
123 if (copy_from_user(ctrl->p_new.p, c->ptr, c->size)) in user_to_new()
124 return -EFAULT; in user_to_new()
125 ctrl->is_new = 1; in user_to_new()
126 if (ctrl->is_dyn_array) in user_to_new()
127 ctrl->new_elems = elems; in user_to_new()
128 else if (ctrl->is_array) in user_to_new()
129 ctrl->type_ops->init(ctrl, elems, ctrl->p_new); in user_to_new()
133 switch (ctrl->type) { in user_to_new()
135 *ctrl->p_new.p_s64 = c->value64; in user_to_new()
138 size = c->size; in user_to_new()
140 return -ERANGE; in user_to_new()
141 if (size > ctrl->maximum + 1) in user_to_new()
142 size = ctrl->maximum + 1; in user_to_new()
143 ret = copy_from_user(ctrl->p_new.p_char, c->string, size) ? -EFAULT : 0; in user_to_new()
145 char last = ctrl->p_new.p_char[size - 1]; in user_to_new()
147 ctrl->p_new.p_char[size - 1] = 0; in user_to_new()
149 * If the string was longer than ctrl->maximum, in user_to_new()
152 if (strlen(ctrl->p_new.p_char) == ctrl->maximum && last) in user_to_new()
153 return -ERANGE; in user_to_new()
154 ctrl->is_new = 1; in user_to_new()
158 *ctrl->p_new.p_s32 = c->value; in user_to_new()
161 ctrl->is_new = 1; in user_to_new()
172 * It is not a fully atomic operation, just best-effort only. After all, if
183 * in case of low-level errors.
188 * controls were affected. Otherwise all controls before that index were
190 * the given index failed, and you don't know what happened with the controls
191 * after the failed one. Since if they were part of a control cluster they
192 * could have been successfully processed (if a cluster member was encountered
193 * at index < error_idx), they could have failed (if a cluster member was at
194 * error_idx), or they may not have been processed yet (if the first cluster
223 for (i = 0, h = helpers; i < cs->count; i++, h++) { in prepare_ext_ctrls()
224 struct v4l2_ext_control *c = &cs->controls[i]; in prepare_ext_ctrls()
227 u32 id = c->id & V4L2_CTRL_ID_MASK; in prepare_ext_ctrls()
229 cs->error_idx = i; in prepare_ext_ctrls()
231 if (cs->which && in prepare_ext_ctrls()
232 cs->which != V4L2_CTRL_WHICH_DEF_VAL && in prepare_ext_ctrls()
233 cs->which != V4L2_CTRL_WHICH_REQUEST_VAL && in prepare_ext_ctrls()
234 V4L2_CTRL_ID2WHICH(id) != cs->which) { in prepare_ext_ctrls()
237 cs->which, id); in prepare_ext_ctrls()
238 return -EINVAL; in prepare_ext_ctrls()
242 * Old-style private controls are not allowed for in prepare_ext_ctrls()
247 "old-style private controls not allowed\n"); in prepare_ext_ctrls()
248 return -EINVAL; in prepare_ext_ctrls()
253 return -EINVAL; in prepare_ext_ctrls()
255 h->ref = ref; in prepare_ext_ctrls()
256 ctrl = ref->ctrl; in prepare_ext_ctrls()
257 if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED) { in prepare_ext_ctrls()
259 return -EINVAL; in prepare_ext_ctrls()
262 if (ctrl->cluster[0]->ncontrols > 1) in prepare_ext_ctrls()
264 if (ctrl->cluster[0] != ctrl) in prepare_ext_ctrls()
265 ref = find_ref_lock(hdl, ctrl->cluster[0]->id); in prepare_ext_ctrls()
266 if (ctrl->is_dyn_array) { in prepare_ext_ctrls()
267 unsigned int max_size = ctrl->dims[0] * ctrl->elem_size; in prepare_ext_ctrls()
268 unsigned int tot_size = ctrl->elem_size; in prepare_ext_ctrls()
270 if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) in prepare_ext_ctrls()
271 tot_size *= ref->p_req_elems; in prepare_ext_ctrls()
273 tot_size *= ctrl->elems; in prepare_ext_ctrls()
275 c->size = ctrl->elem_size * (c->size / ctrl->elem_size); in prepare_ext_ctrls()
277 if (c->size < tot_size) { in prepare_ext_ctrls()
278 c->size = tot_size; in prepare_ext_ctrls()
279 return -ENOSPC; in prepare_ext_ctrls()
281 c->size = tot_size; in prepare_ext_ctrls()
283 if (c->size > max_size) { in prepare_ext_ctrls()
284 c->size = max_size; in prepare_ext_ctrls()
285 return -ENOSPC; in prepare_ext_ctrls()
287 if (!c->size) in prepare_ext_ctrls()
288 return -EFAULT; in prepare_ext_ctrls()
290 } else if (ctrl->is_ptr && !ctrl->is_string) { in prepare_ext_ctrls()
291 unsigned int tot_size = ctrl->elems * ctrl->elem_size; in prepare_ext_ctrls()
293 if (c->size < tot_size) { in prepare_ext_ctrls()
299 c->size = tot_size; in prepare_ext_ctrls()
300 return -ENOSPC; in prepare_ext_ctrls()
304 id, c->size, tot_size); in prepare_ext_ctrls()
305 return -EFAULT; in prepare_ext_ctrls()
307 c->size = tot_size; in prepare_ext_ctrls()
309 /* Store the ref to the master control of the cluster */ in prepare_ext_ctrls()
310 h->mref = ref; in prepare_ext_ctrls()
314 * cluster. in prepare_ext_ctrls()
316 h->next = 0; in prepare_ext_ctrls()
320 * We are done if there were no controls that belong to a multi- in prepare_ext_ctrls()
321 * control cluster. in prepare_ext_ctrls()
328 * belong to the same cluster. in prepare_ext_ctrls()
332 mutex_lock(hdl->lock); in prepare_ext_ctrls()
335 for (i = 0; i < cs->count; i++) in prepare_ext_ctrls()
336 helpers[i].mref->helper = NULL; in prepare_ext_ctrls()
337 for (i = 0, h = helpers; i < cs->count; i++, h++) { in prepare_ext_ctrls()
338 struct v4l2_ctrl_ref *mref = h->mref; in prepare_ext_ctrls()
341 * If the mref->helper is set, then it points to an earlier in prepare_ext_ctrls()
342 * helper that belongs to the same cluster. in prepare_ext_ctrls()
344 if (mref->helper) { in prepare_ext_ctrls()
346 * Set the next field of mref->helper to the current in prepare_ext_ctrls()
347 * index: this means that the earlier helper now in prepare_ext_ctrls()
348 * points to the next helper in the same cluster. in prepare_ext_ctrls()
350 mref->helper->next = i; in prepare_ext_ctrls()
353 * cluster, clear the others. in prepare_ext_ctrls()
355 h->mref = NULL; in prepare_ext_ctrls()
358 mref->helper = h; in prepare_ext_ctrls()
360 mutex_unlock(hdl->lock); in prepare_ext_ctrls()
365 * Handles the corner case where cs->count == 0. It checks whether the
374 return find_ref_lock(hdl, which | 1) ? 0 : -EINVAL; in class_check()
394 is_default = (cs->which == V4L2_CTRL_WHICH_DEF_VAL); in v4l2_g_ext_ctrls_common()
395 is_request = (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL); in v4l2_g_ext_ctrls_common()
397 cs->error_idx = cs->count; in v4l2_g_ext_ctrls_common()
398 cs->which = V4L2_CTRL_ID2WHICH(cs->which); in v4l2_g_ext_ctrls_common()
401 return -EINVAL; in v4l2_g_ext_ctrls_common()
403 if (cs->count == 0) in v4l2_g_ext_ctrls_common()
404 return class_check(hdl, cs->which); in v4l2_g_ext_ctrls_common()
406 if (cs->count > ARRAY_SIZE(helper)) { in v4l2_g_ext_ctrls_common()
407 helpers = kvmalloc_array(cs->count, sizeof(helper[0]), in v4l2_g_ext_ctrls_common()
410 return -ENOMEM; in v4l2_g_ext_ctrls_common()
414 cs->error_idx = cs->count; in v4l2_g_ext_ctrls_common()
416 for (i = 0; !ret && i < cs->count; i++) in v4l2_g_ext_ctrls_common()
417 if (helpers[i].ref->ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) in v4l2_g_ext_ctrls_common()
418 ret = -EACCES; in v4l2_g_ext_ctrls_common()
420 for (i = 0; !ret && i < cs->count; i++) { in v4l2_g_ext_ctrls_common()
428 master = helpers[i].mref->ctrl; in v4l2_g_ext_ctrls_common()
429 cs->error_idx = i; in v4l2_g_ext_ctrls_common()
442 ((master->flags & V4L2_CTRL_FLAG_VOLATILE) || in v4l2_g_ext_ctrls_common()
443 (master->has_volatiles && !is_cur_manual(master)))) { in v4l2_g_ext_ctrls_common()
444 for (j = 0; j < master->ncontrols; j++) in v4l2_g_ext_ctrls_common()
445 cur_to_new(master->cluster[j]); in v4l2_g_ext_ctrls_common()
465 ret = def_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
466 else if (is_request && ref->p_req_array_enomem) in v4l2_g_ext_ctrls_common()
467 ret = -ENOMEM; in v4l2_g_ext_ctrls_common()
468 else if (is_request && ref->p_req_valid) in v4l2_g_ext_ctrls_common()
469 ret = req_to_user(cs->controls + idx, ref); in v4l2_g_ext_ctrls_common()
471 ret = new_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
473 ret = cur_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
480 if (cs->count > ARRAY_SIZE(helper)) in v4l2_g_ext_ctrls_common()
488 if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) in v4l2_g_ext_ctrls()
498 return ctrl->type_ops->validate(ctrl, p_new); in validate_new()
510 cs->error_idx = cs->count; in validate_ctrls()
511 for (i = 0; i < cs->count; i++) { in validate_ctrls()
512 struct v4l2_ctrl *ctrl = helpers[i].ref->ctrl; in validate_ctrls()
515 cs->error_idx = i; in validate_ctrls()
517 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) { in validate_ctrls()
519 "control id 0x%x is read-only\n", in validate_ctrls()
520 ctrl->id); in validate_ctrls()
521 return -EACCES; in validate_ctrls()
526 * but it makes sense to do an up-front check as well. Once in validate_ctrls()
529 * best-effort to avoid that. in validate_ctrls()
531 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) { in validate_ctrls()
534 ctrl->id); in validate_ctrls()
535 return -EBUSY; in validate_ctrls()
541 if (ctrl->is_ptr) in validate_ctrls()
543 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in validate_ctrls()
544 p_new.p_s64 = &cs->controls[i].value64; in validate_ctrls()
546 p_new.p_s32 = &cs->controls[i].value; in validate_ctrls()
554 /* Try or try-and-set controls */
565 cs->error_idx = cs->count; in try_set_ext_ctrls_common()
568 if (cs->which == V4L2_CTRL_WHICH_DEF_VAL) { in try_set_ext_ctrls_common()
571 return -EINVAL; in try_set_ext_ctrls_common()
574 cs->which = V4L2_CTRL_ID2WHICH(cs->which); in try_set_ext_ctrls_common()
579 return -EINVAL; in try_set_ext_ctrls_common()
582 if (cs->count == 0) in try_set_ext_ctrls_common()
583 return class_check(hdl, cs->which); in try_set_ext_ctrls_common()
585 if (cs->count > ARRAY_SIZE(helper)) { in try_set_ext_ctrls_common()
586 helpers = kvmalloc_array(cs->count, sizeof(helper[0]), in try_set_ext_ctrls_common()
589 return -ENOMEM; in try_set_ext_ctrls_common()
595 cs->error_idx = cs->count; in try_set_ext_ctrls_common()
596 for (i = 0; !ret && i < cs->count; i++) { in try_set_ext_ctrls_common()
603 cs->error_idx = i; in try_set_ext_ctrls_common()
604 master = helpers[i].mref->ctrl; in try_set_ext_ctrls_common()
607 /* Reset the 'is_new' flags of the cluster */ in try_set_ext_ctrls_common()
608 for (j = 0; j < master->ncontrols; j++) in try_set_ext_ctrls_common()
609 if (master->cluster[j]) in try_set_ext_ctrls_common()
610 master->cluster[j]->is_new = 0; in try_set_ext_ctrls_common()
620 if (master->is_auto && master->has_volatiles && in try_set_ext_ctrls_common()
622 /* Pick an initial non-manual value */ in try_set_ext_ctrls_common()
623 s32 new_auto_val = master->manual_mode_value + 1; in try_set_ext_ctrls_common()
631 if (helpers[tmp_idx].ref->ctrl == master) in try_set_ext_ctrls_common()
632 new_auto_val = cs->controls[tmp_idx].value; in try_set_ext_ctrls_common()
639 if (new_auto_val == master->manual_mode_value) in try_set_ext_ctrls_common()
644 * Copy the new caller-supplied control values. in try_set_ext_ctrls_common()
648 struct v4l2_ctrl *ctrl = helpers[idx].ref->ctrl; in try_set_ext_ctrls_common()
650 ret = user_to_new(cs->controls + idx, ctrl); in try_set_ext_ctrls_common()
651 if (!ret && ctrl->is_ptr) { in try_set_ext_ctrls_common()
652 ret = validate_new(ctrl, ctrl->p_new); in try_set_ext_ctrls_common()
656 v4l2_ctrl_get_name(ctrl->id), ret); in try_set_ext_ctrls_common()
663 !hdl->req_obj.req && set, 0); in try_set_ext_ctrls_common()
664 if (!ret && hdl->req_obj.req && set) { in try_set_ext_ctrls_common()
665 for (j = 0; j < master->ncontrols; j++) { in try_set_ext_ctrls_common()
667 find_ref(hdl, master->cluster[j]->id); in try_set_ext_ctrls_common()
677 ret = new_to_user(cs->controls + idx, in try_set_ext_ctrls_common()
678 helpers[idx].ref->ctrl); in try_set_ext_ctrls_common()
685 if (cs->count > ARRAY_SIZE(helper)) in try_set_ext_ctrls_common()
698 if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) in try_set_ext_ctrls()
736 struct v4l2_ctrl *master = ctrl->cluster[0]; in get_ctrl()
744 if (!ctrl->is_int && ctrl->type != V4L2_CTRL_TYPE_INTEGER64) in get_ctrl()
745 return -EINVAL; in get_ctrl()
747 if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) in get_ctrl()
748 return -EACCES; in get_ctrl()
752 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) { in get_ctrl()
753 for (i = 0; i < master->ncontrols; i++) in get_ctrl()
754 cur_to_new(master->cluster[i]); in get_ctrl()
766 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_g_ctrl()
770 if (!ctrl || !ctrl->is_int) in v4l2_g_ctrl()
771 return -EINVAL; in v4l2_g_ctrl()
773 control->value = c.value; in v4l2_g_ctrl()
781 struct v4l2_ctrl *master = ctrl->cluster[0]; in set_ctrl()
785 /* Reset the 'is_new' flags of the cluster */ in set_ctrl()
786 for (i = 0; i < master->ncontrols; i++) in set_ctrl()
787 if (master->cluster[i]) in set_ctrl()
788 master->cluster[i]->is_new = 0; in set_ctrl()
790 ret = validate_new(ctrl, ctrl->p_new); in set_ctrl()
799 if (master->is_auto && master->has_volatiles && ctrl == master && in set_ctrl()
800 !is_cur_manual(master) && ctrl->val == master->manual_mode_value) in set_ctrl()
803 ctrl->is_new = 1; in set_ctrl()
825 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_s_ctrl()
826 struct v4l2_ext_control c = { control->id }; in v4l2_s_ctrl()
829 if (!ctrl || !ctrl->is_int) in v4l2_s_ctrl()
830 return -EINVAL; in v4l2_s_ctrl()
832 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) in v4l2_s_ctrl()
833 return -EACCES; in v4l2_s_ctrl()
835 c.value = control->value; in v4l2_s_ctrl()
837 control->value = c.value; in v4l2_s_ctrl()
851 if (WARN_ON(!ctrl->is_int)) in v4l2_ctrl_g_ctrl()
864 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64)) in v4l2_ctrl_g_ctrl_int64()
874 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl()
877 if (WARN_ON(!ctrl->is_int)) in __v4l2_ctrl_s_ctrl()
878 return -EINVAL; in __v4l2_ctrl_s_ctrl()
879 ctrl->val = val; in __v4l2_ctrl_s_ctrl()
886 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_int64()
889 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64)) in __v4l2_ctrl_s_ctrl_int64()
890 return -EINVAL; in __v4l2_ctrl_s_ctrl_int64()
891 *ctrl->p_new.p_s64 = val; in __v4l2_ctrl_s_ctrl_int64()
898 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_string()
901 if (WARN_ON(ctrl->type != V4L2_CTRL_TYPE_STRING)) in __v4l2_ctrl_s_ctrl_string()
902 return -EINVAL; in __v4l2_ctrl_s_ctrl_string()
903 strscpy(ctrl->p_new.p_char, s, ctrl->maximum + 1); in __v4l2_ctrl_s_ctrl_string()
911 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_compound()
914 if (WARN_ON(ctrl->type != type)) in __v4l2_ctrl_s_ctrl_compound()
915 return -EINVAL; in __v4l2_ctrl_s_ctrl_compound()
917 if (WARN_ON(ctrl->is_dyn_array)) in __v4l2_ctrl_s_ctrl_compound()
918 return -EINVAL; in __v4l2_ctrl_s_ctrl_compound()
919 memcpy(ctrl->p_new.p, p, ctrl->elems * ctrl->elem_size); in __v4l2_ctrl_s_ctrl_compound()
934 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_modify_range()
936 switch (ctrl->type) { in __v4l2_ctrl_modify_range()
946 if (ctrl->is_array) in __v4l2_ctrl_modify_range()
947 return -EINVAL; in __v4l2_ctrl_modify_range()
948 ret = check_range(ctrl->type, min, max, step, def); in __v4l2_ctrl_modify_range()
953 return -EINVAL; in __v4l2_ctrl_modify_range()
955 if (ctrl->minimum != min || ctrl->maximum != max || in __v4l2_ctrl_modify_range()
956 ctrl->step != step || ctrl->default_value != def) { in __v4l2_ctrl_modify_range()
958 ctrl->minimum = min; in __v4l2_ctrl_modify_range()
959 ctrl->maximum = max; in __v4l2_ctrl_modify_range()
960 ctrl->step = step; in __v4l2_ctrl_modify_range()
961 ctrl->default_value = def; in __v4l2_ctrl_modify_range()
964 if (validate_new(ctrl, ctrl->p_new)) { in __v4l2_ctrl_modify_range()
965 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in __v4l2_ctrl_modify_range()
966 *ctrl->p_new.p_s64 = def; in __v4l2_ctrl_modify_range()
968 *ctrl->p_new.p_s32 = def; in __v4l2_ctrl_modify_range()
971 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in __v4l2_ctrl_modify_range()
972 value_changed = *ctrl->p_new.p_s64 != *ctrl->p_cur.p_s64; in __v4l2_ctrl_modify_range()
974 value_changed = *ctrl->p_new.p_s32 != *ctrl->p_cur.p_s32; in __v4l2_ctrl_modify_range()
990 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_modify_dimensions()
992 if (!ctrl->is_array || ctrl->is_dyn_array) in __v4l2_ctrl_modify_dimensions()
993 return -EINVAL; in __v4l2_ctrl_modify_dimensions()
995 for (i = 0; i < ctrl->nr_of_dims; i++) in __v4l2_ctrl_modify_dimensions()
998 return -EINVAL; in __v4l2_ctrl_modify_dimensions()
999 p_array = kvzalloc(2 * elems * ctrl->elem_size, GFP_KERNEL); in __v4l2_ctrl_modify_dimensions()
1001 return -ENOMEM; in __v4l2_ctrl_modify_dimensions()
1002 kvfree(ctrl->p_array); in __v4l2_ctrl_modify_dimensions()
1003 ctrl->p_array_alloc_elems = elems; in __v4l2_ctrl_modify_dimensions()
1004 ctrl->elems = elems; in __v4l2_ctrl_modify_dimensions()
1005 ctrl->new_elems = elems; in __v4l2_ctrl_modify_dimensions()
1006 ctrl->p_array = p_array; in __v4l2_ctrl_modify_dimensions()
1007 ctrl->p_new.p = p_array; in __v4l2_ctrl_modify_dimensions()
1008 ctrl->p_cur.p = p_array + elems * ctrl->elem_size; in __v4l2_ctrl_modify_dimensions()
1009 for (i = 0; i < ctrl->nr_of_dims; i++) in __v4l2_ctrl_modify_dimensions()
1010 ctrl->dims[i] = dims[i]; in __v4l2_ctrl_modify_dimensions()
1011 ctrl->type_ops->init(ctrl, 0, ctrl->p_cur); in __v4l2_ctrl_modify_dimensions()
1023 u32 id = qc->id & V4L2_CTRL_ID_MASK; in v4l2_query_ext_ctrl()
1028 return -EINVAL; in v4l2_query_ext_ctrl()
1030 mutex_lock(hdl->lock); in v4l2_query_ext_ctrl()
1035 if ((qc->id & next_flags) && !list_empty(&hdl->ctrl_refs)) { in v4l2_query_ext_ctrl()
1041 if ((qc->id & next_flags) == V4L2_CTRL_FLAG_NEXT_COMPOUND) { in v4l2_query_ext_ctrl()
1044 } else if ((qc->id & next_flags) == next_flags) { in v4l2_query_ext_ctrl()
1049 /* Find the next control with ID > qc->id */ in v4l2_query_ext_ctrl()
1052 if (id >= node2id(hdl->ctrl_refs.prev)) { in v4l2_query_ext_ctrl()
1062 list_for_each_entry_continue(pos, &hdl->ctrl_refs, node) { in v4l2_query_ext_ctrl()
1063 is_compound = pos->ctrl->is_array || in v4l2_query_ext_ctrl()
1064 pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; in v4l2_query_ext_ctrl()
1065 if (id < pos->ctrl->id && in v4l2_query_ext_ctrl()
1080 list_for_each_entry(pos, &hdl->ctrl_refs, node) { in v4l2_query_ext_ctrl()
1081 is_compound = pos->ctrl->is_array || in v4l2_query_ext_ctrl()
1082 pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; in v4l2_query_ext_ctrl()
1083 if (id < pos->ctrl->id && in v4l2_query_ext_ctrl()
1091 mutex_unlock(hdl->lock); in v4l2_query_ext_ctrl()
1094 return -EINVAL; in v4l2_query_ext_ctrl()
1096 ctrl = ref->ctrl; in v4l2_query_ext_ctrl()
1099 qc->id = id; in v4l2_query_ext_ctrl()
1101 qc->id = ctrl->id; in v4l2_query_ext_ctrl()
1102 strscpy(qc->name, ctrl->name, sizeof(qc->name)); in v4l2_query_ext_ctrl()
1103 qc->flags = user_flags(ctrl); in v4l2_query_ext_ctrl()
1104 qc->type = ctrl->type; in v4l2_query_ext_ctrl()
1105 qc->elem_size = ctrl->elem_size; in v4l2_query_ext_ctrl()
1106 qc->elems = ctrl->elems; in v4l2_query_ext_ctrl()
1107 qc->nr_of_dims = ctrl->nr_of_dims; in v4l2_query_ext_ctrl()
1108 memcpy(qc->dims, ctrl->dims, qc->nr_of_dims * sizeof(qc->dims[0])); in v4l2_query_ext_ctrl()
1109 qc->minimum = ctrl->minimum; in v4l2_query_ext_ctrl()
1110 qc->maximum = ctrl->maximum; in v4l2_query_ext_ctrl()
1111 qc->default_value = ctrl->default_value; in v4l2_query_ext_ctrl()
1112 if (ctrl->type == V4L2_CTRL_TYPE_MENU || in v4l2_query_ext_ctrl()
1113 ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU) in v4l2_query_ext_ctrl()
1114 qc->step = 1; in v4l2_query_ext_ctrl()
1116 qc->step = ctrl->step; in v4l2_query_ext_ctrl()
1124 struct v4l2_query_ext_ctrl qec = { qc->id }; in v4l2_queryctrl()
1131 qc->id = qec.id; in v4l2_queryctrl()
1132 qc->type = qec.type; in v4l2_queryctrl()
1133 qc->flags = qec.flags; in v4l2_queryctrl()
1134 strscpy(qc->name, qec.name, sizeof(qc->name)); in v4l2_queryctrl()
1135 switch (qc->type) { in v4l2_queryctrl()
1142 qc->minimum = qec.minimum; in v4l2_queryctrl()
1143 qc->maximum = qec.maximum; in v4l2_queryctrl()
1144 qc->step = qec.step; in v4l2_queryctrl()
1145 qc->default_value = qec.default_value; in v4l2_queryctrl()
1148 qc->minimum = 0; in v4l2_queryctrl()
1149 qc->maximum = 0; in v4l2_queryctrl()
1150 qc->step = 0; in v4l2_queryctrl()
1151 qc->default_value = 0; in v4l2_queryctrl()
1162 u32 i = qm->index; in v4l2_querymenu()
1164 ctrl = v4l2_ctrl_find(hdl, qm->id); in v4l2_querymenu()
1166 return -EINVAL; in v4l2_querymenu()
1168 qm->reserved = 0; in v4l2_querymenu()
1170 switch (ctrl->type) { in v4l2_querymenu()
1172 if (!ctrl->qmenu) in v4l2_querymenu()
1173 return -EINVAL; in v4l2_querymenu()
1176 if (!ctrl->qmenu_int) in v4l2_querymenu()
1177 return -EINVAL; in v4l2_querymenu()
1180 return -EINVAL; in v4l2_querymenu()
1183 if (i < ctrl->minimum || i > ctrl->maximum) in v4l2_querymenu()
1184 return -EINVAL; in v4l2_querymenu()
1187 if (i < BITS_PER_LONG_LONG && (ctrl->menu_skip_mask & BIT_ULL(i))) in v4l2_querymenu()
1188 return -EINVAL; in v4l2_querymenu()
1190 if (ctrl->type == V4L2_CTRL_TYPE_MENU) { in v4l2_querymenu()
1191 if (!ctrl->qmenu[i] || ctrl->qmenu[i][0] == '\0') in v4l2_querymenu()
1192 return -EINVAL; in v4l2_querymenu()
1193 strscpy(qm->name, ctrl->qmenu[i], sizeof(qm->name)); in v4l2_querymenu()
1195 qm->value = ctrl->qmenu_int[i]; in v4l2_querymenu()
1208 struct v4l2_fh *vfh = file->private_data; in v4l2_ctrl_log_status()
1210 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) && vfd->v4l2_dev) in v4l2_ctrl_log_status()
1211 v4l2_ctrl_handler_log_status(vfh->ctrl_handler, in v4l2_ctrl_log_status()
1212 vfd->v4l2_dev->name); in v4l2_ctrl_log_status()
1219 v4l2_ctrl_handler_log_status(sd->ctrl_handler, sd->name); in v4l2_ctrl_subdev_log_status()
1231 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); in v4l2_ctrl_add_event()
1234 return -EINVAL; in v4l2_ctrl_add_event()
1237 list_add_tail(&sev->node, &ctrl->ev_subs); in v4l2_ctrl_add_event()
1238 if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS && in v4l2_ctrl_add_event()
1239 (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL)) in v4l2_ctrl_add_event()
1240 send_initial_event(sev->fh, ctrl); in v4l2_ctrl_add_event()
1247 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); in v4l2_ctrl_del_event()
1253 list_del(&sev->node); in v4l2_ctrl_del_event()
1259 u32 old_changes = old->u.ctrl.changes; in v4l2_ctrl_replace()
1261 old->u.ctrl = new->u.ctrl; in v4l2_ctrl_replace()
1262 old->u.ctrl.changes |= old_changes; in v4l2_ctrl_replace()
1268 new->u.ctrl.changes |= old->u.ctrl.changes; in v4l2_ctrl_merge()
1283 if (sub->type == V4L2_EVENT_CTRL) in v4l2_ctrl_subscribe_event()
1285 return -EINVAL; in v4l2_ctrl_subscribe_event()
1292 if (!sd->ctrl_handler) in v4l2_ctrl_subdev_subscribe_event()
1293 return -EINVAL; in v4l2_ctrl_subdev_subscribe_event()
1303 struct v4l2_fh *fh = file->private_data; in v4l2_ctrl_poll()
1305 poll_wait(file, &fh->wait, wait); in v4l2_ctrl_poll()