Skip to content

poll_wait()

Purpose

poll_wait() connects a driver's wait queue to the kernel poll infrastructure. It allows poll, select, and epoll to wait for driver readiness.

Prototype Pattern

static __poll_t mydev_poll(struct file *file, poll_table *wait)
{
    poll_wait(file, &dev->wq, wait);

    if (data_available(dev))
        return EPOLLIN | EPOLLRDNORM;

    return 0;
}

Important Concept

poll_wait() does not check readiness. It only registers the wait queue. The driver must still return a readiness mask based on current state.

Relationship with Wait Queues

A typical poll flow is:

Userspace poll()
Driver .poll()
poll_wait()
Register wait queue
Return event mask
No event?
Kernel sleeps
wake_up()
Driver .poll() again
Return POLLIN

Notice that poll_wait() never blocks.

Sleeping is performed later by the poll framework if no file descriptor reports readiness.

Readiness Masks

Mask Meaning
EPOLLIN Data is available to read
EPOLLRDNORM Normal readable data is available
EPOLLOUT Device can accept write data
EPOLLERR Error condition
EPOLLHUP Hangup condition