Commit 0189cb57 authored by Xiyu Yang's avatar Xiyu Yang Committed by Sam Ravnborg

fbmem: Convert from atomic_t to refcount_t on fb_info->count

refcount_t type and corresponding API can protect refcounters from
accidental underflow and overflow and further use-after-free situations.
Signed-off-by: default avatarXiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: default avatarXin Tan <tanxin.ctf@gmail.com>
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/1626674392-55857-1-git-send-email-xiyuyang19@fudan.edu.cn
parent 98a65439
...@@ -67,7 +67,7 @@ static struct fb_info *get_fb_info(unsigned int idx) ...@@ -67,7 +67,7 @@ static struct fb_info *get_fb_info(unsigned int idx)
mutex_lock(&registration_lock); mutex_lock(&registration_lock);
fb_info = registered_fb[idx]; fb_info = registered_fb[idx];
if (fb_info) if (fb_info)
atomic_inc(&fb_info->count); refcount_inc(&fb_info->count);
mutex_unlock(&registration_lock); mutex_unlock(&registration_lock);
return fb_info; return fb_info;
...@@ -75,7 +75,7 @@ static struct fb_info *get_fb_info(unsigned int idx) ...@@ -75,7 +75,7 @@ static struct fb_info *get_fb_info(unsigned int idx)
static void put_fb_info(struct fb_info *fb_info) static void put_fb_info(struct fb_info *fb_info)
{ {
if (!atomic_dec_and_test(&fb_info->count)) if (!refcount_dec_and_test(&fb_info->count))
return; return;
if (fb_info->fbops->fb_destroy) if (fb_info->fbops->fb_destroy)
fb_info->fbops->fb_destroy(fb_info); fb_info->fbops->fb_destroy(fb_info);
...@@ -1590,7 +1590,7 @@ static int do_register_framebuffer(struct fb_info *fb_info) ...@@ -1590,7 +1590,7 @@ static int do_register_framebuffer(struct fb_info *fb_info)
if (!registered_fb[i]) if (!registered_fb[i])
break; break;
fb_info->node = i; fb_info->node = i;
atomic_set(&fb_info->count, 1); refcount_set(&fb_info->count, 1);
mutex_init(&fb_info->lock); mutex_init(&fb_info->lock);
mutex_init(&fb_info->mm_lock); mutex_init(&fb_info->mm_lock);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#ifndef _LINUX_FB_H #ifndef _LINUX_FB_H
#define _LINUX_FB_H #define _LINUX_FB_H
#include <linux/refcount.h>
#include <linux/kgdb.h> #include <linux/kgdb.h>
#include <uapi/linux/fb.h> #include <uapi/linux/fb.h>
...@@ -435,7 +436,7 @@ struct fb_tile_ops { ...@@ -435,7 +436,7 @@ struct fb_tile_ops {
struct fb_info { struct fb_info {
atomic_t count; refcount_t count;
int node; int node;
int flags; int flags;
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment