aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/iio
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2011-12-19 09:23:49 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2011-12-22 16:38:10 -0500
commit7933514043d42e69663a5123a53fab50eb0b4aba (patch)
tree1563ca434350c338176f0c9e6cc4648882ad74d0 /drivers/staging/iio
parent869871b58c7f7c26ccf7a89cbe599e9b963b8e69 (diff)
staging:iio: Drop {mark,unmark}_in_use callbacks
These callbacks are currently used by the individual buffer implementations to ensure that the request_update callback is not issued while the buffer is in use. But the core already provides sufficient measures to prevent this from happening in the first place. So it is safe to remove them. There is one functional change due to this patch. Since the buffer is no longer marked as in use when the chrdev is opened, it is now possible to enable the buffer while it is opened. This did not work before, because mark_param_change did fail if the buffer was marked as in use. Acked-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/iio')
-rw-r--r--drivers/staging/iio/Documentation/ring.txt4
-rw-r--r--drivers/staging/iio/buffer.h5
-rw-r--r--drivers/staging/iio/iio_core.h11
-rw-r--r--drivers/staging/iio/industrialio-buffer.c28
-rw-r--r--drivers/staging/iio/industrialio-core.c8
-rw-r--r--drivers/staging/iio/kfifo_buf.c32
-rw-r--r--drivers/staging/iio/ring_sw.c35
7 files changed, 1 insertions, 122 deletions
diff --git a/drivers/staging/iio/Documentation/ring.txt b/drivers/staging/iio/Documentation/ring.txt
index 0f21479ef4e..e33807761cd 100644
--- a/drivers/staging/iio/Documentation/ring.txt
+++ b/drivers/staging/iio/Documentation/ring.txt
@@ -23,10 +23,6 @@ The function pointers within here are used to allow the core to handle
23as much buffer functionality as possible. Note almost all of these 23as much buffer functionality as possible. Note almost all of these
24are optional. 24are optional.
25 25
26mark_in_use, unmark_in_use
27 Basically indicate that not changes should be made to the buffer state that
28 will effect the form of the data being captures (e.g. scan elements or length)
29
30store_to 26store_to
31 If possible, push data to the buffer. 27 If possible, push data to the buffer.
32 28
diff --git a/drivers/staging/iio/buffer.h b/drivers/staging/iio/buffer.h
index ea42b5d27e3..6fb6e64181a 100644
--- a/drivers/staging/iio/buffer.h
+++ b/drivers/staging/iio/buffer.h
@@ -18,8 +18,6 @@ struct iio_buffer;
18 18
19/** 19/**
20 * struct iio_buffer_access_funcs - access functions for buffers. 20 * struct iio_buffer_access_funcs - access functions for buffers.
21 * @mark_in_use: reference counting, typically to prevent module removal
22 * @unmark_in_use: reduce reference count when no longer using buffer
23 * @store_to: actually store stuff to the buffer 21 * @store_to: actually store stuff to the buffer
24 * @read_first_n: try to get a specified number of bytes (must exist) 22 * @read_first_n: try to get a specified number of bytes (must exist)
25 * @request_update: if a parameter change has been marked, update underlying 23 * @request_update: if a parameter change has been marked, update underlying
@@ -38,9 +36,6 @@ struct iio_buffer;
38 * any of them not existing. 36 * any of them not existing.
39 **/ 37 **/
40struct iio_buffer_access_funcs { 38struct iio_buffer_access_funcs {
41 void (*mark_in_use)(struct iio_buffer *buffer);
42 void (*unmark_in_use)(struct iio_buffer *buffer);
43
44 int (*store_to)(struct iio_buffer *buffer, u8 *data, s64 timestamp); 39 int (*store_to)(struct iio_buffer *buffer, u8 *data, s64 timestamp);
45 int (*read_first_n)(struct iio_buffer *buffer, 40 int (*read_first_n)(struct iio_buffer *buffer,
46 size_t n, 41 size_t n,
diff --git a/drivers/staging/iio/iio_core.h b/drivers/staging/iio/iio_core.h
index ff27f1360d9..107cfb1cbb0 100644
--- a/drivers/staging/iio/iio_core.h
+++ b/drivers/staging/iio/iio_core.h
@@ -33,9 +33,6 @@ int __iio_add_chan_devattr(const char *postfix,
33#ifdef CONFIG_IIO_BUFFER 33#ifdef CONFIG_IIO_BUFFER
34struct poll_table_struct; 34struct poll_table_struct;
35 35
36int iio_chrdev_buffer_open(struct iio_dev *indio_dev);
37void iio_chrdev_buffer_release(struct iio_dev *indio_dev);
38
39unsigned int iio_buffer_poll(struct file *filp, 36unsigned int iio_buffer_poll(struct file *filp,
40 struct poll_table_struct *wait); 37 struct poll_table_struct *wait);
41ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf, 38ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
@@ -47,14 +44,6 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
47 44
48#else 45#else
49 46
50static inline int iio_chrdev_buffer_open(struct iio_dev *indio_dev)
51{
52 return 0;
53}
54
55static inline void iio_chrdev_buffer_release(struct iio_dev *indio_dev)
56{}
57
58#define iio_buffer_poll_addr NULL 47#define iio_buffer_poll_addr NULL
59#define iio_buffer_read_first_n_outer_addr NULL 48#define iio_buffer_read_first_n_outer_addr NULL
60 49
diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index d2858ff8aa0..d7b1e9e435a 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -64,26 +64,6 @@ unsigned int iio_buffer_poll(struct file *filp,
64 return 0; 64 return 0;
65} 65}
66 66
67int iio_chrdev_buffer_open(struct iio_dev *indio_dev)
68{
69 struct iio_buffer *rb = indio_dev->buffer;
70 if (!rb)
71 return 0;
72 if (rb->access->mark_in_use)
73 rb->access->mark_in_use(rb);
74 return 0;
75}
76
77void iio_chrdev_buffer_release(struct iio_dev *indio_dev)
78{
79 struct iio_buffer *rb = indio_dev->buffer;
80
81 if (!rb)
82 return;
83 if (rb->access->unmark_in_use)
84 rb->access->unmark_in_use(rb);
85}
86
87void iio_buffer_init(struct iio_buffer *buffer) 67void iio_buffer_init(struct iio_buffer *buffer)
88{ 68{
89 INIT_LIST_HEAD(&buffer->demux_list); 69 INIT_LIST_HEAD(&buffer->demux_list);
@@ -447,16 +427,12 @@ ssize_t iio_buffer_store_enable(struct device *dev,
447 goto error_ret; 427 goto error_ret;
448 } 428 }
449 } 429 }
450 if (buffer->access->mark_in_use)
451 buffer->access->mark_in_use(buffer);
452 /* Definitely possible for devices to support both of these.*/ 430 /* Definitely possible for devices to support both of these.*/
453 if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) { 431 if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) {
454 if (!indio_dev->trig) { 432 if (!indio_dev->trig) {
455 printk(KERN_INFO 433 printk(KERN_INFO
456 "Buffer not started: no trigger\n"); 434 "Buffer not started: no trigger\n");
457 ret = -EINVAL; 435 ret = -EINVAL;
458 if (buffer->access->unmark_in_use)
459 buffer->access->unmark_in_use(buffer);
460 goto error_ret; 436 goto error_ret;
461 } 437 }
462 indio_dev->currentmode = INDIO_BUFFER_TRIGGERED; 438 indio_dev->currentmode = INDIO_BUFFER_TRIGGERED;
@@ -473,8 +449,6 @@ ssize_t iio_buffer_store_enable(struct device *dev,
473 printk(KERN_INFO 449 printk(KERN_INFO
474 "Buffer not started:" 450 "Buffer not started:"
475 "postenable failed\n"); 451 "postenable failed\n");
476 if (buffer->access->unmark_in_use)
477 buffer->access->unmark_in_use(buffer);
478 indio_dev->currentmode = previous_mode; 452 indio_dev->currentmode = previous_mode;
479 if (indio_dev->setup_ops->postdisable) 453 if (indio_dev->setup_ops->postdisable)
480 indio_dev->setup_ops-> 454 indio_dev->setup_ops->
@@ -488,8 +462,6 @@ ssize_t iio_buffer_store_enable(struct device *dev,
488 if (ret) 462 if (ret)
489 goto error_ret; 463 goto error_ret;
490 } 464 }
491 if (buffer->access->unmark_in_use)
492 buffer->access->unmark_in_use(buffer);
493 indio_dev->currentmode = INDIO_DIRECT_MODE; 465 indio_dev->currentmode = INDIO_DIRECT_MODE;
494 if (indio_dev->setup_ops->postdisable) { 466 if (indio_dev->setup_ops->postdisable) {
495 ret = indio_dev->setup_ops->postdisable(indio_dev); 467 ret = indio_dev->setup_ops->postdisable(indio_dev);
diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/staging/iio/industrialio-core.c
index 12d1576a076..19f897f3c85 100644
--- a/drivers/staging/iio/industrialio-core.c
+++ b/drivers/staging/iio/industrialio-core.c
@@ -1083,18 +1083,13 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
1083{ 1083{
1084 struct iio_dev *indio_dev = container_of(inode->i_cdev, 1084 struct iio_dev *indio_dev = container_of(inode->i_cdev,
1085 struct iio_dev, chrdev); 1085 struct iio_dev, chrdev);
1086 unsigned int ret;
1087 1086
1088 if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags)) 1087 if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags))
1089 return -EBUSY; 1088 return -EBUSY;
1090 1089
1091 filp->private_data = indio_dev; 1090 filp->private_data = indio_dev;
1092 1091
1093 ret = iio_chrdev_buffer_open(indio_dev); 1092 return 0;
1094 if (ret < 0)
1095 clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
1096
1097 return ret;
1098} 1093}
1099 1094
1100/** 1095/**
@@ -1104,7 +1099,6 @@ static int iio_chrdev_release(struct inode *inode, struct file *filp)
1104{ 1099{
1105 struct iio_dev *indio_dev = container_of(inode->i_cdev, 1100 struct iio_dev *indio_dev = container_of(inode->i_cdev,
1106 struct iio_dev, chrdev); 1101 struct iio_dev, chrdev);
1107 iio_chrdev_buffer_release(indio_dev);
1108 clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags); 1102 clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
1109 return 0; 1103 return 0;
1110} 1104}
diff --git a/drivers/staging/iio/kfifo_buf.c b/drivers/staging/iio/kfifo_buf.c
index bae4caf4fce..e1e9c06cde4 100644
--- a/drivers/staging/iio/kfifo_buf.c
+++ b/drivers/staging/iio/kfifo_buf.c
@@ -11,9 +11,7 @@
11struct iio_kfifo { 11struct iio_kfifo {
12 struct iio_buffer buffer; 12 struct iio_buffer buffer;
13 struct kfifo kf; 13 struct kfifo kf;
14 int use_count;
15 int update_needed; 14 int update_needed;
16 struct mutex use_lock;
17}; 15};
18 16
19#define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer) 17#define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer)
@@ -33,47 +31,20 @@ static int iio_request_update_kfifo(struct iio_buffer *r)
33 int ret = 0; 31 int ret = 0;
34 struct iio_kfifo *buf = iio_to_kfifo(r); 32 struct iio_kfifo *buf = iio_to_kfifo(r);
35 33
36 mutex_lock(&buf->use_lock);
37 if (!buf->update_needed) 34 if (!buf->update_needed)
38 goto error_ret; 35 goto error_ret;
39 if (buf->use_count) {
40 ret = -EAGAIN;
41 goto error_ret;
42 }
43 kfifo_free(&buf->kf); 36 kfifo_free(&buf->kf);
44 ret = __iio_allocate_kfifo(buf, buf->buffer.bytes_per_datum, 37 ret = __iio_allocate_kfifo(buf, buf->buffer.bytes_per_datum,
45 buf->buffer.length); 38 buf->buffer.length);
46error_ret: 39error_ret:
47 mutex_unlock(&buf->use_lock);
48 return ret; 40 return ret;
49} 41}
50 42
51static void iio_mark_kfifo_in_use(struct iio_buffer *r)
52{
53 struct iio_kfifo *buf = iio_to_kfifo(r);
54 mutex_lock(&buf->use_lock);
55 buf->use_count++;
56 mutex_unlock(&buf->use_lock);
57}
58
59static void iio_unmark_kfifo_in_use(struct iio_buffer *r)
60{
61 struct iio_kfifo *buf = iio_to_kfifo(r);
62 mutex_lock(&buf->use_lock);
63 buf->use_count--;
64 mutex_unlock(&buf->use_lock);
65}
66
67static int iio_get_length_kfifo(struct iio_buffer *r) 43static int iio_get_length_kfifo(struct iio_buffer *r)
68{ 44{
69 return r->length; 45 return r->length;
70} 46}
71 47
72static inline void __iio_init_kfifo(struct iio_kfifo *kf)
73{
74 mutex_init(&kf->use_lock);
75}
76
77static IIO_BUFFER_ENABLE_ATTR; 48static IIO_BUFFER_ENABLE_ATTR;
78static IIO_BUFFER_LENGTH_ATTR; 49static IIO_BUFFER_LENGTH_ATTR;
79 50
@@ -98,7 +69,6 @@ struct iio_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev)
98 kf->update_needed = true; 69 kf->update_needed = true;
99 iio_buffer_init(&kf->buffer); 70 iio_buffer_init(&kf->buffer);
100 kf->buffer.attrs = &iio_kfifo_attribute_group; 71 kf->buffer.attrs = &iio_kfifo_attribute_group;
101 __iio_init_kfifo(kf);
102 72
103 return &kf->buffer; 73 return &kf->buffer;
104} 74}
@@ -168,8 +138,6 @@ static int iio_read_first_n_kfifo(struct iio_buffer *r,
168} 138}
169 139
170const struct iio_buffer_access_funcs kfifo_access_funcs = { 140const struct iio_buffer_access_funcs kfifo_access_funcs = {
171 .mark_in_use = &iio_mark_kfifo_in_use,
172 .unmark_in_use = &iio_unmark_kfifo_in_use,
173 .store_to = &iio_store_to_kfifo, 141 .store_to = &iio_store_to_kfifo,
174 .read_first_n = &iio_read_first_n_kfifo, 142 .read_first_n = &iio_read_first_n_kfifo,
175 .request_update = &iio_request_update_kfifo, 143 .request_update = &iio_request_update_kfifo,
diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
index c239fd3af4a..3e24ec45585 100644
--- a/drivers/staging/iio/ring_sw.c
+++ b/drivers/staging/iio/ring_sw.c
@@ -24,9 +24,7 @@
24 * @read_p: read pointer (oldest available) 24 * @read_p: read pointer (oldest available)
25 * @write_p: write pointer 25 * @write_p: write pointer
26 * @half_p: half buffer length behind write_p (event generation) 26 * @half_p: half buffer length behind write_p (event generation)
27 * @use_count: reference count to prevent resizing when in use
28 * @update_needed: flag to indicated change in size requested 27 * @update_needed: flag to indicated change in size requested
29 * @use_lock: lock to prevent change in size when in use
30 * 28 *
31 * Note that the first element of all ring buffers must be a 29 * Note that the first element of all ring buffers must be a
32 * struct iio_buffer. 30 * struct iio_buffer.
@@ -38,9 +36,7 @@ struct iio_sw_ring_buffer {
38 unsigned char *write_p; 36 unsigned char *write_p;
39 /* used to act as a point at which to signal an event */ 37 /* used to act as a point at which to signal an event */
40 unsigned char *half_p; 38 unsigned char *half_p;
41 int use_count;
42 int update_needed; 39 int update_needed;
43 spinlock_t use_lock;
44}; 40};
45 41
46#define iio_to_sw_ring(r) container_of(r, struct iio_sw_ring_buffer, buf) 42#define iio_to_sw_ring(r) container_of(r, struct iio_sw_ring_buffer, buf)
@@ -58,33 +54,11 @@ static inline int __iio_allocate_sw_ring_buffer(struct iio_sw_ring_buffer *ring,
58 return ring->data ? 0 : -ENOMEM; 54 return ring->data ? 0 : -ENOMEM;
59} 55}
60 56
61static inline void __iio_init_sw_ring_buffer(struct iio_sw_ring_buffer *ring)
62{
63 spin_lock_init(&ring->use_lock);
64}
65
66static inline void __iio_free_sw_ring_buffer(struct iio_sw_ring_buffer *ring) 57static inline void __iio_free_sw_ring_buffer(struct iio_sw_ring_buffer *ring)
67{ 58{
68 kfree(ring->data); 59 kfree(ring->data);
69} 60}
70 61
71static void iio_mark_sw_rb_in_use(struct iio_buffer *r)
72{
73 struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r);
74 spin_lock(&ring->use_lock);
75 ring->use_count++;
76 spin_unlock(&ring->use_lock);
77}
78
79static void iio_unmark_sw_rb_in_use(struct iio_buffer *r)
80{
81 struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r);
82 spin_lock(&ring->use_lock);
83 ring->use_count--;
84 spin_unlock(&ring->use_lock);
85}
86
87
88/* Ring buffer related functionality */ 62/* Ring buffer related functionality */
89/* Store to ring is typically called in the bh of a data ready interrupt handler 63/* Store to ring is typically called in the bh of a data ready interrupt handler
90 * in the device driver */ 64 * in the device driver */
@@ -295,18 +269,12 @@ static int iio_request_update_sw_rb(struct iio_buffer *r)
295 struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r); 269 struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r);
296 270
297 r->stufftoread = false; 271 r->stufftoread = false;
298 spin_lock(&ring->use_lock);
299 if (!ring->update_needed) 272 if (!ring->update_needed)
300 goto error_ret; 273 goto error_ret;
301 if (ring->use_count) {
302 ret = -EAGAIN;
303 goto error_ret;
304 }
305 __iio_free_sw_ring_buffer(ring); 274 __iio_free_sw_ring_buffer(ring);
306 ret = __iio_allocate_sw_ring_buffer(ring, ring->buf.bytes_per_datum, 275 ret = __iio_allocate_sw_ring_buffer(ring, ring->buf.bytes_per_datum,
307 ring->buf.length); 276 ring->buf.length);
308error_ret: 277error_ret:
309 spin_unlock(&ring->use_lock);
310 return ret; 278 return ret;
311} 279}
312 280
@@ -372,7 +340,6 @@ struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev)
372 ring->update_needed = true; 340 ring->update_needed = true;
373 buf = &ring->buf; 341 buf = &ring->buf;
374 iio_buffer_init(buf); 342 iio_buffer_init(buf);
375 __iio_init_sw_ring_buffer(ring);
376 buf->attrs = &iio_ring_attribute_group; 343 buf->attrs = &iio_ring_attribute_group;
377 344
378 return buf; 345 return buf;
@@ -386,8 +353,6 @@ void iio_sw_rb_free(struct iio_buffer *r)
386EXPORT_SYMBOL(iio_sw_rb_free); 353EXPORT_SYMBOL(iio_sw_rb_free);
387 354
388const struct iio_buffer_access_funcs ring_sw_access_funcs = { 355const struct iio_buffer_access_funcs ring_sw_access_funcs = {
389 .mark_in_use = &iio_mark_sw_rb_in_use,
390 .unmark_in_use = &iio_unmark_sw_rb_in_use,
391 .store_to = &iio_store_to_sw_rb, 356 .store_to = &iio_store_to_sw_rb,
392 .read_first_n = &iio_read_first_n_sw_rb, 357 .read_first_n = &iio_read_first_n_sw_rb,
393 .request_update = &iio_request_update_sw_rb, 358 .request_update = &iio_request_update_sw_rb,