Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 1 | /* |
| 2 | * v4l2-event.c |
| 3 | * |
| 4 | * V4L2 events. |
| 5 | * |
| 6 | * Copyright (C) 2009--2010 Nokia Corporation. |
| 7 | * |
| 8 | * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * version 2 as published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 22 | * 02110-1301 USA |
| 23 | */ |
| 24 | |
| 25 | #include <media/v4l2-dev.h> |
| 26 | #include <media/v4l2-fh.h> |
| 27 | #include <media/v4l2-event.h> |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 28 | #include <media/v4l2-ctrls.h> |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 29 | |
| 30 | #include <linux/sched.h> |
| 31 | #include <linux/slab.h> |
Paul Gortmaker | 35a2463 | 2011-08-01 15:26:38 -0400 | [diff] [blame] | 32 | #include <linux/export.h> |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 33 | |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 34 | static unsigned sev_pos(const struct v4l2_subscribed_event *sev, unsigned idx) |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 35 | { |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 36 | idx += sev->first; |
| 37 | return idx >= sev->elems ? idx - sev->elems : idx; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 38 | } |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 39 | |
| 40 | static int __v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event) |
| 41 | { |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 42 | struct v4l2_kevent *kev; |
| 43 | unsigned long flags; |
| 44 | |
| 45 | spin_lock_irqsave(&fh->vdev->fh_lock, flags); |
| 46 | |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 47 | if (list_empty(&fh->available)) { |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 48 | spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); |
| 49 | return -ENOENT; |
| 50 | } |
| 51 | |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 52 | WARN_ON(fh->navailable == 0); |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 53 | |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 54 | kev = list_first_entry(&fh->available, struct v4l2_kevent, list); |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 55 | list_del(&kev->list); |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 56 | fh->navailable--; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 57 | |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 58 | kev->event.pending = fh->navailable; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 59 | *event = kev->event; |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 60 | kev->sev->first = sev_pos(kev->sev, 1); |
| 61 | kev->sev->in_use--; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 62 | |
| 63 | spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event, |
| 69 | int nonblocking) |
| 70 | { |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 71 | int ret; |
| 72 | |
| 73 | if (nonblocking) |
| 74 | return __v4l2_event_dequeue(fh, event); |
| 75 | |
Hans Verkuil | ee6869a | 2010-09-26 08:47:38 -0300 | [diff] [blame] | 76 | /* Release the vdev lock while waiting */ |
| 77 | if (fh->vdev->lock) |
| 78 | mutex_unlock(fh->vdev->lock); |
| 79 | |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 80 | do { |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 81 | ret = wait_event_interruptible(fh->wait, |
| 82 | fh->navailable != 0); |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 83 | if (ret < 0) |
Hans Verkuil | ee6869a | 2010-09-26 08:47:38 -0300 | [diff] [blame] | 84 | break; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 85 | |
| 86 | ret = __v4l2_event_dequeue(fh, event); |
| 87 | } while (ret == -ENOENT); |
| 88 | |
Hans Verkuil | ee6869a | 2010-09-26 08:47:38 -0300 | [diff] [blame] | 89 | if (fh->vdev->lock) |
| 90 | mutex_lock(fh->vdev->lock); |
| 91 | |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 92 | return ret; |
| 93 | } |
Laurent Pinchart | 0a4f8d0 | 2010-05-02 14:32:43 -0300 | [diff] [blame] | 94 | EXPORT_SYMBOL_GPL(v4l2_event_dequeue); |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 95 | |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 96 | /* Caller must hold fh->vdev->fh_lock! */ |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 97 | static struct v4l2_subscribed_event *v4l2_event_subscribed( |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 98 | struct v4l2_fh *fh, u32 type, u32 id) |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 99 | { |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 100 | struct v4l2_subscribed_event *sev; |
| 101 | |
Sakari Ailus | f3cd385 | 2010-05-03 12:42:46 -0300 | [diff] [blame] | 102 | assert_spin_locked(&fh->vdev->fh_lock); |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 103 | |
Hans Verkuil | 3f66f0e | 2011-06-20 11:56:24 -0300 | [diff] [blame] | 104 | list_for_each_entry(sev, &fh->subscribed, list) |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 105 | if (sev->type == type && sev->id == id) |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 106 | return sev; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 107 | |
| 108 | return NULL; |
| 109 | } |
| 110 | |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 111 | static void __v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev, |
| 112 | const struct timespec *ts) |
| 113 | { |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 114 | struct v4l2_subscribed_event *sev; |
| 115 | struct v4l2_kevent *kev; |
Hans Verkuil | 2151bdc | 2011-06-18 07:02:20 -0300 | [diff] [blame] | 116 | bool copy_payload = true; |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 117 | |
| 118 | /* Are we subscribed? */ |
| 119 | sev = v4l2_event_subscribed(fh, ev->type, ev->id); |
| 120 | if (sev == NULL) |
| 121 | return; |
| 122 | |
| 123 | /* Increase event sequence number on fh. */ |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 124 | fh->sequence++; |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 125 | |
| 126 | /* Do we have any free events? */ |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 127 | if (sev->in_use == sev->elems) { |
| 128 | /* no, remove the oldest one */ |
| 129 | kev = sev->events + sev_pos(sev, 0); |
| 130 | list_del(&kev->list); |
| 131 | sev->in_use--; |
| 132 | sev->first = sev_pos(sev, 1); |
| 133 | fh->navailable--; |
Hans Verkuil | 2151bdc | 2011-06-18 07:02:20 -0300 | [diff] [blame] | 134 | if (sev->elems == 1) { |
| 135 | if (sev->replace) { |
| 136 | sev->replace(&kev->event, ev); |
| 137 | copy_payload = false; |
| 138 | } |
| 139 | } else if (sev->merge) { |
| 140 | struct v4l2_kevent *second_oldest = |
| 141 | sev->events + sev_pos(sev, 0); |
| 142 | sev->merge(&kev->event, &second_oldest->event); |
| 143 | } |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 144 | } |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 145 | |
| 146 | /* Take one and fill it. */ |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 147 | kev = sev->events + sev_pos(sev, sev->in_use); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 148 | kev->event.type = ev->type; |
Hans Verkuil | 2151bdc | 2011-06-18 07:02:20 -0300 | [diff] [blame] | 149 | if (copy_payload) |
| 150 | kev->event.u = ev->u; |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 151 | kev->event.id = ev->id; |
| 152 | kev->event.timestamp = *ts; |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 153 | kev->event.sequence = fh->sequence; |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 154 | sev->in_use++; |
| 155 | list_add_tail(&kev->list, &fh->available); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 156 | |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 157 | fh->navailable++; |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 158 | |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 159 | wake_up_all(&fh->wait); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 160 | } |
| 161 | |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 162 | void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev) |
| 163 | { |
| 164 | struct v4l2_fh *fh; |
| 165 | unsigned long flags; |
| 166 | struct timespec timestamp; |
| 167 | |
| 168 | ktime_get_ts(×tamp); |
| 169 | |
| 170 | spin_lock_irqsave(&vdev->fh_lock, flags); |
| 171 | |
Hans Verkuil | 3f66f0e | 2011-06-20 11:56:24 -0300 | [diff] [blame] | 172 | list_for_each_entry(fh, &vdev->fh_list, list) |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 173 | __v4l2_event_queue_fh(fh, ev, ×tamp); |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 174 | |
| 175 | spin_unlock_irqrestore(&vdev->fh_lock, flags); |
| 176 | } |
| 177 | EXPORT_SYMBOL_GPL(v4l2_event_queue); |
| 178 | |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 179 | void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev) |
| 180 | { |
| 181 | unsigned long flags; |
| 182 | struct timespec timestamp; |
| 183 | |
| 184 | ktime_get_ts(×tamp); |
| 185 | |
| 186 | spin_lock_irqsave(&fh->vdev->fh_lock, flags); |
| 187 | __v4l2_event_queue_fh(fh, ev, ×tamp); |
| 188 | spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); |
| 189 | } |
| 190 | EXPORT_SYMBOL_GPL(v4l2_event_queue_fh); |
| 191 | |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 192 | int v4l2_event_pending(struct v4l2_fh *fh) |
| 193 | { |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 194 | return fh->navailable; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 195 | } |
| 196 | EXPORT_SYMBOL_GPL(v4l2_event_pending); |
| 197 | |
Hans Verkuil | 2151bdc | 2011-06-18 07:02:20 -0300 | [diff] [blame] | 198 | static void ctrls_replace(struct v4l2_event *old, const struct v4l2_event *new) |
| 199 | { |
| 200 | u32 old_changes = old->u.ctrl.changes; |
| 201 | |
| 202 | old->u.ctrl = new->u.ctrl; |
| 203 | old->u.ctrl.changes |= old_changes; |
| 204 | } |
| 205 | |
| 206 | static void ctrls_merge(const struct v4l2_event *old, struct v4l2_event *new) |
| 207 | { |
| 208 | new->u.ctrl.changes |= old->u.ctrl.changes; |
| 209 | } |
| 210 | |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 211 | int v4l2_event_subscribe(struct v4l2_fh *fh, |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 212 | struct v4l2_event_subscription *sub, unsigned elems) |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 213 | { |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 214 | struct v4l2_subscribed_event *sev, *found_ev; |
| 215 | struct v4l2_ctrl *ctrl = NULL; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 216 | unsigned long flags; |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 217 | unsigned i; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 218 | |
Hans de Goede | b36b505 | 2011-10-24 05:03:27 -0300 | [diff] [blame] | 219 | if (sub->type == V4L2_EVENT_ALL) |
| 220 | return -EINVAL; |
| 221 | |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 222 | if (elems < 1) |
| 223 | elems = 1; |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 224 | if (sub->type == V4L2_EVENT_CTRL) { |
| 225 | ctrl = v4l2_ctrl_find(fh->ctrl_handler, sub->id); |
| 226 | if (ctrl == NULL) |
| 227 | return -EINVAL; |
| 228 | } |
| 229 | |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 230 | sev = kzalloc(sizeof(*sev) + sizeof(struct v4l2_kevent) * elems, GFP_KERNEL); |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 231 | if (!sev) |
| 232 | return -ENOMEM; |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 233 | for (i = 0; i < elems; i++) |
| 234 | sev->events[i].sev = sev; |
| 235 | sev->type = sub->type; |
| 236 | sev->id = sub->id; |
| 237 | sev->flags = sub->flags; |
| 238 | sev->fh = fh; |
| 239 | sev->elems = elems; |
Hans Verkuil | 2151bdc | 2011-06-18 07:02:20 -0300 | [diff] [blame] | 240 | if (ctrl) { |
| 241 | sev->replace = ctrls_replace; |
| 242 | sev->merge = ctrls_merge; |
| 243 | } |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 244 | |
| 245 | spin_lock_irqsave(&fh->vdev->fh_lock, flags); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 246 | found_ev = v4l2_event_subscribed(fh, sub->type, sub->id); |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 247 | if (!found_ev) |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 248 | list_add(&sev->list, &fh->subscribed); |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 249 | spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); |
| 250 | |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 251 | /* v4l2_ctrl_add_event uses a mutex, so do this outside the spin lock */ |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 252 | if (found_ev) |
| 253 | kfree(sev); |
| 254 | else if (ctrl) |
| 255 | v4l2_ctrl_add_event(ctrl, sev); |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | EXPORT_SYMBOL_GPL(v4l2_event_subscribe); |
| 260 | |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 261 | void v4l2_event_unsubscribe_all(struct v4l2_fh *fh) |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 262 | { |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 263 | struct v4l2_event_subscription sub; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 264 | struct v4l2_subscribed_event *sev; |
| 265 | unsigned long flags; |
| 266 | |
| 267 | do { |
| 268 | sev = NULL; |
| 269 | |
| 270 | spin_lock_irqsave(&fh->vdev->fh_lock, flags); |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 271 | if (!list_empty(&fh->subscribed)) { |
| 272 | sev = list_first_entry(&fh->subscribed, |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 273 | struct v4l2_subscribed_event, list); |
| 274 | sub.type = sev->type; |
| 275 | sub.id = sev->id; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 276 | } |
| 277 | spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 278 | if (sev) |
| 279 | v4l2_event_unsubscribe(fh, &sub); |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 280 | } while (sev); |
| 281 | } |
Hans Verkuil | f1e393d | 2011-06-13 19:24:17 -0300 | [diff] [blame] | 282 | EXPORT_SYMBOL_GPL(v4l2_event_unsubscribe_all); |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 283 | |
| 284 | int v4l2_event_unsubscribe(struct v4l2_fh *fh, |
| 285 | struct v4l2_event_subscription *sub) |
| 286 | { |
| 287 | struct v4l2_subscribed_event *sev; |
| 288 | unsigned long flags; |
Hans de Goede | 78c87e8 | 2011-10-26 05:40:27 -0300 | [diff] [blame] | 289 | int i; |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 290 | |
| 291 | if (sub->type == V4L2_EVENT_ALL) { |
| 292 | v4l2_event_unsubscribe_all(fh); |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | spin_lock_irqsave(&fh->vdev->fh_lock, flags); |
| 297 | |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 298 | sev = v4l2_event_subscribed(fh, sub->type, sub->id); |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 299 | if (sev != NULL) { |
Hans de Goede | 78c87e8 | 2011-10-26 05:40:27 -0300 | [diff] [blame] | 300 | /* Remove any pending events for this subscription */ |
| 301 | for (i = 0; i < sev->in_use; i++) { |
| 302 | list_del(&sev->events[sev_pos(sev, i)].list); |
| 303 | fh->navailable--; |
| 304 | } |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 305 | list_del(&sev->list); |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 306 | } |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 307 | |
| 308 | spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 309 | if (sev && sev->type == V4L2_EVENT_CTRL) { |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 310 | struct v4l2_ctrl *ctrl = v4l2_ctrl_find(fh->ctrl_handler, sev->id); |
| 311 | |
| 312 | if (ctrl) |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 313 | v4l2_ctrl_del_event(ctrl, sev); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 314 | } |
Sakari Ailus | c3b5b02 | 2010-03-01 05:14:18 -0300 | [diff] [blame] | 315 | |
| 316 | kfree(sev); |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | EXPORT_SYMBOL_GPL(v4l2_event_unsubscribe); |