MLK-13722-2 video: mxsfb: change 'usage' to atomic_t type
authorFancy Fang <chen.fang@nxp.com>
Wed, 4 Jan 2017 07:34:43 +0000 (15:34 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 19:58:18 +0000 (14:58 -0500)
The 'usage' field of mxsfb_layer is used to record the
overlay fb user counts. So change its type to atomic_t
to avoid race problem.

Signed-off-by: Fancy Fang <chen.fang@nxp.com>
drivers/video/fbdev/mxsfb.c

index 95d2b28..84a2f15 100644 (file)
@@ -56,6 +56,7 @@
 #include <linux/fb.h>
 #include <linux/mxcfb.h>
 #include <linux/regulator/consumer.h>
+#include <linux/types.h>
 #include <linux/videodev2.h>
 #include <video/of_display_timing.h>
 #include <video/videomode.h>
@@ -217,7 +218,7 @@ struct mxsfb_layer {
        struct fb_info          *ol_fb;
        int                     id;
        int                     registered;
-       uint32_t                usage;
+       atomic_t                usage;
        int                     blank_state;
        uint32_t                global_alpha;
 
@@ -1663,7 +1664,7 @@ static int overlayfb_open(struct fb_info *info, int user)
        struct mxsfb_layer *ofb = (struct mxsfb_layer*)info->par;
        struct mxsfb_info  *fbi = ofb->fbi;
 
-       if (ofb->usage++ == 0) {
+       if (atomic_inc_return(&ofb->usage) == 1) {
                memset((void*)&info->var, 0x0, sizeof(info->var));
 
                ofb->ol_fb->var.xres            = fbi->fb_info->var.xres;
@@ -1682,9 +1683,9 @@ static int overlayfb_release(struct fb_info *info, int user)
        struct mxsfb_layer *ofb = (struct mxsfb_layer*)info->par;
        struct mxsfb_info *fbi = ofb->fbi;
 
-       BUG_ON(!ofb->usage);
+       BUG_ON(!atomic_read(&ofb->usage));
 
-       if (--ofb->usage == 0) {
+       if (atomic_dec_return(&ofb->usage) == 0) {
                if (ofb->blank_state == FB_BLANK_UNBLANK)
                        ofb->ops->disable(ofb);
 
@@ -1907,7 +1908,7 @@ static void init_mxsfb_overlay(struct mxsfb_info *fbi,
 
        ofb->id = 0;
        ofb->ops = &ofb_ops;
-       ofb->usage = 0;
+       atomic_set(&ofb->usage, 0);
        ofb->blank_state = -1;
        ofb->global_alpha = 255;
        ofb->fbi = fbi;