/* Get buffer to userspace. */ static struct ispstat_buffer *isp_stat_buf_get(struct ispstat *stat, struct omap3isp_stat_data *data) { int rval = 0; unsigned long flags; struct ispstat_buffer *buf; spin_lock_irqsave(&stat->isp->stat_lock, flags); while (1) { buf = isp_stat_buf_find_oldest(stat); if (!buf) { spin_unlock_irqrestore(&stat->isp->stat_lock, flags); dev_dbg(stat->isp->dev, "%s: cannot find a buffer.\n", stat->subdev.name); return ERR_PTR(-EBUSY); } if (isp_stat_buf_check_magic(stat, buf)) { dev_dbg(stat->isp->dev, "%s: current buffer has corrupted data\n.", stat->subdev.name); /* Mark empty because it doesn't have valid data. */ buf->empty = 1; } else { /* Buffer isn't corrupted. */ break; } } stat->locked_buf = buf; spin_unlock_irqrestore(&stat->isp->stat_lock, flags); if (buf->buf_size > data->buf_size) { dev_warn(stat->isp->dev, "%s: userspace's buffer size is not enough.\n", stat->subdev.name); isp_stat_buf_release(stat); return ERR_PTR(-EINVAL); } isp_stat_buf_sync_for_cpu(stat, buf); rval = copy_to_user(data->buf, buf->virt_addr, buf->buf_size); if (rval) { dev_info(stat->isp->dev, "%s: failed copying %d bytes of stat data\n", stat->subdev.name, rval); buf = ERR_PTR(-EFAULT); isp_stat_buf_release(stat); } return buf; }
static int isp_stat_buf_queue(struct ispstat *stat) { if (!stat->active_buf) return STAT_NO_BUF; ktime_get_ts(&stat->active_buf->ts); stat->active_buf->buf_size = stat->buf_size; if (isp_stat_buf_check_magic(stat, stat->active_buf)) { dev_dbg(stat->isp->dev, "%s: data wasn't properly written.\n", stat->subdev.name); return STAT_NO_BUF; } stat->active_buf->config_counter = stat->config_counter; stat->active_buf->frame_number = stat->frame_number; stat->active_buf->empty = 0; stat->active_buf = NULL; return STAT_BUF_DONE; }