Skip to content

Commit babc250

Browse files
Mikulas Patockabzolnier
authored andcommitted
udlfb: introduce a rendering mutex
Rendering calls may be done simultaneously from the workqueue, dlfb_ops_write, dlfb_ops_ioctl, dlfb_ops_set_par and dlfb_dpy_deferred_io. The code is robust enough so that it won't crash on concurrent rendering. However, concurrent rendering may cause display corruption if the same pixel is simultaneously being rendered. In order to avoid this corruption, this patch adds a mutex around the rendering calls. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Cc: Bernie Thompson <bernie@plugable.com> Cc: Ladislav Michl <ladis@linux-mips.org> Cc: <stable@vger.kernel.org> [b.zolnierkie: replace "dlfb:" with "uldfb:" in the patch summary] Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
1 parent 6b11f9d commit babc250

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

‎drivers/video/fbdev/udlfb.c‎

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ static int dlfb_render_hline(struct dlfb_data *dlfb, struct urb **urb_ptr,
596596

597597
static int dlfb_handle_damage(struct dlfb_data *dlfb, int x, int y, int width, int height)
598598
{
599-
int i;
599+
int i, ret;
600600
char *cmd;
601601
cycles_t start_cycles, end_cycles;
602602
int bytes_sent = 0;
@@ -606,21 +606,29 @@ static int dlfb_handle_damage(struct dlfb_data *dlfb, int x, int y, int width, i
606606

607607
start_cycles = get_cycles();
608608

609+
mutex_lock(&dlfb->render_mutex);
610+
609611
aligned_x = DL_ALIGN_DOWN(x, sizeof(unsigned long));
610612
width = DL_ALIGN_UP(width + (x-aligned_x), sizeof(unsigned long));
611613
x = aligned_x;
612614

613615
if ((width <= 0) ||
614616
(x + width > dlfb->info->var.xres) ||
615-
(y + height > dlfb->info->var.yres))
616-
return -EINVAL;
617+
(y + height > dlfb->info->var.yres)) {
618+
ret = -EINVAL;
619+
goto unlock_ret;
620+
}
617621

618-
if (!atomic_read(&dlfb->usb_active))
619-
return 0;
622+
if (!atomic_read(&dlfb->usb_active)) {
623+
ret = 0;
624+
goto unlock_ret;
625+
}
620626

621627
urb = dlfb_get_urb(dlfb);
622-
if (!urb)
623-
return 0;
628+
if (!urb) {
629+
ret = 0;
630+
goto unlock_ret;
631+
}
624632
cmd = urb->transfer_buffer;
625633

626634
for (i = y; i < y + height ; i++) {
@@ -654,7 +662,11 @@ static int dlfb_handle_damage(struct dlfb_data *dlfb, int x, int y, int width, i
654662
>> 10)), /* Kcycles */
655663
&dlfb->cpu_kcycles_used);
656664

657-
return 0;
665+
ret = 0;
666+
667+
unlock_ret:
668+
mutex_unlock(&dlfb->render_mutex);
669+
return ret;
658670
}
659671

660672
static void dlfb_init_damage(struct dlfb_data *dlfb)
@@ -782,17 +794,19 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
782794
int bytes_identical = 0;
783795
int bytes_rendered = 0;
784796

797+
mutex_lock(&dlfb->render_mutex);
798+
785799
if (!fb_defio)
786-
return;
800+
goto unlock_ret;
787801

788802
if (!atomic_read(&dlfb->usb_active))
789-
return;
803+
goto unlock_ret;
790804

791805
start_cycles = get_cycles();
792806

793807
urb = dlfb_get_urb(dlfb);
794808
if (!urb)
795-
return;
809+
goto unlock_ret;
796810

797811
cmd = urb->transfer_buffer;
798812

@@ -825,6 +839,8 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
825839
atomic_add(((unsigned int) ((end_cycles - start_cycles)
826840
>> 10)), /* Kcycles */
827841
&dlfb->cpu_kcycles_used);
842+
unlock_ret:
843+
mutex_unlock(&dlfb->render_mutex);
828844
}
829845

830846
static int dlfb_get_edid(struct dlfb_data *dlfb, char *edid, int len)
@@ -986,6 +1002,8 @@ static void dlfb_ops_destroy(struct fb_info *info)
9861002

9871003
cancel_work_sync(&dlfb->damage_work);
9881004

1005+
mutex_destroy(&dlfb->render_mutex);
1006+
9891007
if (info->cmap.len != 0)
9901008
fb_dealloc_cmap(&info->cmap);
9911009
if (info->monspecs.modedb)
@@ -1682,6 +1700,7 @@ static int dlfb_usb_probe(struct usb_interface *intf,
16821700
dlfb->ops = dlfb_ops;
16831701
info->fbops = &dlfb->ops;
16841702

1703+
mutex_init(&dlfb->render_mutex);
16851704
dlfb_init_damage(dlfb);
16861705
spin_lock_init(&dlfb->damage_lock);
16871706
INIT_WORK(&dlfb->damage_work, dlfb_damage_work);

‎include/video/udlfb.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct dlfb_data {
4848
int base8;
4949
u32 pseudo_palette[256];
5050
int blank_mode; /*one of FB_BLANK_ */
51+
struct mutex render_mutex;
5152
int damage_x;
5253
int damage_y;
5354
int damage_x2;

0 commit comments

Comments
 (0)