Thread (33 messages) 33 messages, 5 authors, 2008-09-04
STALE6598d

[PATCH] Add fb_check_var() for fixed mode device.

From: Takashi Yoshii <hidden>
Date: 2008-08-29 05:15:18
Subsystem: framebuffer layer, the rest · Maintainers: Helge Deller, Linus Torvalds

Sounds good.
4. Provide a generic check_var() that does some basic sanity checking
against info->var (eg. check xres, yres and bits_per_pixel).
How about this.
Any comments? Expecially about what to check, what to restore.

Cheers,
/yoshii # Restoring pixclock would be a workaround for Xorg issue :)

drivers/video/fbmem.c:fb_check_var()
 New function for fixed mode device which doesn't provide its own
 check_var function.

Signed-off-by: Takashi YOSHII <redacted>
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index c6b8e92..ff94eaf 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -904,6 +904,56 @@ static int fb_check_caps(struct fb_info *info, struct fb_var_screeninfo *var,
 	return err;
 }
 
+/* Sanity check for drivers which can't change video mode */
+static int
+fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
+{
+	struct fb_var_screeninfo *constant = &info->var;
+        __u32 xoffset = var->xoffset;
+	__u32 yoffset = var->yoffset;
+	__u32 activate = var->activate;
+	__u32 yres = (constant->vmode & FB_VMODE_YWRAP)? 0: var->yres; 
+
+	/* do round _up_ */
+	if (var->xres_virtual < xoffset + var->xres)
+		var->xres_virtual = xoffset + var->xres;
+	if (var->yres_virtual < yoffset + yres)
+		var->yres_virtual = yoffset + yres;
+
+	/* bigger is error, smaller is OK */
+	if( ( var->xres > constant->xres )
+	  ||( var->yres > constant->yres )
+	  ||( var->xres_virtual > constant->xres_virtual )
+	  ||( var->yres_virtual > constant->yres_virtual ))
+		return -EINVAL;
+
+	/* only length are checked for bitfields */
+	if( ( var->bits_per_pixel > constant->bits_per_pixel )
+	  ||( var->red.length > constant->red.length )
+	  ||( var->green.length > constant->green.length )
+	  ||( var->blue.length > constant->blue.length ))
+		return -EINVAL;
+
+	/* boolean parameters can't be rounded, should be equal */
+	if( ( !var->grayscale != !constant->grayscale )
+	  ||( !var->nonstd != !constant->nonstd )
+	  ||( var->vmode != constant->vmode ))
+		return -EINVAL;
+
+	/* pan is acceptable only if we have fb_pan_display) */
+	if ( (var->yoffset || var->xoffset) && !info->fbops->fb_pan_display )
+		return -EINVAL;
+
+	/* copy most */
+	*var = *constant;
+	/* resotore some that are not a part of viede mode */
+	var->xoffset = xoffset;
+	var->yoffset = yoffset;
+	var->activate = activate;
+
+	return 0;
+}
+
 int
 fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
 {
@@ -940,9 +990,11 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
 
 		if (info->fbops->fb_check_var) {
 			ret = info->fbops->fb_check_var(var, info);
-			if (ret)
-				goto done;
-		}
+		} else
+			ret = fb_check_var(var, info);
+
+		if (ret)
+			goto done;
 
 		if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
 			struct fb_videomode mode;


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help