All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>,
	Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>,
	Jeremy Kerr <jk@ozlabs.org>
Subject: [PATCH] powerpc/powernv/prd: Allow copying partial data to user space
Date: Tue, 22 Oct 2019 17:02:13 +0530	[thread overview]
Message-ID: <20191022113213.18295-1-hegdevasant@linux.vnet.ibm.com> (raw)

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 --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,
-- 
2.21.0


                 reply	other threads:[~2019-10-22 11:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191022113213.18295-1-hegdevasant@linux.vnet.ibm.com \
    --to=hegdevasant@linux.vnet.ibm.com \
    --cc=jk@ozlabs.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=svaidy@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.