/* Read as many bytes from the mailbox as possible, until one of the conditions becomes true: */
static ssize_t spufs_mbox_read(struct file *file, char __user *buf, size_t len, loff_t *pos)
/* Read as many bytes from the mailbox as possible, until one of the conditions becomes true: */
static ssize_t spufs_mbox_read(struct file *file, char __user *buf, size_t len, loff_t *pos)
{
	struct spu_context *ctx = file->private_data;
	u32 mbox_data, __user *udata;
	ssize_t count;
	if (len < 4)
		return -EINVAL;
	if (!access_ok(VERIFY_WRITE, buf, len))
		return -EFAULT;
	udata = (void __user *)buf;
	count = spu_acquire(ctx);
	if (count)
		return count;
	for (count = 0; (count + 4) <= len; count += 4, udata++) {
		int ret;
		ret = ctx->ops->mbox_read(ctx, &mbox_data);
		if (ret == 0)
			break;
		ret = __put_user(mbox_data, udata);
		if (ret) {
			if (!count)
				count = -EFAULT;
			break;
		}
	}
	spu_release(ctx);
	if (!count)
		count = -EAGAIN;
	return count;
}