static unsigned int poll(struct file *file, struct socket *sock, poll_table *wait) { struct sock *sk = sock->sk; u32 mask; poll_wait(file, sk->sk_sleep, wait); if (!skb_queue_empty(&sk->sk_receive_queue) || (sock->state == SS_UNCONNECTED) || (sock->state == SS_DISCONNECTING)) mask = (POLLRDNORM | POLLIN); else mask = 0; if (sock->state == SS_DISCONNECTING) mask |= POLLHUP; else mask |= POLLOUT; return mask; }
/** * mei_poll - the poll function * * @file: pointer to file structure * @wait: pointer to poll_table structure * * Return: poll mask */ static unsigned int mei_poll(struct file *file, poll_table *wait) { unsigned long req_events = poll_requested_events(wait); struct mei_cl *cl = file->private_data; struct mei_device *dev; unsigned int mask = 0; if (WARN_ON(!cl || !cl->dev)) return POLLERR; dev = cl->dev; mutex_lock(&dev->device_lock); if (dev->dev_state != MEI_DEV_ENABLED || !mei_cl_is_connected(cl)) { mask = POLLERR; goto out; } if (cl == &dev->iamthif_cl) { mask = mei_amthif_poll(dev, file, wait); goto out; } if (req_events & (POLLIN | POLLRDNORM)) { poll_wait(file, &cl->rx_wait, wait); if (!list_empty(&cl->rd_completed)) mask |= POLLIN | POLLRDNORM; else mei_cl_read_start(cl, 0, file); } out: mutex_unlock(&dev->device_lock); return mask; }
/** * datagram_poll - generic datagram poll * @file: file struct * @sock: socket * @wait: poll table * * Datagram poll: Again totally generic. This also handles * sequenced packet sockets providing the socket receive queue * is only ever holding data ready to receive. * * Note: when you _don't_ use this routine for this protocol, * and you use a different write policy from sock_writeable() * then please supply your own write_space callback. */ unsigned int datagram_poll(struct file *file, struct socket *sock, poll_table *wait) { struct sock *sk = sock->sk; unsigned int mask; poll_wait(file, sk->sk_sleep, wait); mask = 0; /* exceptional events? */ if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) mask |= POLLERR; if (sk->sk_shutdown & RCV_SHUTDOWN) mask |= POLLRDHUP; if (sk->sk_shutdown == SHUTDOWN_MASK) mask |= POLLHUP; /* readable? */ if (!skb_queue_empty(&sk->sk_receive_queue) || (sk->sk_shutdown & RCV_SHUTDOWN)) mask |= POLLIN | POLLRDNORM; /* Connection-based need to check for termination and startup */ if (connection_based(sk)) { if (sk->sk_state == TCP_CLOSE) mask |= POLLHUP; /* connection hasn't started yet? */ if (sk->sk_state == TCP_SYN_SENT) return mask; } /* writable? */ if (sock_writeable(sk)) mask |= POLLOUT | POLLWRNORM | POLLWRBAND; else set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); return mask; }
unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait) { unsigned long flags; unsigned int ret; struct vb2_buffer *vb = NULL; if (q->num_buffers == 0 && q->fileio == NULL) { if (!V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_READ)) { ret = __vb2_init_fileio(q, 1); if (ret) return POLLERR; } if (V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_WRITE)) { ret = __vb2_init_fileio(q, 0); if (ret) return POLLERR; return POLLOUT | POLLWRNORM; } } if (list_empty(&q->queued_list)) return POLLERR; poll_wait(file, &q->done_wq, wait); spin_lock_irqsave(&q->done_lock, flags); if (!list_empty(&q->done_list)) vb = list_first_entry(&q->done_list, struct vb2_buffer, done_entry); spin_unlock_irqrestore(&q->done_lock, flags); if (vb && (vb->state == VB2_BUF_STATE_DONE || vb->state == VB2_BUF_STATE_ERROR)) { return (V4L2_TYPE_IS_OUTPUT(q->type)) ? POLLOUT | POLLWRNORM : POLLIN | POLLRDNORM; } return 0; }
/** * @brief Poll the video queue. * * @param queue * @param file * @param wait * * This function implements video queue polling and is intended to be used by * the device poll handler. */ unsigned int microdia_queue_poll(struct microdia_video_queue *queue, struct file *file, poll_table *wait) { struct microdia_buffer *buf; unsigned int mask = 0; mutex_lock(&queue->mutex); if (list_empty(&queue->mainqueue)) { mask |= POLLERR; goto done; } buf = list_first_entry(&queue->mainqueue, struct microdia_buffer, stream); poll_wait(file, &buf->wait, wait); if (buf->state == MICRODIA_BUF_STATE_DONE || buf->state == MICRODIA_BUF_STATE_ERROR) mask |= POLLIN | POLLRDNORM; done: mutex_unlock(&queue->mutex); return mask; }
static unsigned int dvb_demux_poll (struct file *file, poll_table *wait) { struct dmxdev_filter *dmxdevfilter = dvb_dmxdev_file_to_filter(file); unsigned int mask = 0; if (!dmxdevfilter) return -EINVAL; poll_wait(file, &dmxdevfilter->buffer.queue, wait); if (dmxdevfilter->state != DMXDEV_STATE_GO && dmxdevfilter->state != DMXDEV_STATE_DONE && dmxdevfilter->state != DMXDEV_STATE_TIMEDOUT) return 0; if (dmxdevfilter->buffer.error) mask |= (POLLIN | POLLRDNORM | POLLPRI | POLLERR); if (dmxdevfilter->buffer.pread != dmxdevfilter->buffer.pwrite) mask |= (POLLIN | POLLRDNORM | POLLPRI); return mask; }
static __poll_t goldfish_pipe_poll(struct file *filp, poll_table *wait) { struct goldfish_pipe *pipe = filp->private_data; __poll_t mask = 0; int status; poll_wait(filp, &pipe->wake_queue, wait); status = goldfish_pipe_cmd(pipe, PIPE_CMD_POLL); if (status < 0) return -ERESTARTSYS; if (status & PIPE_POLL_IN) mask |= EPOLLIN | EPOLLRDNORM; if (status & PIPE_POLL_OUT) mask |= EPOLLOUT | EPOLLWRNORM; if (status & PIPE_POLL_HUP) mask |= EPOLLHUP; if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) mask |= EPOLLERR; return mask; }
/** * @brief poll handler for char dev * * @param filp pointer to structure file * @param wait pointer to poll_table structure * @return mask */ static unsigned int chardev_poll(struct file *filp, poll_table * wait) { unsigned int mask; struct char_dev *dev = (struct char_dev *)filp->private_data; struct m_dev *m_dev = NULL; ENTER(); if (!dev || !dev->m_dev) { LEAVE(); return -ENXIO; } m_dev = dev->m_dev; poll_wait(filp, &m_dev->req_wait_q, wait); mask = POLLOUT | POLLWRNORM; if (skb_peek(&m_dev->rx_q)) mask |= POLLIN | POLLRDNORM; if (!test_bit(HCI_UP, &(m_dev->flags))) mask |= POLLHUP; PRINTM(INFO, "poll mask=0x%x\n", mask); LEAVE(); return mask; }
static unsigned int co_os_manager_poll(struct file *file, struct poll_table_struct *pollts) { co_manager_open_desc_t opened = (typeof(opened))(file->private_data); unsigned int mask = POLLOUT | POLLWRNORM, size; co_queue_t *queue; co_os_mutex_acquire(opened->lock); queue = &opened->out_queue; size = co_queue_size(queue); co_os_mutex_release(opened->lock); poll_wait(file, &opened->os->waitq, pollts); if (size) mask |= POLLIN | POLLRDNORM; if (!opened->active) mask |= POLLHUP; return mask; }
// We need to support this function if we want the select() call to behave // properly on this file. static unsigned int plog_poll(struct file *file, poll_table * wait) { unsigned int readable; plog_reader *s = (plog_reader*) file->private_data; monotonic_ptr file_rp = s->read_ptr; unsigned long flags; poll_wait(file, &plog_wait, wait); spin_lock_irqsave(&s_lock, flags); readable = plog_readable(file_rp); spin_unlock_irqrestore(&s_lock, flags); // If there is 4096 bytes, you can read data. if (readable >= 4096) { return POLLIN | POLLRDNORM; } return 0; }
static unsigned int proc_sys_poll(struct file *filp, poll_table *wait) { struct inode *inode = filp->f_path.dentry->d_inode; struct ctl_table *table = PROC_I(inode)->sysctl_entry; unsigned long event = (unsigned long)filp->private_data; unsigned int ret = DEFAULT_POLLMASK; if (!table->proc_handler) goto out; if (!table->poll) goto out; poll_wait(filp, &table->poll->wait, wait); if (event != atomic_read(&table->poll->event)) { filp->private_data = proc_sys_poll_event(table->poll); ret = POLLIN | POLLRDNORM | POLLERR | POLLPRI; } out: return ret; }
static unsigned int normal_poll(struct tty_struct * tty, struct file * file, poll_table *wait) { unsigned int mask = 0; poll_wait(file, &tty->poll_wait, wait); if (input_available_p(tty, TIME_CHAR(tty) ? 0 : MIN_CHAR(tty))) mask |= POLLIN | POLLRDNORM; if (tty->packet && tty->link->ctrl_status) mask |= POLLPRI | POLLIN | POLLRDNORM; if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) mask |= POLLHUP; if (tty_hung_up_p(file)) mask |= POLLHUP; if (!(mask & (POLLHUP | POLLIN | POLLRDNORM))) { if (MIN_CHAR(tty) && !TIME_CHAR(tty)) tty->minimum_to_wake = MIN_CHAR(tty); else tty->minimum_to_wake = 1; } if (tty->driver.chars_in_buffer(tty) < WAKEUP_CHARS) mask |= POLLOUT | POLLWRNORM; return mask; }
static unsigned int dvb_demux_poll(struct file *file, poll_table *wait) { struct dmxdev_filter *dmxdevfilter = file->private_data; unsigned int mask = 0; if (!dmxdevfilter) return -EINVAL; poll_wait(file, &dmxdevfilter->buffer.queue, wait); if (dmxdevfilter->state != DMXDEV_STATE_GO && dmxdevfilter->state != DMXDEV_STATE_DONE && dmxdevfilter->state != DMXDEV_STATE_TIMEDOUT) return 0; if (dmxdevfilter->buffer.error) mask |= (POLLIN | POLLRDNORM | POLLPRI | POLLERR); if (!dvb_ringbuffer_empty(&dmxdevfilter->buffer)) mask |= (POLLIN | POLLRDNORM | POLLPRI); return mask; }
static unsigned int rawchip_fops_poll(struct file *filp, struct poll_table_struct *pll_table) { int rc = 0; unsigned long flags; poll_wait(filp, &yushan_int.yushan_wait, pll_table); spin_lock_irqsave(&yushan_int.yushan_spin_lock, flags); if (atomic_read(&interrupt)) { atomic_set(&interrupt, 0); atomic_set(&rawchipCtrl->check_intr0, 1); rc = POLLIN | POLLRDNORM; } if (atomic_read(&interrupt2)) { atomic_set(&interrupt2, 0); atomic_set(&rawchipCtrl->check_intr1, 1); rc = POLLIN | POLLRDNORM; } spin_unlock_irqrestore(&yushan_int.yushan_spin_lock, flags); return rc; }
static unsigned int avSync_device_poll(struct file *file, struct poll_table_struct *wait) { isil_avSync_dev_t *dev; unsigned int mask = 0; dev = (isil_avSync_dev_t*)file->private_data; if (dev == NULL) { printk("[%s]:video_dev is null\n", __FUNCTION__); return -ENODEV; } down(&dev->sem); if(atomic_read(&dev->opened_flags)) { poll_wait(file, &dev->wait_poll, wait); if(dev->avSync_frame_queue.op->get_curr_queue_entry_number(&dev->avSync_frame_queue)){ mask = POLLIN | POLLRDNORM; } } else { printk("%s:%s have not been opened\n", __FUNCTION__, dev->name); mask = POLLOUT | POLLWRNORM | POLLIN | POLLRDNORM; } up(&dev->sem); return mask; }
static unsigned int rmnet_ctl_poll(struct file *file, poll_table *wait) { unsigned int mask = 0; struct rmnet_ctrl_dev *dev; dev = file->private_data; if (!dev) return POLLERR; poll_wait(file, &dev->read_wait_queue, wait); if (!is_dev_connected(dev)) { dev_dbg(dev->devicep, "%s: Device not connected\n", __func__); return POLLERR; } if (!list_empty(&dev->rx_list)) { poll_time = cpu_clock(smp_processor_id()); rd_poll_delta_time = poll_time - rd_cb_time; mask |= POLLIN | POLLRDNORM; } return mask; }
/* Sysfs attribute files are pollable. The idea is that you read * the content and then you use 'poll' or 'select' to wait for * the content to change. When the content changes (assuming the * manager for the kobject supports notification), poll will * return POLLERR|POLLPRI, and select will return the fd whether * it is waiting for read, write, or exceptions. * Once poll/select indicates that the value has changed, you * need to close and re-open the file, as simply seeking and reading * again will not get new data, or reset the state of 'poll'. * Reminder: this only works for attributes which actively support * it, and it is not possible to test an attribute from userspace * to see if it supports poll (Nether 'poll' or 'select' return * an appropriate error code). When in doubt, set a suitable timeout value. */ static unsigned int sysfs_poll(struct file *filp, poll_table *wait) { struct sysfs_buffer * buffer = filp->private_data; struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata; struct kobject *kobj = attr_sd->s_parent->s_elem.dir.kobj; /* need parent for the kobj, grab both */ if (!sysfs_get_active_two(attr_sd)) goto trigger; poll_wait(filp, &kobj->poll, wait); sysfs_put_active_two(attr_sd); if (buffer->event != atomic_read(&attr_sd->s_event)) goto trigger; return 0; trigger: buffer->needs_read_fill = 1; return POLLERR|POLLPRI; }
static unsigned int g2d_poll(struct file *file, poll_table *wait) { unsigned int mask = 0; if (atomic_read(&g2d_dev->in_use) == 0) { mask = POLLOUT | POLLWRNORM; g2d_clk_disable(g2d_dev); mutex_unlock(&g2d_dev->lock); } else { poll_wait(file, &g2d_dev->waitq, wait); if(atomic_read(&g2d_dev->in_use) == 0) { mask = POLLOUT | POLLWRNORM; g2d_clk_disable(g2d_dev); mutex_unlock(&g2d_dev->lock); } } return mask; }
/* Sysfs attribute files are pollable. The idea is that you read * the content and then you use 'poll' or 'select' to wait for * the content to change. When the content changes (assuming the * manager for the kobject supports notification), poll will * return POLLERR|POLLPRI, and select will return the fd whether * it is waiting for read, write, or exceptions. * Once poll/select indicates that the value has changed, you * need to close and re-open the file, or seek to 0 and read again. * Reminder: this only works for attributes which actively support * it, and it is not possible to test an attribute from userspace * to see if it supports poll (Neither 'poll' nor 'select' return * an appropriate error code). When in doubt, set a suitable timeout value. */ static unsigned int sysfs_poll(struct file *filp, poll_table *wait) { struct sysfs_buffer * buffer = filp->private_data; struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata; struct sysfs_open_dirent *od = attr_sd->s_attr.open; /* need parent for the kobj, grab both */ if (!sysfs_get_active(attr_sd)) goto trigger; poll_wait(filp, &od->poll, wait); sysfs_put_active(attr_sd); if (buffer->event != atomic_read_unchecked(&od->event)) goto trigger; return DEFAULT_POLLMASK; trigger: buffer->needs_read_fill = 1; return DEFAULT_POLLMASK|POLLERR|POLLPRI; }
/** * ecryptfs_miscdev_poll * @file: dev file (ignored) * @pt: dev poll table (ignored) * * Returns the poll mask */ static unsigned int ecryptfs_miscdev_poll(struct file *file, poll_table *pt) { struct ecryptfs_daemon *daemon; unsigned int mask = 0; uid_t euid = current_euid(); int rc; mutex_lock(&ecryptfs_daemon_hash_mux); /* TODO: Just use file->private_data? */ rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns()); if (rc || !daemon) { mutex_unlock(&ecryptfs_daemon_hash_mux); return -EINVAL; } mutex_lock(&daemon->mux); mutex_unlock(&ecryptfs_daemon_hash_mux); if (daemon->flags & ECRYPTFS_DAEMON_ZOMBIE) { printk(KERN_WARNING "%s: Attempt to poll on zombified " "daemon\n", __func__); goto out_unlock_daemon; } if (daemon->flags & ECRYPTFS_DAEMON_IN_READ) goto out_unlock_daemon; if (daemon->flags & ECRYPTFS_DAEMON_IN_POLL) goto out_unlock_daemon; daemon->flags |= ECRYPTFS_DAEMON_IN_POLL; mutex_unlock(&daemon->mux); poll_wait(file, &daemon->wait, pt); mutex_lock(&daemon->mux); if (!list_empty(&daemon->msg_ctx_out_queue)) mask |= POLLIN | POLLRDNORM; out_unlock_daemon: daemon->flags &= ~ECRYPTFS_DAEMON_IN_POLL; mutex_unlock(&daemon->mux); return mask; }
/* Called without the kernel lock held - fine */ static unsigned int r3964_poll(struct tty_struct *tty, struct file *file, struct poll_table_struct *wait) { struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; struct r3964_client_info *pClient; struct r3964_message *pMsg = NULL; unsigned long flags; int result = POLLOUT; TRACE_L("POLL"); pClient = findClient(pInfo, task_pid(current)); if (pClient) { poll_wait(file, &pInfo->read_wait, wait); spin_lock_irqsave(&pInfo->lock, flags); pMsg = pClient->first_msg; spin_unlock_irqrestore(&pInfo->lock, flags); if (pMsg) result |= POLLIN | POLLRDNORM; } else { result = -EINVAL; } return result; }
static unsigned int qti_ctrl_poll(struct file *file, poll_table *wait) { struct qti_ctrl_port *port = container_of(file->private_data, struct qti_ctrl_port, ctrl_device); unsigned long flags; unsigned int mask = 0; if (!port) { pr_err("%s on a NULL device\n", __func__); return POLLERR; } poll_wait(file, &port->read_wq, wait); spin_lock_irqsave(&port->lock, flags); if (!list_empty(&port->cpkt_req_q)) { mask |= POLLIN | POLLRDNORM; pr_debug("%s sets POLLIN for rmnet_ctrl_qti_port\n", __func__); } spin_unlock_irqrestore(&port->lock, flags); return mask; }
static unsigned int bus1_fop_poll(struct file *file, struct poll_table_struct *wait) { struct bus1_peer *peer = file->private_data; struct bus1_peer_info *peer_info; unsigned int mask; poll_wait(file, &peer->waitq, wait); /* * If the peer is still in state NEW, then CONNECT hasn't been called * and the peer is unused. Return no event at all. */ if (bus1_active_is_new(&peer->active)) return 0; /* * We now dereference the peer object (which is rcu-protected). It * might be NULL during a racing DISCONNECT. If it is non-NULL *and* * the peer has not been deactivated, then the peer is live and thus * writable. If data is queued, it is readable as well. */ rcu_read_lock(); peer_info = rcu_dereference(peer->info); if (!peer_info || bus1_active_is_deactivated(&peer->active)) { mask = POLLERR | POLLHUP; } else { mask = POLLOUT | POLLWRNORM; if (bus1_queue_is_readable(&peer_info->queue) || atomic_read(&peer_info->n_dropped) > 0) mask |= POLLIN | POLLRDNORM; } rcu_read_unlock(); return mask; }
unsigned int afu_poll(struct file *file, struct poll_table_struct *poll) { struct cxl_context *ctx = file->private_data; int mask = 0; unsigned long flags; poll_wait(file, &ctx->wq, poll); pr_devel("afu_poll wait done pe: %i\n", ctx->pe); spin_lock_irqsave(&ctx->lock, flags); if (ctx_event_pending(ctx)) mask |= POLLIN | POLLRDNORM; else if (ctx->status == CLOSED) /* Only error on closed when there are no futher events pending */ mask |= POLLERR; spin_unlock_irqrestore(&ctx->lock, flags); pr_devel("afu_poll pe: %i returning %#x\n", ctx->pe, mask); return mask; }
static unsigned int ach_ch_poll(struct file *file, poll_table * wait) { unsigned int mask = POLLOUT | POLLWRNORM; struct ach_ch_file *ch_file = (struct ach_ch_file *)file->private_data; struct ach_header *shm = ch_file->shm; enum ach_status r; /* KDEBUG1("In ach_ch_poll (minor=%d)\n", ch_file->dev->minor); */ /* Add ourselves wait queue */ poll_wait(file, &shm->sync.readq, wait); /* Lock channel and check what happened */ r = chan_lock(ch_file); if( ACH_OK != r ) return -get_errno(r); if (ch_file->seq_num != shm->last_seq) { mask |= POLLIN | POLLRDNORM; } rt_mutex_unlock(&shm->sync.mutex); return mask; }
static unsigned xnpipe_poll(struct file *file, poll_table *pt) { struct xnpipe_state *state = file->private_data; unsigned r_mask = 0, w_mask = 0; spl_t s; poll_wait(file, &state->readq, pt); xnlock_get_irqsave(&nklock, s); if (testbits(state->status, XNPIPE_KERN_CONN)) w_mask |= (POLLOUT | POLLWRNORM); else r_mask |= POLLHUP; if (!emptyq_p(&state->outq)) r_mask |= (POLLIN | POLLRDNORM); else /* * Procs which have issued a timed out poll req will * remain linked to the sleepers queue, and will be * silently unlinked the next time the Xenomai side * kicks xnpipe_wakeup_proc. */ xnpipe_enqueue_wait(state, XNPIPE_USER_WREAD); xnlock_put_irqrestore(&nklock, s); /* * A descriptor is always ready for writing with the current * implementation, so there is no need to have/handle the * writeq queue so far. */ return r_mask | w_mask; }
static unsigned int rpcrouter_poll(struct file *filp, struct poll_table_struct *wait) { struct msm_rpc_endpoint *ept; unsigned mask = 0; ept = (struct msm_rpc_endpoint *) filp->private_data; if (!list_empty(&ept->read_q)) mask |= POLLIN; if (ept->restart_state != 0) mask |= POLLERR; if (!mask) { poll_wait(filp, &ept->wait_q, wait); if (!list_empty(&ept->read_q)) mask |= POLLIN; if (ept->restart_state != 0) mask |= POLLERR; } return mask; }
unsigned int signal_poll(struct file *filp,struct poll_table_struct *wait) { unsigned int mask=0; if(down_interruptible(&sem)) { return -ERESTARTSYS; } poll_wait(filp,&my_queue,wait); if(buffer_char_count>0) { mask|=POLLIN|POLLRDNORM; } if(buffer_char_count==0) { mask|=POLLOUT|POLLWRNORM; } up(&sem); return mask; }
unsigned int fm_chr_poll(struct file *file, poll_table * wait) { unsigned long mask; FM_CHR_DRV_DBG(" inside %s", __func__); mask = 0; /* Poll and wait */ poll_wait(file, &fm_chr_dev->fm_data_q, wait); spin_lock(&fm_chr_dev->lock); FM_CHR_DRV_VER(" Completed poll "); if (!skb_queue_empty(&fm_chr_dev->rx_q)) mask |= POLLIN; FM_CHR_DRV_VER(" return 0x%02x \n", (unsigned int)mask); spin_unlock(&fm_chr_dev->lock); return mask; }
unsigned int DMAbuf_poll(struct file * file, int dev, poll_table *wait) { struct audio_operations *adev = audio_devs[dev]; poll_wait(file, &adev->poll_sleeper, wait); return poll_input(file, dev, wait) | poll_output(file, dev, wait); }