Beispiel #1
0
static ssize_t rd_read(struct file *file, char __user *buf,
                       size_t sz, loff_t *ppos)
{
    struct msm_rd_state *rd = file->private_data;
    struct circ_buf *fifo = &rd->fifo;
    const char *fptr = &fifo->buf[fifo->tail];
    int n = 0, ret = 0;

    mutex_lock(&rd->read_lock);

    ret = wait_event_interruptible(rd->fifo_event,
                                   circ_count(&rd->fifo) > 0);
    if (ret)
        goto out;

    n = min_t(int, sz, circ_count_to_end(&rd->fifo));
    ret = copy_to_user(buf, fptr, n);
    if (ret)
        goto out;

    fifo->tail = (fifo->tail + n) & (BUF_SZ - 1);
    *ppos += n;

    wake_up_all(&rd->fifo_event);

out:
    mutex_unlock(&rd->read_lock);
    if (ret)
        return ret;
    return n;
}
Beispiel #2
0
static inline bool __acpi_aml_readable(struct circ_buf *circ, unsigned long flag)
{
	/*
	 * Another read is not in progress and there is data in buffer
	 * available for read.
	 */
	if (!(acpi_aml_io.flags & flag) && circ_count(circ))
		return true;
	return false;
}