ALSA: hda: Initialize power_state field properly
[platform/kernel/linux-rpi.git] / fs / eventpoll.c
index 2737ef5..58f48ea 100644 (file)
@@ -336,9 +336,9 @@ static inline int ep_cmp_ffd(struct epoll_filefd *p1,
 }
 
 /* Tells us if the item is currently linked */
-static inline int ep_is_linked(struct list_head *p)
+static inline int ep_is_linked(struct epitem *epi)
 {
-       return !list_empty(p);
+       return !list_empty(&epi->rdllink);
 }
 
 static inline struct eppoll_entry *ep_pwq_from_wait(wait_queue_entry_t *p)
@@ -391,7 +391,6 @@ static bool ep_busy_loop_end(void *p, unsigned long start_time)
 
        return ep_events_available(ep) || busy_loop_timeout(start_time);
 }
-#endif /* CONFIG_NET_RX_BUSY_POLL */
 
 /*
  * Busy poll if globally on and supporting sockets found && no events,
@@ -401,20 +400,16 @@ static bool ep_busy_loop_end(void *p, unsigned long start_time)
  */
 static void ep_busy_loop(struct eventpoll *ep, int nonblock)
 {
-#ifdef CONFIG_NET_RX_BUSY_POLL
        unsigned int napi_id = READ_ONCE(ep->napi_id);
 
        if ((napi_id >= MIN_NAPI_ID) && net_busy_loop_on())
                napi_busy_loop(napi_id, nonblock ? NULL : ep_busy_loop_end, ep);
-#endif
 }
 
 static inline void ep_reset_busy_poll_napi_id(struct eventpoll *ep)
 {
-#ifdef CONFIG_NET_RX_BUSY_POLL
        if (ep->napi_id)
                ep->napi_id = 0;
-#endif
 }
 
 /*
@@ -422,7 +417,6 @@ static inline void ep_reset_busy_poll_napi_id(struct eventpoll *ep)
  */
 static inline void ep_set_busy_poll_napi_id(struct epitem *epi)
 {
-#ifdef CONFIG_NET_RX_BUSY_POLL
        struct eventpoll *ep;
        unsigned int napi_id;
        struct socket *sock;
@@ -452,9 +446,24 @@ static inline void ep_set_busy_poll_napi_id(struct epitem *epi)
 
        /* record NAPI ID for use in next busy poll */
        ep->napi_id = napi_id;
-#endif
 }
 
+#else
+
+static inline void ep_busy_loop(struct eventpoll *ep, int nonblock)
+{
+}
+
+static inline void ep_reset_busy_poll_napi_id(struct eventpoll *ep)
+{
+}
+
+static inline void ep_set_busy_poll_napi_id(struct epitem *epi)
+{
+}
+
+#endif /* CONFIG_NET_RX_BUSY_POLL */
+
 /**
  * ep_call_nested - Perform a bound (possibly) nested call, by checking
  *                  that the recursion limit is not exceeded, and that
@@ -667,10 +676,11 @@ static __poll_t ep_scan_ready_list(struct eventpoll *ep,
 {
        __poll_t res;
        int pwake = 0;
-       unsigned long flags;
        struct epitem *epi, *nepi;
        LIST_HEAD(txlist);
 
+       lockdep_assert_irqs_enabled();
+
        /*
         * We need to lock this because we could be hit by
         * eventpoll_release_file() and epoll_ctl().
@@ -687,17 +697,17 @@ static __poll_t ep_scan_ready_list(struct eventpoll *ep,
         * because we want the "sproc" callback to be able to do it
         * in a lockless way.
         */
-       spin_lock_irqsave(&ep->wq.lock, flags);
+       spin_lock_irq(&ep->wq.lock);
        list_splice_init(&ep->rdllist, &txlist);
        ep->ovflist = NULL;
-       spin_unlock_irqrestore(&ep->wq.lock, flags);
+       spin_unlock_irq(&ep->wq.lock);
 
        /*
         * Now call the callback function.
         */
        res = (*sproc)(ep, &txlist, priv);
 
-       spin_lock_irqsave(&ep->wq.lock, flags);
+       spin_lock_irq(&ep->wq.lock);
        /*
         * During the time we spent inside the "sproc" callback, some
         * other events might have been queued by the poll callback.
@@ -711,7 +721,7 @@ static __poll_t ep_scan_ready_list(struct eventpoll *ep,
                 * queued into ->ovflist but the "txlist" might already
                 * contain them, and the list_splice() below takes care of them.
                 */
-               if (!ep_is_linked(&epi->rdllink)) {
+               if (!ep_is_linked(epi)) {
                        list_add_tail(&epi->rdllink, &ep->rdllist);
                        ep_pm_stay_awake(epi);
                }
@@ -739,7 +749,7 @@ static __poll_t ep_scan_ready_list(struct eventpoll *ep,
                if (waitqueue_active(&ep->poll_wait))
                        pwake++;
        }
-       spin_unlock_irqrestore(&ep->wq.lock, flags);
+       spin_unlock_irq(&ep->wq.lock);
 
        if (!ep_locked)
                mutex_unlock(&ep->mtx);
@@ -763,9 +773,10 @@ static void epi_rcu_free(struct rcu_head *head)
  */
 static int ep_remove(struct eventpoll *ep, struct epitem *epi)
 {
-       unsigned long flags;
        struct file *file = epi->ffd.file;
 
+       lockdep_assert_irqs_enabled();
+
        /*
         * Removes poll wait queue hooks.
         */
@@ -778,10 +789,10 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi)
 
        rb_erase_cached(&epi->rbn, &ep->rbr);
 
-       spin_lock_irqsave(&ep->wq.lock, flags);
-       if (ep_is_linked(&epi->rdllink))
+       spin_lock_irq(&ep->wq.lock);
+       if (ep_is_linked(epi))
                list_del_init(&epi->rdllink);
-       spin_unlock_irqrestore(&ep->wq.lock, flags);
+       spin_unlock_irq(&ep->wq.lock);
 
        wakeup_source_unregister(ep_wakeup_source(epi));
        /*
@@ -1143,7 +1154,7 @@ static int ep_poll_callback(wait_queue_entry_t *wait, unsigned mode, int sync, v
         * semantics). All the events that happen during that period of time are
         * chained in ep->ovflist and requeued later on.
         */
-       if (unlikely(ep->ovflist != EP_UNACTIVE_PTR)) {
+       if (ep->ovflist != EP_UNACTIVE_PTR) {
                if (epi->next == EP_UNACTIVE_PTR) {
                        epi->next = ep->ovflist;
                        ep->ovflist = epi;
@@ -1160,7 +1171,7 @@ static int ep_poll_callback(wait_queue_entry_t *wait, unsigned mode, int sync, v
        }
 
        /* If this file is already in the ready list we exit soon */
-       if (!ep_is_linked(&epi->rdllink)) {
+       if (!ep_is_linked(epi)) {
                list_add_tail(&epi->rdllink, &ep->rdllist);
                ep_pm_stay_awake_rcu(epi);
        }
@@ -1410,11 +1421,12 @@ static int ep_insert(struct eventpoll *ep, const struct epoll_event *event,
 {
        int error, pwake = 0;
        __poll_t revents;
-       unsigned long flags;
        long user_watches;
        struct epitem *epi;
        struct ep_pqueue epq;
 
+       lockdep_assert_irqs_enabled();
+
        user_watches = atomic_long_read(&ep->user->epoll_watches);
        if (unlikely(user_watches >= max_user_watches))
                return -ENOSPC;
@@ -1477,13 +1489,13 @@ static int ep_insert(struct eventpoll *ep, const struct epoll_event *event,
                goto error_remove_epi;
 
        /* We have to drop the new item inside our item list to keep track of it */
-       spin_lock_irqsave(&ep->wq.lock, flags);
+       spin_lock_irq(&ep->wq.lock);
 
        /* record NAPI ID of new item if present */
        ep_set_busy_poll_napi_id(epi);
 
        /* If the file is already "ready" we drop it inside the ready list */
-       if (revents && !ep_is_linked(&epi->rdllink)) {
+       if (revents && !ep_is_linked(epi)) {
                list_add_tail(&epi->rdllink, &ep->rdllist);
                ep_pm_stay_awake(epi);
 
@@ -1494,7 +1506,7 @@ static int ep_insert(struct eventpoll *ep, const struct epoll_event *event,
                        pwake++;
        }
 
-       spin_unlock_irqrestore(&ep->wq.lock, flags);
+       spin_unlock_irq(&ep->wq.lock);
 
        atomic_long_inc(&ep->user->epoll_watches);
 
@@ -1520,10 +1532,10 @@ error_unregister:
         * list, since that is used/cleaned only inside a section bound by "mtx".
         * And ep_insert() is called with "mtx" held.
         */
-       spin_lock_irqsave(&ep->wq.lock, flags);
-       if (ep_is_linked(&epi->rdllink))
+       spin_lock_irq(&ep->wq.lock);
+       if (ep_is_linked(epi))
                list_del_init(&epi->rdllink);
-       spin_unlock_irqrestore(&ep->wq.lock, flags);
+       spin_unlock_irq(&ep->wq.lock);
 
        wakeup_source_unregister(ep_wakeup_source(epi));
 
@@ -1543,6 +1555,8 @@ static int ep_modify(struct eventpoll *ep, struct epitem *epi,
        int pwake = 0;
        poll_table pt;
 
+       lockdep_assert_irqs_enabled();
+
        init_poll_funcptr(&pt, NULL);
 
        /*
@@ -1587,7 +1601,7 @@ static int ep_modify(struct eventpoll *ep, struct epitem *epi,
         */
        if (ep_item_poll(epi, &pt, 1)) {
                spin_lock_irq(&ep->wq.lock);
-               if (!ep_is_linked(&epi->rdllink)) {
+               if (!ep_is_linked(epi)) {
                        list_add_tail(&epi->rdllink, &ep->rdllist);
                        ep_pm_stay_awake(epi);
 
@@ -1732,11 +1746,12 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
                   int maxevents, long timeout)
 {
        int res = 0, eavail, timed_out = 0;
-       unsigned long flags;
        u64 slack = 0;
        wait_queue_entry_t wait;
        ktime_t expires, *to = NULL;
 
+       lockdep_assert_irqs_enabled();
+
        if (timeout > 0) {
                struct timespec64 end_time = ep_set_mstimeout(timeout);
 
@@ -1749,7 +1764,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
                 * caller specified a non blocking operation.
                 */
                timed_out = 1;
-               spin_lock_irqsave(&ep->wq.lock, flags);
+               spin_lock_irq(&ep->wq.lock);
                goto check_events;
        }
 
@@ -1758,7 +1773,7 @@ fetch_events:
        if (!ep_events_available(ep))
                ep_busy_loop(ep, timed_out);
 
-       spin_lock_irqsave(&ep->wq.lock, flags);
+       spin_lock_irq(&ep->wq.lock);
 
        if (!ep_events_available(ep)) {
                /*
@@ -1800,11 +1815,11 @@ fetch_events:
                                break;
                        }
 
-                       spin_unlock_irqrestore(&ep->wq.lock, flags);
+                       spin_unlock_irq(&ep->wq.lock);
                        if (!schedule_hrtimeout_range(to, slack, HRTIMER_MODE_ABS))
                                timed_out = 1;
 
-                       spin_lock_irqsave(&ep->wq.lock, flags);
+                       spin_lock_irq(&ep->wq.lock);
                }
 
                __remove_wait_queue(&ep->wq, &wait);
@@ -1814,7 +1829,7 @@ check_events:
        /* Is it worth to try to dig for events ? */
        eavail = ep_events_available(ep);
 
-       spin_unlock_irqrestore(&ep->wq.lock, flags);
+       spin_unlock_irq(&ep->wq.lock);
 
        /*
         * Try to transfer events to user space. In case we get 0 events and