Lines Matching refs:hdl

1694 static inline int handler_set_err(struct v4l2_ctrl_handler *hdl, int err)  in handler_set_err()  argument
1696 if (hdl->error == 0) in handler_set_err()
1697 hdl->error = err; in handler_set_err()
1702 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_handler_init_class() argument
1706 hdl->lock = &hdl->_lock; in v4l2_ctrl_handler_init_class()
1707 mutex_init(hdl->lock); in v4l2_ctrl_handler_init_class()
1708 lockdep_set_class_and_name(hdl->lock, key, name); in v4l2_ctrl_handler_init_class()
1709 INIT_LIST_HEAD(&hdl->ctrls); in v4l2_ctrl_handler_init_class()
1710 INIT_LIST_HEAD(&hdl->ctrl_refs); in v4l2_ctrl_handler_init_class()
1711 hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8; in v4l2_ctrl_handler_init_class()
1712 hdl->buckets = kcalloc(hdl->nr_of_buckets, sizeof(hdl->buckets[0]), in v4l2_ctrl_handler_init_class()
1714 hdl->error = hdl->buckets ? 0 : -ENOMEM; in v4l2_ctrl_handler_init_class()
1715 return hdl->error; in v4l2_ctrl_handler_init_class()
1720 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl) in v4l2_ctrl_handler_free() argument
1726 if (hdl == NULL || hdl->buckets == NULL) in v4l2_ctrl_handler_free()
1729 mutex_lock(hdl->lock); in v4l2_ctrl_handler_free()
1731 list_for_each_entry_safe(ref, next_ref, &hdl->ctrl_refs, node) { in v4l2_ctrl_handler_free()
1736 list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) { in v4l2_ctrl_handler_free()
1742 kfree(hdl->buckets); in v4l2_ctrl_handler_free()
1743 hdl->buckets = NULL; in v4l2_ctrl_handler_free()
1744 hdl->cached = NULL; in v4l2_ctrl_handler_free()
1745 hdl->error = 0; in v4l2_ctrl_handler_free()
1746 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_free()
1757 struct v4l2_ctrl_handler *hdl, u32 id) in find_private_ref() argument
1762 list_for_each_entry(ref, &hdl->ctrl_refs, node) { in find_private_ref()
1778 static struct v4l2_ctrl_ref *find_ref(struct v4l2_ctrl_handler *hdl, u32 id) in find_ref() argument
1787 return find_private_ref(hdl, id); in find_ref()
1788 bucket = id % hdl->nr_of_buckets; in find_ref()
1791 if (hdl->cached && hdl->cached->ctrl->id == id) in find_ref()
1792 return hdl->cached; in find_ref()
1795 ref = hdl->buckets ? hdl->buckets[bucket] : NULL; in find_ref()
1800 hdl->cached = ref; /* cache it! */ in find_ref()
1806 struct v4l2_ctrl_handler *hdl, u32 id) in find_ref_lock() argument
1810 if (hdl) { in find_ref_lock()
1811 mutex_lock(hdl->lock); in find_ref_lock()
1812 ref = find_ref(hdl, id); in find_ref_lock()
1813 mutex_unlock(hdl->lock); in find_ref_lock()
1819 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id) in v4l2_ctrl_find() argument
1821 struct v4l2_ctrl_ref *ref = find_ref_lock(hdl, id); in v4l2_ctrl_find()
1828 static int handler_new_ref(struct v4l2_ctrl_handler *hdl, in handler_new_ref() argument
1835 int bucket = id % hdl->nr_of_buckets; /* which bucket to use */ in handler_new_ref()
1842 id != class_ctrl && find_ref_lock(hdl, class_ctrl) == NULL) in handler_new_ref()
1843 if (!v4l2_ctrl_new_std(hdl, NULL, class_ctrl, 0, 0, 0, 0)) in handler_new_ref()
1844 return hdl->error; in handler_new_ref()
1846 if (hdl->error) in handler_new_ref()
1847 return hdl->error; in handler_new_ref()
1851 return handler_set_err(hdl, -ENOMEM); in handler_new_ref()
1853 if (ctrl->handler == hdl) { in handler_new_ref()
1864 mutex_lock(hdl->lock); in handler_new_ref()
1870 if (list_empty(&hdl->ctrl_refs) || id > node2id(hdl->ctrl_refs.prev)) { in handler_new_ref()
1871 list_add_tail(&new_ref->node, &hdl->ctrl_refs); in handler_new_ref()
1876 list_for_each_entry(ref, &hdl->ctrl_refs, node) { in handler_new_ref()
1890 new_ref->next = hdl->buckets[bucket]; in handler_new_ref()
1891 hdl->buckets[bucket] = new_ref; in handler_new_ref()
1894 mutex_unlock(hdl->lock); in handler_new_ref()
1899 static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new() argument
1918 if (hdl->error) in v4l2_ctrl_new()
1958 handler_set_err(hdl, -ERANGE); in v4l2_ctrl_new()
1963 handler_set_err(hdl, err); in v4l2_ctrl_new()
1967 handler_set_err(hdl, -ERANGE); in v4l2_ctrl_new()
1973 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new()
1991 handler_set_err(hdl, -ENOMEM); in v4l2_ctrl_new()
1997 ctrl->handler = hdl; in v4l2_ctrl_new()
2037 if (handler_new_ref(hdl, ctrl)) { in v4l2_ctrl_new()
2041 mutex_lock(hdl->lock); in v4l2_ctrl_new()
2042 list_add_tail(&ctrl->node, &hdl->ctrls); in v4l2_ctrl_new()
2043 mutex_unlock(hdl->lock); in v4l2_ctrl_new()
2047 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new_custom() argument
2076 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_custom()
2080 ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->type_ops, cfg->id, name, in v4l2_ctrl_new_custom()
2092 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new_std() argument
2104 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std()
2107 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, in v4l2_ctrl_new_std()
2114 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new_std_menu() argument
2137 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu()
2140 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, in v4l2_ctrl_new_std_menu()
2147 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new_std_menu_items() argument
2163 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu_items()
2169 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu_items()
2172 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, in v4l2_ctrl_new_std_menu_items()
2180 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new_int_menu() argument
2194 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_int_menu()
2197 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, in v4l2_ctrl_new_int_menu()
2204 struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_add_ctrl() argument
2207 if (hdl == NULL || hdl->error) in v4l2_ctrl_add_ctrl()
2210 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_add_ctrl()
2213 if (ctrl->handler == hdl) in v4l2_ctrl_add_ctrl()
2215 return handler_new_ref(hdl, ctrl) ? NULL : ctrl; in v4l2_ctrl_add_ctrl()
2220 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_add_handler() argument
2228 if (!hdl || !add || hdl == add) in v4l2_ctrl_add_handler()
2230 if (hdl->error) in v4l2_ctrl_add_handler()
2231 return hdl->error; in v4l2_ctrl_add_handler()
2245 ret = handler_new_ref(hdl, ctrl); in v4l2_ctrl_add_handler()
2397 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_handler_log_status() argument
2404 if (hdl == NULL) in v4l2_ctrl_handler_log_status()
2411 mutex_lock(hdl->lock); in v4l2_ctrl_handler_log_status()
2412 list_for_each_entry(ctrl, &hdl->ctrls, node) in v4l2_ctrl_handler_log_status()
2415 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_log_status()
2427 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl) in v4l2_ctrl_handler_setup() argument
2432 if (hdl == NULL) in v4l2_ctrl_handler_setup()
2434 mutex_lock(hdl->lock); in v4l2_ctrl_handler_setup()
2435 list_for_each_entry(ctrl, &hdl->ctrls, node) in v4l2_ctrl_handler_setup()
2438 list_for_each_entry(ctrl, &hdl->ctrls, node) { in v4l2_ctrl_handler_setup()
2459 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_setup()
2465 int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctrl *qc) in v4l2_query_ext_ctrl() argument
2472 if (hdl == NULL) in v4l2_query_ext_ctrl()
2475 mutex_lock(hdl->lock); in v4l2_query_ext_ctrl()
2478 ref = find_ref(hdl, id); in v4l2_query_ext_ctrl()
2480 if ((qc->id & next_flags) && !list_empty(&hdl->ctrl_refs)) { in v4l2_query_ext_ctrl()
2497 if (id >= node2id(hdl->ctrl_refs.prev)) { in v4l2_query_ext_ctrl()
2502 list_for_each_entry_continue(ref, &hdl->ctrl_refs, node) { in v4l2_query_ext_ctrl()
2509 if (&ref->node == &hdl->ctrl_refs) in v4l2_query_ext_ctrl()
2516 list_for_each_entry(ref, &hdl->ctrl_refs, node) { in v4l2_query_ext_ctrl()
2523 if (&ref->node == &hdl->ctrl_refs) in v4l2_query_ext_ctrl()
2527 mutex_unlock(hdl->lock); in v4l2_query_ext_ctrl()
2560 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc) in v4l2_queryctrl() argument
2565 rc = v4l2_query_ext_ctrl(hdl, &qec); in v4l2_queryctrl()
2605 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm) in v4l2_querymenu() argument
2610 ctrl = v4l2_ctrl_find(hdl, qm->id); in v4l2_querymenu()
2696 static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, in prepare_ext_ctrls() argument
2720 ref = find_ref_lock(hdl, id); in prepare_ext_ctrls()
2730 ref = find_ref_lock(hdl, ctrl->cluster[0]->id); in prepare_ext_ctrls()
2761 mutex_lock(hdl->lock); in prepare_ext_ctrls()
2783 mutex_unlock(hdl->lock); in prepare_ext_ctrls()
2790 static int class_check(struct v4l2_ctrl_handler *hdl, u32 ctrl_class) in class_check() argument
2793 return list_empty(&hdl->ctrl_refs) ? -EINVAL : 0; in class_check()
2794 return find_ref_lock(hdl, ctrl_class | 1) ? 0 : -EINVAL; in class_check()
2800 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) in v4l2_g_ext_ctrls() argument
2810 if (hdl == NULL) in v4l2_g_ext_ctrls()
2814 return class_check(hdl, cs->ctrl_class); in v4l2_g_ext_ctrls()
2823 ret = prepare_ext_ctrls(hdl, cs, helpers, true); in v4l2_g_ext_ctrls()
2909 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control) in v4l2_g_ctrl() argument
2911 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_g_ctrl()
3057 static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, in try_set_ext_ctrls() argument
3069 if (hdl == NULL) in try_set_ext_ctrls()
3073 return class_check(hdl, cs->ctrl_class); in try_set_ext_ctrls()
3081 ret = prepare_ext_ctrls(hdl, cs, helpers, false); in try_set_ext_ctrls()
3158 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) in v4l2_try_ext_ctrls() argument
3160 return try_set_ext_ctrls(NULL, hdl, cs, false); in v4l2_try_ext_ctrls()
3164 int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, in v4l2_s_ext_ctrls() argument
3167 return try_set_ext_ctrls(fh, hdl, cs, true); in v4l2_s_ext_ctrls()
3225 int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, in v4l2_s_ctrl() argument
3228 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_s_ctrl()