Skip to contentSkip to conversation

Behaviour change of /dev/fb0?

PATCH In review Richard Purdie 3 participants 7 messages Apr 14, 2006 – Apr 17, 2006 Framebuffer layer

lore
Share & tools
lore
#0 lore raw

Ignoring whether this is a good idea or not, under 2.6.15 you could run

dd if=/dev/zero of=/dev/fb0

which would clear the framebuffer. It would end up saying "dd: /dev/fb0:
No space left on device".

Under 2.6.16 (and a recent git kernel), the same command clears the screen but then hangs. Was the change in behaviour intentional?

I've noticed this on a couple of ARM based Zaurus handhelds under both w100fb and pxafb.

Richard

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642

#1 lore raw
Quoted 4 lines · Richard Purdie

Ignoring whether this is a good idea or not, under 2.6.15 you could run

dd if=/dev/zero of=/dev/fb0

Quoted 9 lines

which would clear the framebuffer. It would end up saying "dd: /dev/fb0:
No space left on device".

Under 2.6.16 (and a recent git kernel), the same command clears the screen but then hangs. Was the change in behaviour intentional?

I've noticed this on a couple of ARM based Zaurus handhelds under both w100fb and pxafb.

There is a change in behavior of fb_read and fb_write committed Jan 2006. They return the number of bytes read or written if the requested size is bigger than the remaining space. Previously, they returned -ENOSPC.

But I haven't experienced hangs...

Tony

#2 lore raw
Quoted 15 lines · Antonino A. Daplas
Quoted 4 lines · Richard Purdie

Ignoring whether this is a good idea or not, under 2.6.15 you could run

dd if=/dev/zero of=/dev/fb0

Quoted 9 lines

which would clear the framebuffer. It would end up saying "dd: /dev/fb0:
No space left on device".

Under 2.6.16 (and a recent git kernel), the same command clears the screen but then hangs. Was the change in behaviour intentional?

I've noticed this on a couple of ARM based Zaurus handhelds under both w100fb and pxafb.

Quoted 5 lines

There is a change in behavior of fb_read and fb_write committed Jan 2006. They return the number of bytes read or written if the requested size is bigger than the remaining space. Previously, they returned -ENOSPC.

But I haven't experienced hangs...

The change in question is:

@@ -661,19 +664,19 @@ fb_write(struct file *file, const char _
return info->fbops->fb_write(file, buf, count, ppos);

total_size = info->screen_size;
+
if (total_size == 0)
total_size = info->fix.smem_len;

if (p > total_size)
- return -ENOSPC;
+ return 0;
+
if (count >= total_size)
- count = total_size;
- err = 0;
- if (count + p > total_size) {
- count = total_size - p;
- err = -ENOSPC;
- }
- cnt = 0;
+ count = total_size;
+
+ if (count + p > total_size)
+ count = total_size - p;
+
buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
GFP_KERNEL);
if (!buffer)

I agree with the latter part of this but not the change for the "if (p > total_size)" case. If we return zero here, the writer will just keep retrying to write to the device indefinitely and therefore hang. Would it make sense to revert that part of the change?:

If we reach the end of the framebuffer, we should return an out of space error, not zero. Returning zero implies we might be able to write further bytes at some future time which isn't true.

drivers/video/fbmem.c +1 -1
Index: git/drivers/video/fbmem.c
===================================================================
@@ -674,7 +674,7 @@
 		total_size = info->fix.smem_len;
 
 	if (p > total_size)
-		return 0;
+		return -ENOSPC;
 
 	if (count >= total_size)
 		count = total_size;
#3 lore raw
In reply to Richard Purdie
Quoted 4 lines · Richard Purdie

Ignoring whether this is a good idea or not, under 2.6.15 you could run

dd if=/dev/zero of=/dev/fb0

Quoted 9 lines

which would clear the framebuffer. It would end up saying "dd: /dev/fb0:
No space left on device".

Under 2.6.16 (and a recent git kernel), the same command clears the screen but then hangs. Was the change in behaviour intentional?

I've noticed this on a couple of ARM based Zaurus handhelds under both w100fb and pxafb.

After reading 'man 2 read' more thoroughly, I've adjusted fb_write()'s return codes appropriately. Can you try this patch and let me know if it fixes your problem.

Tony

fbdev: Fix return error of fb_write()

- return -EFBIG if file offset is past the maximum allowable offset
- return -EFBIG and write to end of framebuffer if size is bigger than the framebuffer length
- return -ENOSPC and write to end of framebuffer if size is bigger than the framebuffer length - file offset

---

 drivers/video/fbmem.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
drivers/video/fbmem.c +9 -3
index 944855b..8a643bf 100644
@@ -669,13 +669,19 @@ fb_write(struct file *file, const char _
 		total_size = info->fix.smem_len;
 
 	if (p > total_size)
-		return 0;
+		return -EFBIG;
 
-	if (count >= total_size)
+	if (count >= total_size) {
+		err = -EFBIG;
 		count = total_size;
+	}
+
+	if (count + p > total_size) {
+		if (!err)
+			err = -ENOSPC;
 
-	if (count + p > total_size)
 		count = total_size - p;
+	}
 
 	buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
 			 GFP_KERNEL);
#4 lore raw
Quoted 20 lines · Antonino A. Daplas
Quoted 4 lines · Richard Purdie

Ignoring whether this is a good idea or not, under 2.6.15 you could run

dd if=/dev/zero of=/dev/fb0

Quoted 9 lines

which would clear the framebuffer. It would end up saying "dd: /dev/fb0:
No space left on device".

Under 2.6.16 (and a recent git kernel), the same command clears the screen but then hangs. Was the change in behaviour intentional?

I've noticed this on a couple of ARM based Zaurus handhelds under both w100fb and pxafb.

After reading 'man 2 read' more thoroughly, I've adjusted fb_write()'s return codes appropriately. Can you try this patch and let me know if it fixes your problem.

Quoted 5 lines

Tony

fbdev: Fix return error of fb_write()

- return -EFBIG if file offset is past the maximum allowable offset

OK.

Quoted 2 lines

- return -EFBIG and write to end of framebuffer if size is bigger than the framebuffer length

We should return the number of bytes written in this case.

Quoted 2 lines

- return -ENOSPC and write to end of framebuffer if size is bigger than the framebuffer length - file offset

Also here.

If we can transfer _any_ bytes, we should do so, then return the number of bytes transferred. If no bytes were transferrable then we should return -Ewhatever.

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642

#5 lore raw

PATCH 1/1 fbdev: Fix return error of fb_write

Fix return code of fb_write():

If at least 1 byte was transferred to the device, return number of bytes, otherwise:

- return -EFBIG - if file offset is past the maximum allowable offset or size is greater than framebuffer length
- return -ENOSPC - if size is greater than framebuffer length - offset

---

Quoted 15 lines · Andrew Morton
Quoted 3 lines · Antonino A. Daplas

Richard Purdie wrote:

- return -EFBIG if file offset is past the maximum allowable offset

OK.

Quoted 2 lines

- return -EFBIG and write to end of framebuffer if size is bigger than the framebuffer length

We should return the number of bytes written in this case.

Quoted 2 lines

- return -ENOSPC and write to end of framebuffer if size is bigger than the framebuffer length - file offset

Quoted 8 lines

Also here.

If we can transfer _any_ bytes, we should do so, then return the number of bytes transferred. If no bytes were transferrable then we should return -Ewhatever.

Okay, here's try #2:

 drivers/video/fbmem.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
drivers/video/fbmem.c +10 -4
index 944855b..a4b6776 100644
@@ -669,13 +669,19 @@ fb_write(struct file *file, const char _
 		total_size = info->fix.smem_len;
 
 	if (p > total_size)
-		return 0;
+		return -EFBIG;
 
-	if (count >= total_size)
+	if (count > total_size) {
+		err = -EFBIG;
 		count = total_size;
+	}
+
+	if (count + p > total_size) {
+		if (!err)
+			err = -ENOSPC;
 
-	if (count + p > total_size)
 		count = total_size - p;
+	}
 
 	buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
 			 GFP_KERNEL);
@@ -717,7 +723,7 @@ fb_write(struct file *file, const char _
 
 	kfree(buffer);
 
-	return (err) ? err : cnt;
+	return (cnt) ? cnt : err;
 }
 
 #ifdef CONFIG_KMOD
#6 lore raw

Re: [PATCH] fbdev: Fix return error of fb_write

Quoted 10 lines · Antonino A. Daplas

Fix return code of fb_write():

If at least 1 byte was transferred to the device, return number of bytes, otherwise:

- return -EFBIG - if file offset is past the maximum allowable offset or size is greater than framebuffer length
- return -ENOSPC - if size is greater than framebuffer length - offset

I can confirm this fixes the problem I reported, thanks!

Richard

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642