Commit b3e88137 authored by Thomas Zimmermann's avatar Thomas Zimmermann
Browse files

fbdev: Warn on incorrect framebuffer access



Test in framebuffer read, write and drawing helpers if FBINFO_VIRTFB
has been set correctly. Framebuffers in I/O memory should only be
accessed with the architecture's respective helpers. Framebuffers
in system memory should be accessed with the regular load and
store operations. Presumably not all drivers get this right, so we
now warn about it.

Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231127131655.4020-32-tzimmermann@suse.de
parent 33253d9e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -391,6 +391,9 @@ void cfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
	if (p->state != FBINFO_STATE_RUNNING)
		return;

	if (p->flags & FBINFO_VIRTFB)
		fb_warn_once(p, "Framebuffer is not in I/O address space.");

	/* if the beginning of the target area might overlap with the end of
	the source area, be have to copy the area reverse. */
	if ((dy == sy && dx > sx) || (dy > sy)) {
+3 −0
Original line number Diff line number Diff line
@@ -287,6 +287,9 @@ void cfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
	if (p->state != FBINFO_STATE_RUNNING)
		return;

	if (p->flags & FBINFO_VIRTFB)
		fb_warn_once(p, "Framebuffer is not in I/O address space.");

	if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
	    p->fix.visual == FB_VISUAL_DIRECTCOLOR )
		fg = ((u32 *) (p->pseudo_palette))[rect->color];
+3 −0
Original line number Diff line number Diff line
@@ -326,6 +326,9 @@ void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
	if (p->state != FBINFO_STATE_RUNNING)
		return;

	if (p->flags & FBINFO_VIRTFB)
		fb_warn_once(p, "Framebuffer is not in I/O address space.");

	bitstart = (dy * p->fix.line_length * 8) + (dx * bpp);
	start_index = bitstart & (32 - 1);
	pitch_index = (p->fix.line_length & (bpl - 1)) * 8;
+9 −0
Original line number Diff line number Diff line
@@ -12,6 +12,9 @@ ssize_t fb_io_read(struct fb_info *info, char __user *buf, size_t count, loff_t
	int c, cnt = 0, err = 0;
	unsigned long total_size, trailing;

	if (info->flags & FBINFO_VIRTFB)
		fb_warn_once(info, "Framebuffer is not in I/O address space.");

	if (!info->screen_base)
		return -ENODEV;

@@ -73,6 +76,9 @@ ssize_t fb_io_write(struct fb_info *info, const char __user *buf, size_t count,
	int c, cnt = 0, err = 0;
	unsigned long total_size, trailing;

	if (info->flags & FBINFO_VIRTFB)
		fb_warn_once(info, "Framebuffer is not in I/O address space.");

	if (!info->screen_base)
		return -ENODEV;

@@ -138,6 +144,9 @@ int fb_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
	u32 len = info->fix.smem_len;
	unsigned long mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT;

	if (info->flags & FBINFO_VIRTFB)
		fb_warn_once(info, "Framebuffer is not in I/O address space.");

	/*
	 * This can be either the framebuffer mapping, or if pgoff points
	 * past it, the mmio mapping.
+6 −0
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@ ssize_t fb_sys_read(struct fb_info *info, char __user *buf, size_t count,
	unsigned long total_size, c;
	ssize_t ret;

	if (!(info->flags & FBINFO_VIRTFB))
		fb_warn_once(info, "Framebuffer is not in virtual address space.");

	if (!info->screen_buffer)
		return -ENODEV;

@@ -64,6 +67,9 @@ ssize_t fb_sys_write(struct fb_info *info, const char __user *buf,
	unsigned long total_size, c;
	size_t ret;

	if (!(info->flags & FBINFO_VIRTFB))
		fb_warn_once(info, "Framebuffer is not in virtual address space.");

	if (!info->screen_buffer)
		return -ENODEV;

Loading