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()
94 for (idx = 0; idx < ctrl->elems; idx++) in def_to_user()
95 ctrl->type_ops->init(ctrl, idx, ctrl->p_new); in def_to_user()
97 return ptr_to_user(c, ctrl, ctrl->p_new); in def_to_user()
100 /* Helper function: copy the caller-provider value to the given control value */
108 ctrl->is_new = 1; in user_to_ptr()
109 if (ctrl->is_ptr && !ctrl->is_string) { in user_to_ptr()
112 ret = copy_from_user(ptr.p, c->ptr, c->size) ? -EFAULT : 0; in user_to_ptr()
113 if (ret || !ctrl->is_array) in user_to_ptr()
115 for (idx = c->size / ctrl->elem_size; idx < ctrl->elems; idx++) in user_to_ptr()
116 ctrl->type_ops->init(ctrl, idx, ptr); in user_to_ptr()
120 switch (ctrl->type) { in user_to_ptr()
122 *ptr.p_s64 = c->value64; in user_to_ptr()
125 size = c->size; in user_to_ptr()
127 return -ERANGE; in user_to_ptr()
128 if (size > ctrl->maximum + 1) in user_to_ptr()
129 size = ctrl->maximum + 1; in user_to_ptr()
130 ret = copy_from_user(ptr.p_char, c->string, size) ? -EFAULT : 0; in user_to_ptr()
132 char last = ptr.p_char[size - 1]; in user_to_ptr()
134 ptr.p_char[size - 1] = 0; in user_to_ptr()
136 * If the string was longer than ctrl->maximum, in user_to_ptr()
139 if (strlen(ptr.p_char) == ctrl->maximum && last) in user_to_ptr()
140 return -ERANGE; in user_to_ptr()
144 *ptr.p_s32 = c->value; in user_to_ptr()
150 /* Helper function: copy the caller-provider value as the new control value */
153 return user_to_ptr(c, ctrl, ctrl->p_new); in user_to_new()
163 * It is not a fully atomic operation, just best-effort only. After all, if
174 * in case of low-level errors.
205 struct v4l2_ext_controls *cs, in prepare_ext_ctrls() argument
214 for (i = 0, h = helpers; i < cs->count; i++, h++) { in prepare_ext_ctrls()
215 struct v4l2_ext_control *c = &cs->controls[i]; in prepare_ext_ctrls()
218 u32 id = c->id & V4L2_CTRL_ID_MASK; in prepare_ext_ctrls()
220 cs->error_idx = i; in prepare_ext_ctrls()
222 if (cs->which && in prepare_ext_ctrls()
223 cs->which != V4L2_CTRL_WHICH_DEF_VAL && in prepare_ext_ctrls()
224 cs->which != V4L2_CTRL_WHICH_REQUEST_VAL && in prepare_ext_ctrls()
225 V4L2_CTRL_ID2WHICH(id) != cs->which) { in prepare_ext_ctrls()
227 "invalid which 0x%x or control id 0x%x\n", in prepare_ext_ctrls()
228 cs->which, id); in prepare_ext_ctrls()
229 return -EINVAL; in prepare_ext_ctrls()
233 * Old-style private controls are not allowed for in prepare_ext_ctrls()
238 "old-style private controls not allowed\n"); in prepare_ext_ctrls()
239 return -EINVAL; in prepare_ext_ctrls()
243 dprintk(vdev, "cannot find control id 0x%x\n", id); in prepare_ext_ctrls()
244 return -EINVAL; in prepare_ext_ctrls()
246 h->ref = ref; in prepare_ext_ctrls()
247 ctrl = ref->ctrl; in prepare_ext_ctrls()
248 if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED) { in prepare_ext_ctrls()
249 dprintk(vdev, "control id 0x%x is disabled\n", id); in prepare_ext_ctrls()
250 return -EINVAL; in prepare_ext_ctrls()
253 if (ctrl->cluster[0]->ncontrols > 1) in prepare_ext_ctrls()
255 if (ctrl->cluster[0] != ctrl) in prepare_ext_ctrls()
256 ref = find_ref_lock(hdl, ctrl->cluster[0]->id); in prepare_ext_ctrls()
257 if (ctrl->is_ptr && !ctrl->is_string) { in prepare_ext_ctrls()
258 unsigned int tot_size = ctrl->elems * ctrl->elem_size; in prepare_ext_ctrls()
260 if (c->size < tot_size) { in prepare_ext_ctrls()
266 c->size = tot_size; in prepare_ext_ctrls()
267 return -ENOSPC; in prepare_ext_ctrls()
270 "pointer control id 0x%x size too small, %d bytes but %d bytes needed\n", in prepare_ext_ctrls()
271 id, c->size, tot_size); in prepare_ext_ctrls()
272 return -EFAULT; in prepare_ext_ctrls()
274 c->size = tot_size; in prepare_ext_ctrls()
277 h->mref = ref; in prepare_ext_ctrls()
283 h->next = 0; in prepare_ext_ctrls()
287 * We are done if there were no controls that belong to a multi- in prepare_ext_ctrls()
299 mutex_lock(hdl->lock); in prepare_ext_ctrls()
302 for (i = 0; i < cs->count; i++) in prepare_ext_ctrls()
303 helpers[i].mref->helper = NULL; in prepare_ext_ctrls()
304 for (i = 0, h = helpers; i < cs->count; i++, h++) { in prepare_ext_ctrls()
305 struct v4l2_ctrl_ref *mref = h->mref; in prepare_ext_ctrls()
308 * If the mref->helper is set, then it points to an earlier in prepare_ext_ctrls()
311 if (mref->helper) { in prepare_ext_ctrls()
313 * Set the next field of mref->helper to the current in prepare_ext_ctrls()
317 mref->helper->next = i; in prepare_ext_ctrls()
322 h->mref = NULL; in prepare_ext_ctrls()
325 mref->helper = h; in prepare_ext_ctrls()
327 mutex_unlock(hdl->lock); in prepare_ext_ctrls()
332 * Handles the corner case where cs->count == 0. It checks whether the
341 return find_ref_lock(hdl, which | 1) ? 0 : -EINVAL; in class_check()
352 struct v4l2_ext_controls *cs, in v4l2_g_ext_ctrls_common() argument
361 is_default = (cs->which == V4L2_CTRL_WHICH_DEF_VAL); in v4l2_g_ext_ctrls_common()
362 is_request = (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL); in v4l2_g_ext_ctrls_common()
364 cs->error_idx = cs->count; in v4l2_g_ext_ctrls_common()
365 cs->which = V4L2_CTRL_ID2WHICH(cs->which); in v4l2_g_ext_ctrls_common()
368 return -EINVAL; in v4l2_g_ext_ctrls_common()
370 if (cs->count == 0) in v4l2_g_ext_ctrls_common()
371 return class_check(hdl, cs->which); in v4l2_g_ext_ctrls_common()
373 if (cs->count > ARRAY_SIZE(helper)) { in v4l2_g_ext_ctrls_common()
374 helpers = kvmalloc_array(cs->count, sizeof(helper[0]), in v4l2_g_ext_ctrls_common()
377 return -ENOMEM; in v4l2_g_ext_ctrls_common()
380 ret = prepare_ext_ctrls(hdl, cs, helpers, vdev, true); in v4l2_g_ext_ctrls_common()
381 cs->error_idx = cs->count; in v4l2_g_ext_ctrls_common()
383 for (i = 0; !ret && i < cs->count; i++) in v4l2_g_ext_ctrls_common()
384 if (helpers[i].ref->ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) in v4l2_g_ext_ctrls_common()
385 ret = -EACCES; in v4l2_g_ext_ctrls_common()
387 for (i = 0; !ret && i < cs->count; i++) { in v4l2_g_ext_ctrls_common()
395 master = helpers[i].mref->ctrl; in v4l2_g_ext_ctrls_common()
396 cs->error_idx = i; in v4l2_g_ext_ctrls_common()
409 ((master->flags & V4L2_CTRL_FLAG_VOLATILE) || in v4l2_g_ext_ctrls_common()
410 (master->has_volatiles && !is_cur_manual(master)))) { in v4l2_g_ext_ctrls_common()
411 for (j = 0; j < master->ncontrols; j++) in v4l2_g_ext_ctrls_common()
412 cur_to_new(master->cluster[j]); in v4l2_g_ext_ctrls_common()
432 ret = def_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
433 else if (is_request && ref->valid_p_req) in v4l2_g_ext_ctrls_common()
434 ret = req_to_user(cs->controls + idx, ref); in v4l2_g_ext_ctrls_common()
436 ret = new_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
438 ret = cur_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
445 if (cs->count > ARRAY_SIZE(helper)) in v4l2_g_ext_ctrls_common()
451 struct media_device *mdev, struct v4l2_ext_controls *cs) in v4l2_g_ext_ctrls() argument
453 if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) in v4l2_g_ext_ctrls()
454 return v4l2_g_ext_ctrls_request(hdl, vdev, mdev, cs); in v4l2_g_ext_ctrls()
456 return v4l2_g_ext_ctrls_common(hdl, cs, vdev); in v4l2_g_ext_ctrls()
461 static int validate_ctrls(struct v4l2_ext_controls *cs, in validate_ctrls() argument
469 cs->error_idx = cs->count; in validate_ctrls()
470 for (i = 0; i < cs->count; i++) { in validate_ctrls()
471 struct v4l2_ctrl *ctrl = helpers[i].ref->ctrl; in validate_ctrls()
474 cs->error_idx = i; in validate_ctrls()
476 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) { in validate_ctrls()
478 "control id 0x%x is read-only\n", in validate_ctrls()
479 ctrl->id); in validate_ctrls()
480 return -EACCES; in validate_ctrls()
485 * but it makes sense to do an up-front check as well. Once in validate_ctrls()
488 * best-effort to avoid that. in validate_ctrls()
490 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) { in validate_ctrls()
492 "control id 0x%x is grabbed, cannot set\n", in validate_ctrls()
493 ctrl->id); in validate_ctrls()
494 return -EBUSY; in validate_ctrls()
500 if (ctrl->is_ptr) in validate_ctrls()
502 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in validate_ctrls()
503 p_new.p_s64 = &cs->controls[i].value64; in validate_ctrls()
505 p_new.p_s32 = &cs->controls[i].value; in validate_ctrls()
513 /* Try or try-and-set controls */
516 struct v4l2_ext_controls *cs, in try_set_ext_ctrls_common() argument
524 cs->error_idx = cs->count; in try_set_ext_ctrls_common()
527 if (cs->which == V4L2_CTRL_WHICH_DEF_VAL) { in try_set_ext_ctrls_common()
530 return -EINVAL; in try_set_ext_ctrls_common()
533 cs->which = V4L2_CTRL_ID2WHICH(cs->which); in try_set_ext_ctrls_common()
538 return -EINVAL; in try_set_ext_ctrls_common()
541 if (cs->count == 0) in try_set_ext_ctrls_common()
542 return class_check(hdl, cs->which); in try_set_ext_ctrls_common()
544 if (cs->count > ARRAY_SIZE(helper)) { in try_set_ext_ctrls_common()
545 helpers = kvmalloc_array(cs->count, sizeof(helper[0]), in try_set_ext_ctrls_common()
548 return -ENOMEM; in try_set_ext_ctrls_common()
550 ret = prepare_ext_ctrls(hdl, cs, helpers, vdev, false); in try_set_ext_ctrls_common()
552 ret = validate_ctrls(cs, helpers, vdev, set); in try_set_ext_ctrls_common()
554 cs->error_idx = cs->count; in try_set_ext_ctrls_common()
555 for (i = 0; !ret && i < cs->count; i++) { in try_set_ext_ctrls_common()
562 cs->error_idx = i; in try_set_ext_ctrls_common()
563 master = helpers[i].mref->ctrl; in try_set_ext_ctrls_common()
567 for (j = 0; j < master->ncontrols; j++) in try_set_ext_ctrls_common()
568 if (master->cluster[j]) in try_set_ext_ctrls_common()
569 master->cluster[j]->is_new = 0; in try_set_ext_ctrls_common()
579 if (master->is_auto && master->has_volatiles && in try_set_ext_ctrls_common()
581 /* Pick an initial non-manual value */ in try_set_ext_ctrls_common()
582 s32 new_auto_val = master->manual_mode_value + 1; in try_set_ext_ctrls_common()
590 if (helpers[tmp_idx].ref->ctrl == master) in try_set_ext_ctrls_common()
591 new_auto_val = cs->controls[tmp_idx].value; in try_set_ext_ctrls_common()
598 if (new_auto_val == master->manual_mode_value) in try_set_ext_ctrls_common()
603 * Copy the new caller-supplied control values. in try_set_ext_ctrls_common()
607 struct v4l2_ctrl *ctrl = helpers[idx].ref->ctrl; in try_set_ext_ctrls_common()
609 ret = user_to_new(cs->controls + idx, ctrl); in try_set_ext_ctrls_common()
610 if (!ret && ctrl->is_ptr) { in try_set_ext_ctrls_common()
611 ret = validate_new(ctrl, ctrl->p_new); in try_set_ext_ctrls_common()
615 v4l2_ctrl_get_name(ctrl->id), ret); in try_set_ext_ctrls_common()
622 !hdl->req_obj.req && set, 0); in try_set_ext_ctrls_common()
623 if (!ret && hdl->req_obj.req && set) { in try_set_ext_ctrls_common()
624 for (j = 0; j < master->ncontrols; j++) { in try_set_ext_ctrls_common()
626 find_ref(hdl, master->cluster[j]->id); in try_set_ext_ctrls_common()
636 ret = new_to_user(cs->controls + idx, in try_set_ext_ctrls_common()
637 helpers[idx].ref->ctrl); in try_set_ext_ctrls_common()
644 if (cs->count > ARRAY_SIZE(helper)) in try_set_ext_ctrls_common()
653 struct v4l2_ext_controls *cs, bool set) in try_set_ext_ctrls() argument
657 if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) in try_set_ext_ctrls()
658 return try_set_ext_ctrls_request(fh, hdl, vdev, mdev, cs, set); in try_set_ext_ctrls()
660 ret = try_set_ext_ctrls_common(fh, hdl, cs, vdev, set); in try_set_ext_ctrls()
672 struct v4l2_ext_controls *cs) in v4l2_try_ext_ctrls() argument
674 return try_set_ext_ctrls(NULL, hdl, vdev, mdev, cs, false); in v4l2_try_ext_ctrls()
682 struct v4l2_ext_controls *cs) in v4l2_s_ext_ctrls() argument
684 return try_set_ext_ctrls(fh, hdl, vdev, mdev, cs, true); in v4l2_s_ext_ctrls()
695 struct v4l2_ctrl *master = ctrl->cluster[0]; in get_ctrl()
703 if (!ctrl->is_int && ctrl->type != V4L2_CTRL_TYPE_INTEGER64) in get_ctrl()
704 return -EINVAL; in get_ctrl()
706 if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) in get_ctrl()
707 return -EACCES; in get_ctrl()
711 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) { in get_ctrl()
712 for (i = 0; i < master->ncontrols; i++) in get_ctrl()
713 cur_to_new(master->cluster[i]); in get_ctrl()
725 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_g_ctrl()
729 if (!ctrl || !ctrl->is_int) in v4l2_g_ctrl()
730 return -EINVAL; in v4l2_g_ctrl()
732 control->value = c.value; in v4l2_g_ctrl()
740 struct v4l2_ctrl *master = ctrl->cluster[0]; in set_ctrl()
745 for (i = 0; i < master->ncontrols; i++) in set_ctrl()
746 if (master->cluster[i]) in set_ctrl()
747 master->cluster[i]->is_new = 0; in set_ctrl()
749 ret = validate_new(ctrl, ctrl->p_new); in set_ctrl()
758 if (master->is_auto && master->has_volatiles && ctrl == master && in set_ctrl()
759 !is_cur_manual(master) && ctrl->val == master->manual_mode_value) in set_ctrl()
762 ctrl->is_new = 1; in set_ctrl()
784 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_s_ctrl()
785 struct v4l2_ext_control c = { control->id }; in v4l2_s_ctrl()
788 if (!ctrl || !ctrl->is_int) in v4l2_s_ctrl()
789 return -EINVAL; in v4l2_s_ctrl()
791 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) in v4l2_s_ctrl()
792 return -EACCES; in v4l2_s_ctrl()
794 c.value = control->value; in v4l2_s_ctrl()
796 control->value = c.value; in v4l2_s_ctrl()
810 if (WARN_ON(!ctrl->is_int)) in v4l2_ctrl_g_ctrl()
823 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64)) in v4l2_ctrl_g_ctrl_int64()
833 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl()
836 if (WARN_ON(!ctrl->is_int)) in __v4l2_ctrl_s_ctrl()
837 return -EINVAL; in __v4l2_ctrl_s_ctrl()
838 ctrl->val = val; in __v4l2_ctrl_s_ctrl()
845 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_int64()
848 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64)) in __v4l2_ctrl_s_ctrl_int64()
849 return -EINVAL; in __v4l2_ctrl_s_ctrl_int64()
850 *ctrl->p_new.p_s64 = val; in __v4l2_ctrl_s_ctrl_int64()
857 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_string()
860 if (WARN_ON(ctrl->type != V4L2_CTRL_TYPE_STRING)) in __v4l2_ctrl_s_ctrl_string()
861 return -EINVAL; in __v4l2_ctrl_s_ctrl_string()
862 strscpy(ctrl->p_new.p_char, s, ctrl->maximum + 1); in __v4l2_ctrl_s_ctrl_string()
870 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_compound()
873 if (WARN_ON(ctrl->type != type)) in __v4l2_ctrl_s_ctrl_compound()
874 return -EINVAL; in __v4l2_ctrl_s_ctrl_compound()
875 memcpy(ctrl->p_new.p, p, ctrl->elems * ctrl->elem_size); in __v4l2_ctrl_s_ctrl_compound()
890 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_modify_range()
892 switch (ctrl->type) { in __v4l2_ctrl_modify_range()
902 if (ctrl->is_array) in __v4l2_ctrl_modify_range()
903 return -EINVAL; in __v4l2_ctrl_modify_range()
904 ret = check_range(ctrl->type, min, max, step, def); in __v4l2_ctrl_modify_range()
909 return -EINVAL; in __v4l2_ctrl_modify_range()
911 if (ctrl->minimum != min || ctrl->maximum != max || in __v4l2_ctrl_modify_range()
912 ctrl->step != step || ctrl->default_value != def) { in __v4l2_ctrl_modify_range()
914 ctrl->minimum = min; in __v4l2_ctrl_modify_range()
915 ctrl->maximum = max; in __v4l2_ctrl_modify_range()
916 ctrl->step = step; in __v4l2_ctrl_modify_range()
917 ctrl->default_value = def; in __v4l2_ctrl_modify_range()
920 if (validate_new(ctrl, ctrl->p_new)) { in __v4l2_ctrl_modify_range()
921 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in __v4l2_ctrl_modify_range()
922 *ctrl->p_new.p_s64 = def; in __v4l2_ctrl_modify_range()
924 *ctrl->p_new.p_s32 = def; in __v4l2_ctrl_modify_range()
927 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in __v4l2_ctrl_modify_range()
928 value_changed = *ctrl->p_new.p_s64 != *ctrl->p_cur.p_s64; in __v4l2_ctrl_modify_range()
930 value_changed = *ctrl->p_new.p_s32 != *ctrl->p_cur.p_s32; in __v4l2_ctrl_modify_range()
943 u32 id = qc->id & V4L2_CTRL_ID_MASK; in v4l2_query_ext_ctrl()
948 return -EINVAL; in v4l2_query_ext_ctrl()
950 mutex_lock(hdl->lock); in v4l2_query_ext_ctrl()
955 if ((qc->id & next_flags) && !list_empty(&hdl->ctrl_refs)) { in v4l2_query_ext_ctrl()
961 if ((qc->id & next_flags) == V4L2_CTRL_FLAG_NEXT_COMPOUND) { in v4l2_query_ext_ctrl()
964 } else if ((qc->id & next_flags) == next_flags) { in v4l2_query_ext_ctrl()
969 /* Find the next control with ID > qc->id */ in v4l2_query_ext_ctrl()
972 if (id >= node2id(hdl->ctrl_refs.prev)) { in v4l2_query_ext_ctrl()
979 list_for_each_entry_continue(ref, &hdl->ctrl_refs, node) { in v4l2_query_ext_ctrl()
980 is_compound = ref->ctrl->is_array || in v4l2_query_ext_ctrl()
981 ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; in v4l2_query_ext_ctrl()
982 if (id < ref->ctrl->id && in v4l2_query_ext_ctrl()
986 if (&ref->node == &hdl->ctrl_refs) in v4l2_query_ext_ctrl()
995 list_for_each_entry(ref, &hdl->ctrl_refs, node) { in v4l2_query_ext_ctrl()
996 is_compound = ref->ctrl->is_array || in v4l2_query_ext_ctrl()
997 ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; in v4l2_query_ext_ctrl()
998 if (id < ref->ctrl->id && in v4l2_query_ext_ctrl()
1002 if (&ref->node == &hdl->ctrl_refs) in v4l2_query_ext_ctrl()
1006 mutex_unlock(hdl->lock); in v4l2_query_ext_ctrl()
1009 return -EINVAL; in v4l2_query_ext_ctrl()
1011 ctrl = ref->ctrl; in v4l2_query_ext_ctrl()
1014 qc->id = id; in v4l2_query_ext_ctrl()
1016 qc->id = ctrl->id; in v4l2_query_ext_ctrl()
1017 strscpy(qc->name, ctrl->name, sizeof(qc->name)); in v4l2_query_ext_ctrl()
1018 qc->flags = user_flags(ctrl); in v4l2_query_ext_ctrl()
1019 qc->type = ctrl->type; in v4l2_query_ext_ctrl()
1020 qc->elem_size = ctrl->elem_size; in v4l2_query_ext_ctrl()
1021 qc->elems = ctrl->elems; in v4l2_query_ext_ctrl()
1022 qc->nr_of_dims = ctrl->nr_of_dims; in v4l2_query_ext_ctrl()
1023 memcpy(qc->dims, ctrl->dims, qc->nr_of_dims * sizeof(qc->dims[0])); in v4l2_query_ext_ctrl()
1024 qc->minimum = ctrl->minimum; in v4l2_query_ext_ctrl()
1025 qc->maximum = ctrl->maximum; in v4l2_query_ext_ctrl()
1026 qc->default_value = ctrl->default_value; in v4l2_query_ext_ctrl()
1027 if (ctrl->type == V4L2_CTRL_TYPE_MENU || in v4l2_query_ext_ctrl()
1028 ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU) in v4l2_query_ext_ctrl()
1029 qc->step = 1; in v4l2_query_ext_ctrl()
1031 qc->step = ctrl->step; in v4l2_query_ext_ctrl()
1039 struct v4l2_query_ext_ctrl qec = { qc->id }; in v4l2_queryctrl()
1046 qc->id = qec.id; in v4l2_queryctrl()
1047 qc->type = qec.type; in v4l2_queryctrl()
1048 qc->flags = qec.flags; in v4l2_queryctrl()
1049 strscpy(qc->name, qec.name, sizeof(qc->name)); in v4l2_queryctrl()
1050 switch (qc->type) { in v4l2_queryctrl()
1057 qc->minimum = qec.minimum; in v4l2_queryctrl()
1058 qc->maximum = qec.maximum; in v4l2_queryctrl()
1059 qc->step = qec.step; in v4l2_queryctrl()
1060 qc->default_value = qec.default_value; in v4l2_queryctrl()
1063 qc->minimum = 0; in v4l2_queryctrl()
1064 qc->maximum = 0; in v4l2_queryctrl()
1065 qc->step = 0; in v4l2_queryctrl()
1066 qc->default_value = 0; in v4l2_queryctrl()
1077 u32 i = qm->index; in v4l2_querymenu()
1079 ctrl = v4l2_ctrl_find(hdl, qm->id); in v4l2_querymenu()
1081 return -EINVAL; in v4l2_querymenu()
1083 qm->reserved = 0; in v4l2_querymenu()
1085 switch (ctrl->type) { in v4l2_querymenu()
1087 if (!ctrl->qmenu) in v4l2_querymenu()
1088 return -EINVAL; in v4l2_querymenu()
1091 if (!ctrl->qmenu_int) in v4l2_querymenu()
1092 return -EINVAL; in v4l2_querymenu()
1095 return -EINVAL; in v4l2_querymenu()
1098 if (i < ctrl->minimum || i > ctrl->maximum) in v4l2_querymenu()
1099 return -EINVAL; in v4l2_querymenu()
1102 if (ctrl->menu_skip_mask & (1ULL << i)) in v4l2_querymenu()
1103 return -EINVAL; in v4l2_querymenu()
1105 if (ctrl->type == V4L2_CTRL_TYPE_MENU) { in v4l2_querymenu()
1106 if (!ctrl->qmenu[i] || ctrl->qmenu[i][0] == '\0') in v4l2_querymenu()
1107 return -EINVAL; in v4l2_querymenu()
1108 strscpy(qm->name, ctrl->qmenu[i], sizeof(qm->name)); in v4l2_querymenu()
1110 qm->value = ctrl->qmenu_int[i]; in v4l2_querymenu()
1123 struct v4l2_fh *vfh = file->private_data; in v4l2_ctrl_log_status()
1125 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) && vfd->v4l2_dev) in v4l2_ctrl_log_status()
1126 v4l2_ctrl_handler_log_status(vfh->ctrl_handler, in v4l2_ctrl_log_status()
1127 vfd->v4l2_dev->name); in v4l2_ctrl_log_status()
1134 v4l2_ctrl_handler_log_status(sd->ctrl_handler, sd->name); in v4l2_ctrl_subdev_log_status()
1146 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); in v4l2_ctrl_add_event()
1149 return -EINVAL; in v4l2_ctrl_add_event()
1152 list_add_tail(&sev->node, &ctrl->ev_subs); in v4l2_ctrl_add_event()
1153 if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS && in v4l2_ctrl_add_event()
1154 (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL)) in v4l2_ctrl_add_event()
1155 send_initial_event(sev->fh, ctrl); in v4l2_ctrl_add_event()
1162 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); in v4l2_ctrl_del_event()
1168 list_del(&sev->node); in v4l2_ctrl_del_event()
1174 u32 old_changes = old->u.ctrl.changes; in v4l2_ctrl_replace()
1176 old->u.ctrl = new->u.ctrl; in v4l2_ctrl_replace()
1177 old->u.ctrl.changes |= old_changes; in v4l2_ctrl_replace()
1183 new->u.ctrl.changes |= old->u.ctrl.changes; in v4l2_ctrl_merge()
1198 if (sub->type == V4L2_EVENT_CTRL) in v4l2_ctrl_subscribe_event()
1200 return -EINVAL; in v4l2_ctrl_subscribe_event()
1207 if (!sd->ctrl_handler) in v4l2_ctrl_subdev_subscribe_event()
1208 return -EINVAL; in v4l2_ctrl_subdev_subscribe_event()
1218 struct v4l2_fh *fh = file->private_data; in v4l2_ctrl_poll()
1220 poll_wait(file, &fh->wait, wait); in v4l2_ctrl_poll()