提交 77068d36 编写于 作者: H Hans Verkuil 提交者: Mauro Carvalho Chehab

[media] v4l2-ctrls/event: remove struct v4l2_ctrl_fh, instead use v4l2_subscribed_event

The v4l2_ctrl_fh struct connected v4l2_ctrl with v4l2_fh so the control
would know which filehandles subscribed to it. However, it is much easier
to use struct v4l2_subscribed_event directly for that and get rid of that
intermediate struct.
Signed-off-by: NHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: NMauro Carvalho Chehab <mchehab@redhat.com>
上级 523f46d6
master alk-4.19.24 alk-4.19.30 alk-4.19.34 alk-4.19.36 alk-4.19.43 alk-4.19.48 alk-4.19.57 ck-4.19.67 ck-4.19.81 ck-4.19.91 github/fork/deepanshu1422/fix-typo-in-comment github/fork/haosdent/fix-typo linux-next v4.19.91 v4.19.90 v4.19.89 v4.19.88 v4.19.87 v4.19.86 v4.19.85 v4.19.84 v4.19.83 v4.19.82 v4.19.81 v4.19.80 v4.19.79 v4.19.78 v4.19.77 v4.19.76 v4.19.75 v4.19.74 v4.19.73 v4.19.72 v4.19.71 v4.19.70 v4.19.69 v4.19.68 v4.19.67 v4.19.66 v4.19.65 v4.19.64 v4.19.63 v4.19.62 v4.19.61 v4.19.60 v4.19.59 v4.19.58 v4.19.57 v4.19.56 v4.19.55 v4.19.54 v4.19.53 v4.19.52 v4.19.51 v4.19.50 v4.19.49 v4.19.48 v4.19.47 v4.19.46 v4.19.45 v4.19.44 v4.19.43 v4.19.42 v4.19.41 v4.19.40 v4.19.39 v4.19.38 v4.19.37 v4.19.36 v4.19.35 v4.19.34 v4.19.33 v4.19.32 v4.19.31 v4.19.30 v4.19.29 v4.19.28 v4.19.27 v4.19.26 v4.19.25 v4.19.24 v4.19.23 v4.19.22 v4.19.21 v4.19.20 v4.19.19 v4.19.18 v4.19.17 v4.19.16 v4.19.15 v4.19.14 v4.19.13 v4.19.12 v4.19.11 v4.19.10 v4.19.9 v4.19.8 v4.19.7 v4.19.6 v4.19.5 v4.19.4 v4.19.3 v4.19.2 v4.19.1 v4.19 v4.19-rc8 v4.19-rc7 v4.19-rc6 v4.19-rc5 v4.19-rc4 v4.19-rc3 v4.19-rc2 v4.19-rc1 ck-release-21 ck-release-20 ck-release-19.2 ck-release-19.1 ck-release-19 ck-release-18 ck-release-17.2 ck-release-17.1 ck-release-17 ck-release-16 ck-release-15.1 ck-release-15 ck-release-14 ck-release-13.2 ck-release-13 ck-release-12 ck-release-11 ck-release-10 ck-release-9 ck-release-7 alk-release-15 alk-release-14 alk-release-13.2 alk-release-13 alk-release-12 alk-release-11 alk-release-10 alk-release-9 alk-release-7
无相关合并请求
......@@ -581,15 +581,15 @@ static void fill_event(struct v4l2_event *ev, struct v4l2_ctrl *ctrl, u32 change
static void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes)
{
struct v4l2_event ev;
struct v4l2_ctrl_fh *pos;
struct v4l2_subscribed_event *sev;
if (list_empty(&ctrl->fhs))
if (list_empty(&ctrl->ev_subs))
return;
fill_event(&ev, ctrl, changes);
list_for_each_entry(pos, &ctrl->fhs, node)
if (pos->fh != fh)
v4l2_event_queue_fh(pos->fh, &ev);
list_for_each_entry(sev, &ctrl->ev_subs, node)
if (sev->fh && sev->fh != fh)
v4l2_event_queue_fh(sev->fh, &ev);
}
/* Helper function: copy the current control value back to the caller */
......@@ -867,7 +867,7 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
{
struct v4l2_ctrl_ref *ref, *next_ref;
struct v4l2_ctrl *ctrl, *next_ctrl;
struct v4l2_ctrl_fh *ctrl_fh, *next_ctrl_fh;
struct v4l2_subscribed_event *sev, *next_sev;
if (hdl == NULL || hdl->buckets == NULL)
return;
......@@ -881,10 +881,8 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
/* Free all controls owned by the handler */
list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) {
list_del(&ctrl->node);
list_for_each_entry_safe(ctrl_fh, next_ctrl_fh, &ctrl->fhs, node) {
list_del(&ctrl_fh->node);
kfree(ctrl_fh);
}
list_for_each_entry_safe(sev, next_sev, &ctrl->ev_subs, node)
list_del(&sev->node);
kfree(ctrl);
}
kfree(hdl->buckets);
......@@ -1084,7 +1082,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
}
INIT_LIST_HEAD(&ctrl->node);
INIT_LIST_HEAD(&ctrl->fhs);
INIT_LIST_HEAD(&ctrl->ev_subs);
ctrl->handler = hdl;
ctrl->ops = ops;
ctrl->id = id;
......@@ -2028,41 +2026,31 @@ int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
}
EXPORT_SYMBOL(v4l2_ctrl_s_ctrl);
void v4l2_ctrl_add_fh(struct v4l2_ctrl_handler *hdl,
struct v4l2_ctrl_fh *ctrl_fh,
struct v4l2_event_subscription *sub)
void v4l2_ctrl_add_event(struct v4l2_ctrl *ctrl,
struct v4l2_subscribed_event *sev)
{
struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, sub->id);
v4l2_ctrl_lock(ctrl);
list_add_tail(&ctrl_fh->node, &ctrl->fhs);
list_add_tail(&sev->node, &ctrl->ev_subs);
if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS &&
(sub->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL)) {
(sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL)) {
struct v4l2_event ev;
fill_event(&ev, ctrl, V4L2_EVENT_CTRL_CH_VALUE |
V4L2_EVENT_CTRL_CH_FLAGS);
v4l2_event_queue_fh(ctrl_fh->fh, &ev);
v4l2_event_queue_fh(sev->fh, &ev);
}
v4l2_ctrl_unlock(ctrl);
}
EXPORT_SYMBOL(v4l2_ctrl_add_fh);
EXPORT_SYMBOL(v4l2_ctrl_add_event);
void v4l2_ctrl_del_fh(struct v4l2_ctrl *ctrl, struct v4l2_fh *fh)
void v4l2_ctrl_del_event(struct v4l2_ctrl *ctrl,
struct v4l2_subscribed_event *sev)
{
struct v4l2_ctrl_fh *pos;
v4l2_ctrl_lock(ctrl);
list_for_each_entry(pos, &ctrl->fhs, node) {
if (pos->fh == fh) {
list_del(&pos->node);
kfree(pos);
break;
}
}
list_del(&sev->node);
v4l2_ctrl_unlock(ctrl);
}
EXPORT_SYMBOL(v4l2_ctrl_del_fh);
EXPORT_SYMBOL(v4l2_ctrl_del_event);
int v4l2_ctrl_subscribe_fh(struct v4l2_fh *fh,
struct v4l2_event_subscription *sub, unsigned n)
......
......@@ -213,7 +213,6 @@ int v4l2_event_subscribe(struct v4l2_fh *fh,
{
struct v4l2_subscribed_event *sev, *found_ev;
struct v4l2_ctrl *ctrl = NULL;
struct v4l2_ctrl_fh *ctrl_fh = NULL;
unsigned long flags;
if (sub->type == V4L2_EVENT_CTRL) {
......@@ -222,17 +221,9 @@ int v4l2_event_subscribe(struct v4l2_fh *fh,
return -EINVAL;
}
sev = kmalloc(sizeof(*sev), GFP_KERNEL);
sev = kzalloc(sizeof(*sev), GFP_KERNEL);
if (!sev)
return -ENOMEM;
if (ctrl) {
ctrl_fh = kzalloc(sizeof(*ctrl_fh), GFP_KERNEL);
if (!ctrl_fh) {
kfree(sev);
return -ENOMEM;
}
ctrl_fh->fh = fh;
}
spin_lock_irqsave(&fh->vdev->fh_lock, flags);
......@@ -241,22 +232,19 @@ int v4l2_event_subscribe(struct v4l2_fh *fh,
INIT_LIST_HEAD(&sev->list);
sev->type = sub->type;
sev->id = sub->id;
sev->fh = fh;
sev->flags = sub->flags;
list_add(&sev->list, &fh->subscribed);
sev = NULL;
}
spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
/* v4l2_ctrl_add_fh uses a mutex, so do this outside the spin lock */
if (ctrl) {
if (found_ev)
kfree(ctrl_fh);
else
v4l2_ctrl_add_fh(fh->ctrl_handler, ctrl_fh, sub);
}
kfree(sev);
if (found_ev)
kfree(sev);
else if (ctrl)
v4l2_ctrl_add_event(ctrl, sev);
return 0;
}
......@@ -298,15 +286,17 @@ int v4l2_event_unsubscribe(struct v4l2_fh *fh,
spin_lock_irqsave(&fh->vdev->fh_lock, flags);
sev = v4l2_event_subscribed(fh, sub->type, sub->id);
if (sev != NULL)
if (sev != NULL) {
list_del(&sev->list);
sev->fh = NULL;
}
spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
if (sev->type == V4L2_EVENT_CTRL) {
if (sev && sev->type == V4L2_EVENT_CTRL) {
struct v4l2_ctrl *ctrl = v4l2_ctrl_find(fh->ctrl_handler, sev->id);
if (ctrl)
v4l2_ctrl_del_fh(ctrl, fh);
v4l2_ctrl_del_event(ctrl, sev);
}
kfree(sev);
......
......@@ -31,6 +31,7 @@ struct v4l2_ctrl;
struct video_device;
struct v4l2_subdev;
struct v4l2_event_subscription;
struct v4l2_subscribed_event;
struct v4l2_fh;
/** struct v4l2_ctrl_ops - The control operations that the driver has to provide.
......@@ -53,6 +54,7 @@ struct v4l2_ctrl_ops {
/** struct v4l2_ctrl - The control structure.
* @node: The list node.
* @ev_subs: The list of control event subscriptions.
* @handler: The handler that owns the control.
* @cluster: Point to start of cluster array.
* @ncontrols: Number of controls in cluster array.
......@@ -108,7 +110,7 @@ struct v4l2_ctrl_ops {
struct v4l2_ctrl {
/* Administrative fields */
struct list_head node;
struct list_head fhs;
struct list_head ev_subs;
struct v4l2_ctrl_handler *handler;
struct v4l2_ctrl **cluster;
unsigned ncontrols;
......@@ -184,11 +186,6 @@ struct v4l2_ctrl_handler {
int error;
};
struct v4l2_ctrl_fh {
struct list_head node;
struct v4l2_fh *fh;
};
/** struct v4l2_ctrl_config - Control configuration structure.
* @ops: The control ops.
* @id: The control ID.
......@@ -497,10 +494,10 @@ s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
/* Internal helper functions that deal with control events. */
void v4l2_ctrl_add_fh(struct v4l2_ctrl_handler *hdl,
struct v4l2_ctrl_fh *ctrl_fh,
struct v4l2_event_subscription *sub);
void v4l2_ctrl_del_fh(struct v4l2_ctrl *ctrl, struct v4l2_fh *fh);
void v4l2_ctrl_add_event(struct v4l2_ctrl *ctrl,
struct v4l2_subscribed_event *sev);
void v4l2_ctrl_del_event(struct v4l2_ctrl *ctrl,
struct v4l2_subscribed_event *sev);
/** v4l2_ctrl_subscribe_fh() - Helper function that subscribes a control event.
* @fh: The file handler that subscribed the control event.
......
......@@ -38,9 +38,18 @@ struct v4l2_kevent {
};
struct v4l2_subscribed_event {
/* list node for the v4l2_fh->subscribed list */
struct list_head list;
/* event type */
u32 type;
/* associated object ID (e.g. control ID) */
u32 id;
/* copy of v4l2_event_subscription->flags */
u32 flags;
/* filehandle that subscribed to this event */
struct v4l2_fh *fh;
/* list node that hooks into the object's event list (if there is one) */
struct list_head node;
};
int v4l2_event_alloc(struct v4l2_fh *fh, unsigned int n);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部