diff mbox series

powerpc/powernv/prd: Allow copying partial data to user space

Message ID 20191022113213.18295-1-hegdevasant@linux.vnet.ibm.com (mailing list archive)
State New
Headers show
Series powerpc/powernv/prd: Allow copying partial data to user space | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch powerpc/merge (6b450d0404ca83dc131dadffd40c5aa6f7a603af)
snowpatch_ozlabs/build-ppc64le success Build succeeded
snowpatch_ozlabs/build-ppc64be success Build succeeded
snowpatch_ozlabs/build-ppc64e success Build succeeded
snowpatch_ozlabs/build-pmac32 success Build succeeded
snowpatch_ozlabs/checkpatch success total: 0 errors, 0 warnings, 0 checks, 56 lines checked

Commit Message

Vasant Hegde Oct. 22, 2019, 11:32 a.m. UTC
Allow copying partial data to user space. So that opal-prd daemon
can read message size, reallocate memory and make read call to
get rest of the data.

Cc: Jeremy Kerr <jk@ozlabs.org>
Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/powernv/opal-prd.c | 27 ++++++++---------------
 1 file changed, 9 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/arch/powerpc/platforms/powernv/opal-prd.c b/arch/powerpc/platforms/powernv/opal-prd.c
index 45f4223a790f..dac9d18293d8 100644
--- a/arch/powerpc/platforms/powernv/opal-prd.c
+++ b/arch/powerpc/platforms/powernv/opal-prd.c
@@ -153,20 +153,15 @@  static __poll_t opal_prd_poll(struct file *file,
 static ssize_t opal_prd_read(struct file *file, char __user *buf,
 		size_t count, loff_t *ppos)
 {
-	struct opal_prd_msg_queue_item *item;
+	struct opal_prd_msg_queue_item *item = NULL;
 	unsigned long flags;
-	ssize_t size, err;
+	ssize_t size;
 	int rc;
 
 	/* we need at least a header's worth of data */
 	if (count < sizeof(item->msg))
 		return -EINVAL;
 
-	if (*ppos)
-		return -ESPIPE;
-
-	item = NULL;
-
 	for (;;) {
 
 		spin_lock_irqsave(&opal_prd_msg_queue_lock, flags);
@@ -190,27 +185,23 @@  static ssize_t opal_prd_read(struct file *file, char __user *buf,
 	}
 
 	size = be16_to_cpu(item->msg.size);
-	if (size > count) {
-		err = -EINVAL;
+	rc = simple_read_from_buffer(buf, count, ppos, &item->msg, size);
+	if (rc < 0)
 		goto err_requeue;
-	}
-
-	rc = copy_to_user(buf, &item->msg, size);
-	if (rc) {
-		err = -EFAULT;
+	if (*ppos < size)
 		goto err_requeue;
-	}
 
+	/* Reset position */
+	*ppos = 0;
 	kfree(item);
-
-	return size;
+	return rc;
 
 err_requeue:
 	/* eep! re-queue at the head of the list */
 	spin_lock_irqsave(&opal_prd_msg_queue_lock, flags);
 	list_add(&item->list, &opal_prd_msg_queue);
 	spin_unlock_irqrestore(&opal_prd_msg_queue_lock, flags);
-	return err;
+	return rc;
 }
 
 static ssize_t opal_prd_write(struct file *file, const char __user *buf,