ASoC: bd28623: Remove now redundant non_legacy_dai_naming flag
[linux-2.6-microblaze.git] / fs / pipe.c
index e140ea1..74ae9fa 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -653,7 +653,7 @@ pipe_poll(struct file *filp, poll_table *wait)
        unsigned int head, tail;
 
        /* Epoll has some historical nasty semantics, this enables them */
-       pipe->poll_usage = 1;
+       WRITE_ONCE(pipe->poll_usage, true);
 
        /*
         * Reading pipe state only -- no need for acquiring the semaphore.
@@ -1245,30 +1245,33 @@ unsigned int round_pipe_size(unsigned long size)
 
 /*
  * Resize the pipe ring to a number of slots.
+ *
+ * Note the pipe can be reduced in capacity, but only if the current
+ * occupancy doesn't exceed nr_slots; if it does, EBUSY will be
+ * returned instead.
  */
 int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots)
 {
        struct pipe_buffer *bufs;
        unsigned int head, tail, mask, n;
 
-       /*
-        * We can shrink the pipe, if arg is greater than the ring occupancy.
-        * Since we don't expect a lot of shrink+grow operations, just free and
-        * allocate again like we would do for growing.  If the pipe currently
-        * contains more buffers than arg, then return busy.
-        */
-       mask = pipe->ring_size - 1;
-       head = pipe->head;
-       tail = pipe->tail;
-       n = pipe_occupancy(pipe->head, pipe->tail);
-       if (nr_slots < n)
-               return -EBUSY;
-
        bufs = kcalloc(nr_slots, sizeof(*bufs),
                       GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
        if (unlikely(!bufs))
                return -ENOMEM;
 
+       spin_lock_irq(&pipe->rd_wait.lock);
+       mask = pipe->ring_size - 1;
+       head = pipe->head;
+       tail = pipe->tail;
+
+       n = pipe_occupancy(head, tail);
+       if (nr_slots < n) {
+               spin_unlock_irq(&pipe->rd_wait.lock);
+               kfree(bufs);
+               return -EBUSY;
+       }
+
        /*
         * The pipe array wraps around, so just start the new one at zero
         * and adjust the indices.
@@ -1300,6 +1303,8 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots)
        pipe->tail = tail;
        pipe->head = head;
 
+       spin_unlock_irq(&pipe->rd_wait.lock);
+
        /* This might have made more room for writers */
        wake_up_interruptible(&pipe->wr_wait);
        return 0;