linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jaya Kumar <jayakumar.lkml@gmail.com>
To: linux-fbdev-devel@lists.sourceforge.net
Cc: akpm@linux-foundation.org, Jaya Kumar <jayakumar.lkml@gmail.com>
Subject: [PATCH 2/4 2.6.24] fbdev: hecubafb bugfix v4
Date: Fri, 04 Apr 2008 08:24:29 -0400	[thread overview]
Message-ID: <20080404122429.6404.76840.sendpatchset@hit-nxdomain.opendns.com> (raw)
In-Reply-To: <20080404122358.6404.54652.sendpatchset@hit-nxdomain.opendns.com>

This patch is a bugfix for hecubafb_write which would return an incorrect
error value for the bytecount from framebuffer writes.

Signed-off-by: Jaya Kumar <jayakumar.lkml@gmail.com>

---
 hecubafb.c |   52 +++++++++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 25 deletions(-)


diff --git a/drivers/video/hecubafb.c b/drivers/video/hecubafb.c
index 94e0df8..b77d033 100644
--- a/drivers/video/hecubafb.c
+++ b/drivers/video/hecubafb.c
@@ -270,41 +270,43 @@ static void hecubafb_imageblit(struct fb_info *info,
 static ssize_t hecubafb_write(struct fb_info *info, const char __user *buf,
 				size_t count, loff_t *ppos)
 {
-	unsigned long p;
-	int err=-EINVAL;
-	struct hecubafb_par *par;
-	unsigned int xres;
-	unsigned int fbmemlength;
+	struct hecubafb_par *par = info->par;
+	unsigned long p = *ppos;
+	void *dst;
+	int err = 0;
+	unsigned long total_size;
 
-	p = *ppos;
-	par = info->par;
-	xres = info->var.xres;
-	fbmemlength = (xres * info->var.yres)/8;
+	if (info->state != FBINFO_STATE_RUNNING)
+		return -EPERM;
 
-	if (p > fbmemlength)
-		return -ENOSPC;
+	total_size = info->fix.smem_len;
 
-	err = 0;
-	if ((count + p) > fbmemlength) {
-		count = fbmemlength - p;
-		err = -ENOSPC;
+	if (p > total_size)
+		return -EFBIG;
+
+	if (count > total_size) {
+		err = -EFBIG;
+		count = total_size;
 	}
 
-	if (count) {
-		char *base_addr;
+	if (count + p > total_size) {
+		if (!err)
+			err = -ENOSPC;
 
-		base_addr = (char __force *)info->screen_base;
-		count -= copy_from_user(base_addr + p, buf, count);
-		*ppos += count;
-		err = -EFAULT;
+		count = total_size - p;
 	}
 
-	hecubafb_dpy_update(par);
+	dst = (void __force *) (info->screen_base + p);
+
+	if (copy_from_user(dst, buf, count))
+		err = -EFAULT;
 
-	if (count)
-		return count;
+	if  (!err)
+		*ppos += count;
+
+	hecubafb_dpy_update(par);
 
-	return err;
+	return (err) ? err : count;
 }
 
 static struct fb_ops hecubafb_ops = {

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

  parent reply	other threads:[~2008-04-04 13:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-04 12:23 [PATCH 0/4 2.6.24] fbdev: metronomefb and hecubafb bugfix and platforming v4 Jaya Kumar
2008-04-04 12:24 ` [PATCH 1/4 2.6.24] fbdev: metronomefb bugfix v4 Jaya Kumar
2008-04-04 12:24 ` Jaya Kumar [this message]
2008-04-04 12:24 ` [PATCH 3/4 2.6.24] fbdev: platforming metronomefb and am200epd v4 Jaya Kumar
2008-04-04 12:24 ` [PATCH 4/4 2.6.24] fbdev: platforming hecubafb and n411 v4 Jaya Kumar
2008-04-07 23:53 ` [PATCH 0/4 2.6.24] fbdev: metronomefb and hecubafb bugfix and platforming v4 Andrew Morton
2008-04-08  1:31   ` Jaya Kumar

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=20080404122429.6404.76840.sendpatchset@hit-nxdomain.opendns.com \
    --to=jayakumar.lkml@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fbdev-devel@lists.sourceforge.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).