Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4868bfca authored by Gidon Studinski's avatar Gidon Studinski Committed by Alexei Avshalom Lazar
Browse files

wigig_sensing: enforce data read in multiple of burst size



In case user space application requests for data size which is not a
multiple of the burst size and there is enough data in the drivers internal
buffer, a partial burst may be read by the application, which may cause
loss of burst boundary.

This patch fixes the above. In case the application supplies a buffer which
is smaller than the burst size, an error is returned to the application.

Change-Id: I5233476d99937dd1a13ceaec625588414a1dc04a
Signed-off-by: default avatarGidon Studinski <gidons@codeaurora.org>
Signed-off-by: default avatarAlexei Avshalom Lazar <ailizaro@codeaurora.org>
parent 12db0990
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -711,6 +711,12 @@ static ssize_t wigig_sensing_read(struct file *filp, char __user *buf,
	if (ctx->stm.change_mode_in_progress)
		return -EINVAL;

	/* Read buffer too small */
	if (count < ctx->stm.burst_size) {
		pr_err("Read buffer must be larger than burst size\n");
		return -EINVAL;
	}

	/* No data in the buffer */
	while (circ_cnt(&d->b, d->size_bytes) == 0) {
		if (filp->f_flags & O_NONBLOCK)
@@ -720,11 +726,11 @@ static ssize_t wigig_sensing_read(struct file *filp, char __user *buf,
			circ_cnt(&d->b, d->size_bytes) != 0))
			return -ERESTARTSYS;
	}

	if (mutex_lock_interruptible(&d->lock))
		return -ERESTARTSYS;

	copy_size = min_t(u32, circ_cnt(&d->b, d->size_bytes), count);
	copy_size -= copy_size % ctx->stm.burst_size;
	size_to_end = circ_cnt_to_end(&d->b, d->size_bytes);
	tail = d->b.tail;
	pr_debug("copy_size=%u, size_to_end=%u, head=%u, tail=%u\n",