Lines Matching +full:cs +full:- +full:x

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"
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.
214 struct v4l2_ext_controls *cs, in prepare_ext_ctrls() argument
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()
236 "invalid which 0x%x or control id 0x%x\n", 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()
252 dprintk(vdev, "cannot find control id 0x%x\n", id); 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()
258 dprintk(vdev, "control id 0x%x is disabled\n", id); 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()
303 "pointer control id 0x%x size too small, %d bytes but %d bytes needed\n", 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()
310 h->mref = ref; 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()
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()
344 if (mref->helper) { in prepare_ext_ctrls()
346 * Set the next field of mref->helper to the current in prepare_ext_ctrls()
350 mref->helper->next = i; 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()
385 struct v4l2_ext_controls *cs, in v4l2_g_ext_ctrls_common() argument
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()
413 ret = prepare_ext_ctrls(hdl, cs, helpers, vdev, true); 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()
486 struct media_device *mdev, struct v4l2_ext_controls *cs) in v4l2_g_ext_ctrls() argument
488 if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) in v4l2_g_ext_ctrls()
489 return v4l2_g_ext_ctrls_request(hdl, vdev, mdev, cs); in v4l2_g_ext_ctrls()
491 return v4l2_g_ext_ctrls_common(hdl, cs, vdev); in v4l2_g_ext_ctrls()
498 return ctrl->type_ops->validate(ctrl, p_new); in validate_new()
502 static int validate_ctrls(struct v4l2_ext_controls *cs, in validate_ctrls() argument
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()
533 "control id 0x%x is grabbed, cannot set\n", 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 */
557 struct v4l2_ext_controls *cs, in try_set_ext_ctrls_common() argument
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()
591 ret = prepare_ext_ctrls(hdl, cs, helpers, vdev, false); in try_set_ext_ctrls_common()
593 ret = validate_ctrls(cs, helpers, vdev, set); 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()
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()
694 struct v4l2_ext_controls *cs, bool set) in try_set_ext_ctrls() argument
698 if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) in try_set_ext_ctrls()
699 return try_set_ext_ctrls_request(fh, hdl, vdev, mdev, cs, set); in try_set_ext_ctrls()
701 ret = try_set_ext_ctrls_common(fh, hdl, cs, vdev, set); in try_set_ext_ctrls()
713 struct v4l2_ext_controls *cs) in v4l2_try_ext_ctrls() argument
715 return try_set_ext_ctrls(NULL, hdl, vdev, mdev, cs, false); in v4l2_try_ext_ctrls()
723 struct v4l2_ext_controls *cs) in v4l2_s_ext_ctrls() argument
725 return try_set_ext_ctrls(fh, hdl, vdev, mdev, cs, true); in v4l2_s_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()
767 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_g_ctrl()
771 if (!ctrl || !ctrl->is_int) in v4l2_g_ctrl()
772 return -EINVAL; in v4l2_g_ctrl()
776 control->value = c.value; in v4l2_g_ctrl()
785 struct v4l2_ctrl *master = ctrl->cluster[0]; in set_ctrl()
790 for (i = 0; i < master->ncontrols; i++) in set_ctrl()
791 if (master->cluster[i]) in set_ctrl()
792 master->cluster[i]->is_new = 0; in set_ctrl()
794 ret = validate_new(ctrl, ctrl->p_new); in set_ctrl()
803 if (master->is_auto && master->has_volatiles && ctrl == master && in set_ctrl()
804 !is_cur_manual(master) && ctrl->val == master->manual_mode_value) in set_ctrl()
807 ctrl->is_new = 1; in set_ctrl()
830 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_s_ctrl()
831 struct v4l2_ext_control c = { control->id }; in v4l2_s_ctrl()
834 if (!ctrl || !ctrl->is_int) in v4l2_s_ctrl()
835 return -EINVAL; in v4l2_s_ctrl()
837 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) in v4l2_s_ctrl()
838 return -EACCES; in v4l2_s_ctrl()
840 c.value = control->value; in v4l2_s_ctrl()
842 control->value = c.value; in v4l2_s_ctrl()
856 if (WARN_ON(!ctrl->is_int)) in v4l2_ctrl_g_ctrl()
869 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64)) in v4l2_ctrl_g_ctrl_int64()
879 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl()
882 if (WARN_ON(!ctrl->is_int)) in __v4l2_ctrl_s_ctrl()
883 return -EINVAL; in __v4l2_ctrl_s_ctrl()
884 ctrl->val = val; in __v4l2_ctrl_s_ctrl()
891 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_int64()
894 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64)) in __v4l2_ctrl_s_ctrl_int64()
895 return -EINVAL; in __v4l2_ctrl_s_ctrl_int64()
896 *ctrl->p_new.p_s64 = val; in __v4l2_ctrl_s_ctrl_int64()
903 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_string()
906 if (WARN_ON(ctrl->type != V4L2_CTRL_TYPE_STRING)) in __v4l2_ctrl_s_ctrl_string()
907 return -EINVAL; in __v4l2_ctrl_s_ctrl_string()
908 strscpy(ctrl->p_new.p_char, s, ctrl->maximum + 1); in __v4l2_ctrl_s_ctrl_string()
916 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_compound()
919 if (WARN_ON(ctrl->type != type)) in __v4l2_ctrl_s_ctrl_compound()
920 return -EINVAL; in __v4l2_ctrl_s_ctrl_compound()
922 if (WARN_ON(ctrl->is_dyn_array)) in __v4l2_ctrl_s_ctrl_compound()
923 return -EINVAL; in __v4l2_ctrl_s_ctrl_compound()
924 memcpy(ctrl->p_new.p, p, ctrl->elems * ctrl->elem_size); in __v4l2_ctrl_s_ctrl_compound()
939 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_modify_range()
941 switch (ctrl->type) { in __v4l2_ctrl_modify_range()
951 if (ctrl->is_array) in __v4l2_ctrl_modify_range()
952 return -EINVAL; in __v4l2_ctrl_modify_range()
953 ret = check_range(ctrl->type, min, max, step, def); in __v4l2_ctrl_modify_range()
958 return -EINVAL; in __v4l2_ctrl_modify_range()
960 if (ctrl->minimum != min || ctrl->maximum != max || in __v4l2_ctrl_modify_range()
961 ctrl->step != step || ctrl->default_value != def) { in __v4l2_ctrl_modify_range()
963 ctrl->minimum = min; in __v4l2_ctrl_modify_range()
964 ctrl->maximum = max; in __v4l2_ctrl_modify_range()
965 ctrl->step = step; in __v4l2_ctrl_modify_range()
966 ctrl->default_value = def; in __v4l2_ctrl_modify_range()
969 if (validate_new(ctrl, ctrl->p_new)) { in __v4l2_ctrl_modify_range()
970 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in __v4l2_ctrl_modify_range()
971 *ctrl->p_new.p_s64 = def; in __v4l2_ctrl_modify_range()
973 *ctrl->p_new.p_s32 = def; in __v4l2_ctrl_modify_range()
976 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in __v4l2_ctrl_modify_range()
977 value_changed = *ctrl->p_new.p_s64 != *ctrl->p_cur.p_s64; in __v4l2_ctrl_modify_range()
979 value_changed = *ctrl->p_new.p_s32 != *ctrl->p_cur.p_s32; in __v4l2_ctrl_modify_range()
995 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_modify_dimensions()
997 if (!ctrl->is_array || ctrl->is_dyn_array) in __v4l2_ctrl_modify_dimensions()
998 return -EINVAL; in __v4l2_ctrl_modify_dimensions()
1000 for (i = 0; i < ctrl->nr_of_dims; i++) in __v4l2_ctrl_modify_dimensions()
1003 return -EINVAL; in __v4l2_ctrl_modify_dimensions()
1004 p_array = kvzalloc(2 * elems * ctrl->elem_size, GFP_KERNEL); in __v4l2_ctrl_modify_dimensions()
1006 return -ENOMEM; in __v4l2_ctrl_modify_dimensions()
1007 kvfree(ctrl->p_array); in __v4l2_ctrl_modify_dimensions()
1008 ctrl->p_array_alloc_elems = elems; in __v4l2_ctrl_modify_dimensions()
1009 ctrl->elems = elems; in __v4l2_ctrl_modify_dimensions()
1010 ctrl->new_elems = elems; in __v4l2_ctrl_modify_dimensions()
1011 ctrl->p_array = p_array; in __v4l2_ctrl_modify_dimensions()
1012 ctrl->p_new.p = p_array; in __v4l2_ctrl_modify_dimensions()
1013 ctrl->p_cur.p = p_array + elems * ctrl->elem_size; in __v4l2_ctrl_modify_dimensions()
1014 for (i = 0; i < ctrl->nr_of_dims; i++) in __v4l2_ctrl_modify_dimensions()
1015 ctrl->dims[i] = dims[i]; in __v4l2_ctrl_modify_dimensions()
1016 ctrl->type_ops->init(ctrl, 0, ctrl->p_cur); in __v4l2_ctrl_modify_dimensions()
1028 u32 id = qc->id & V4L2_CTRL_ID_MASK; in v4l2_query_ext_ctrl()
1033 return -EINVAL; in v4l2_query_ext_ctrl()
1035 mutex_lock(hdl->lock); in v4l2_query_ext_ctrl()
1040 if ((qc->id & next_flags) && !list_empty(&hdl->ctrl_refs)) { in v4l2_query_ext_ctrl()
1046 if ((qc->id & next_flags) == V4L2_CTRL_FLAG_NEXT_COMPOUND) { in v4l2_query_ext_ctrl()
1049 } else if ((qc->id & next_flags) == next_flags) { in v4l2_query_ext_ctrl()
1054 /* Find the next control with ID > qc->id */ in v4l2_query_ext_ctrl()
1057 if (id >= node2id(hdl->ctrl_refs.prev)) { in v4l2_query_ext_ctrl()
1067 list_for_each_entry_continue(pos, &hdl->ctrl_refs, node) { in v4l2_query_ext_ctrl()
1068 is_compound = pos->ctrl->is_array || in v4l2_query_ext_ctrl()
1069 pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; in v4l2_query_ext_ctrl()
1070 if (id < pos->ctrl->id && in v4l2_query_ext_ctrl()
1085 list_for_each_entry(pos, &hdl->ctrl_refs, node) { in v4l2_query_ext_ctrl()
1086 is_compound = pos->ctrl->is_array || in v4l2_query_ext_ctrl()
1087 pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; in v4l2_query_ext_ctrl()
1088 if (id < pos->ctrl->id && in v4l2_query_ext_ctrl()
1096 mutex_unlock(hdl->lock); in v4l2_query_ext_ctrl()
1099 return -EINVAL; in v4l2_query_ext_ctrl()
1101 ctrl = ref->ctrl; in v4l2_query_ext_ctrl()
1104 qc->id = id; in v4l2_query_ext_ctrl()
1106 qc->id = ctrl->id; in v4l2_query_ext_ctrl()
1107 strscpy(qc->name, ctrl->name, sizeof(qc->name)); in v4l2_query_ext_ctrl()
1108 qc->flags = user_flags(ctrl); in v4l2_query_ext_ctrl()
1109 qc->type = ctrl->type; in v4l2_query_ext_ctrl()
1110 qc->elem_size = ctrl->elem_size; in v4l2_query_ext_ctrl()
1111 qc->elems = ctrl->elems; in v4l2_query_ext_ctrl()
1112 qc->nr_of_dims = ctrl->nr_of_dims; in v4l2_query_ext_ctrl()
1113 memcpy(qc->dims, ctrl->dims, qc->nr_of_dims * sizeof(qc->dims[0])); in v4l2_query_ext_ctrl()
1114 qc->minimum = ctrl->minimum; in v4l2_query_ext_ctrl()
1115 qc->maximum = ctrl->maximum; in v4l2_query_ext_ctrl()
1116 qc->default_value = ctrl->default_value; in v4l2_query_ext_ctrl()
1117 if (ctrl->type == V4L2_CTRL_TYPE_MENU || in v4l2_query_ext_ctrl()
1118 ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU) in v4l2_query_ext_ctrl()
1119 qc->step = 1; in v4l2_query_ext_ctrl()
1121 qc->step = ctrl->step; in v4l2_query_ext_ctrl()
1129 struct v4l2_query_ext_ctrl qec = { qc->id }; in v4l2_queryctrl()
1136 qc->id = qec.id; in v4l2_queryctrl()
1137 qc->type = qec.type; in v4l2_queryctrl()
1138 qc->flags = qec.flags; in v4l2_queryctrl()
1139 strscpy(qc->name, qec.name, sizeof(qc->name)); in v4l2_queryctrl()
1140 switch (qc->type) { in v4l2_queryctrl()
1147 qc->minimum = qec.minimum; in v4l2_queryctrl()
1148 qc->maximum = qec.maximum; in v4l2_queryctrl()
1149 qc->step = qec.step; in v4l2_queryctrl()
1150 qc->default_value = qec.default_value; in v4l2_queryctrl()
1153 qc->minimum = 0; in v4l2_queryctrl()
1154 qc->maximum = 0; in v4l2_queryctrl()
1155 qc->step = 0; in v4l2_queryctrl()
1156 qc->default_value = 0; in v4l2_queryctrl()
1167 u32 i = qm->index; in v4l2_querymenu()
1169 ctrl = v4l2_ctrl_find(hdl, qm->id); in v4l2_querymenu()
1171 return -EINVAL; in v4l2_querymenu()
1173 qm->reserved = 0; in v4l2_querymenu()
1175 switch (ctrl->type) { in v4l2_querymenu()
1177 if (!ctrl->qmenu) in v4l2_querymenu()
1178 return -EINVAL; in v4l2_querymenu()
1181 if (!ctrl->qmenu_int) in v4l2_querymenu()
1182 return -EINVAL; in v4l2_querymenu()
1185 return -EINVAL; in v4l2_querymenu()
1188 if (i < ctrl->minimum || i > ctrl->maximum) in v4l2_querymenu()
1189 return -EINVAL; in v4l2_querymenu()
1192 if (i < BITS_PER_LONG_LONG && (ctrl->menu_skip_mask & BIT_ULL(i))) in v4l2_querymenu()
1193 return -EINVAL; in v4l2_querymenu()
1195 if (ctrl->type == V4L2_CTRL_TYPE_MENU) { in v4l2_querymenu()
1196 if (!ctrl->qmenu[i] || ctrl->qmenu[i][0] == '\0') in v4l2_querymenu()
1197 return -EINVAL; in v4l2_querymenu()
1198 strscpy(qm->name, ctrl->qmenu[i], sizeof(qm->name)); in v4l2_querymenu()
1200 qm->value = ctrl->qmenu_int[i]; in v4l2_querymenu()
1213 struct v4l2_fh *vfh = file->private_data; in v4l2_ctrl_log_status()
1215 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) && vfd->v4l2_dev) in v4l2_ctrl_log_status()
1216 v4l2_ctrl_handler_log_status(vfh->ctrl_handler, in v4l2_ctrl_log_status()
1217 vfd->v4l2_dev->name); in v4l2_ctrl_log_status()
1224 v4l2_ctrl_handler_log_status(sd->ctrl_handler, sd->name); in v4l2_ctrl_subdev_log_status()
1236 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); in v4l2_ctrl_add_event()
1239 return -EINVAL; in v4l2_ctrl_add_event()
1242 list_add_tail(&sev->node, &ctrl->ev_subs); in v4l2_ctrl_add_event()
1243 if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS && in v4l2_ctrl_add_event()
1244 (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL)) in v4l2_ctrl_add_event()
1245 send_initial_event(sev->fh, ctrl); in v4l2_ctrl_add_event()
1252 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); in v4l2_ctrl_del_event()
1258 list_del(&sev->node); in v4l2_ctrl_del_event()
1264 u32 old_changes = old->u.ctrl.changes; in v4l2_ctrl_replace()
1266 old->u.ctrl = new->u.ctrl; in v4l2_ctrl_replace()
1267 old->u.ctrl.changes |= old_changes; in v4l2_ctrl_replace()
1273 new->u.ctrl.changes |= old->u.ctrl.changes; in v4l2_ctrl_merge()
1288 if (sub->type == V4L2_EVENT_CTRL) in v4l2_ctrl_subscribe_event()
1290 return -EINVAL; in v4l2_ctrl_subscribe_event()
1297 if (!sd->ctrl_handler) in v4l2_ctrl_subdev_subscribe_event()
1298 return -EINVAL; in v4l2_ctrl_subdev_subscribe_event()
1308 struct v4l2_fh *fh = file->private_data; in v4l2_ctrl_poll()
1310 poll_wait(file, &fh->wait, wait); in v4l2_ctrl_poll()