All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fbmem: Convert from atomic_t to refcount_t on fb_info->count
@ 2021-07-19  5:59 Xiyu Yang
  2021-07-19 20:19 ` Sam Ravnborg
  0 siblings, 1 reply; 2+ messages in thread
From: Xiyu Yang @ 2021-07-19  5:59 UTC (permalink / raw)
  To: Daniel Vetter, Gustavo A. R. Silva, Matthew Wilcox, Sam Ravnborg,
	Arnd Bergmann, Thomas Zimmermann, George Kennedy, Xiyu Yang,
	Tetsuo Handa, Jason Gunthorpe, William Kucharski, Xin Tan,
	dri-devel, linux-fbdev, linux-kernel
  Cc: yuanxzhang

refcount_t type and corresponding API can protect refcounters from
accidental underflow and overflow and further use-after-free situations.

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
---
 drivers/video/fbdev/core/fbmem.c | 6 +++---
 include/linux/fb.h               | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
index 98f193078c05..b7d26b928e1d 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -67,7 +67,7 @@ static struct fb_info *get_fb_info(unsigned int idx)
 	mutex_lock(&registration_lock);
 	fb_info = registered_fb[idx];
 	if (fb_info)
-		atomic_inc(&fb_info->count);
+		refcount_inc(&fb_info->count);
 	mutex_unlock(&registration_lock);
 
 	return fb_info;
@@ -75,7 +75,7 @@ static struct fb_info *get_fb_info(unsigned int idx)
 
 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;
 	if (fb_info->fbops->fb_destroy)
 		fb_info->fbops->fb_destroy(fb_info);
@@ -1594,7 +1594,7 @@ static int do_register_framebuffer(struct fb_info *fb_info)
 		if (!registered_fb[i])
 			break;
 	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->mm_lock);
 
diff --git a/include/linux/fb.h b/include/linux/fb.h
index ecfbcc0553a5..5950f8f5dc74 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -2,6 +2,7 @@
 #ifndef _LINUX_FB_H
 #define _LINUX_FB_H
 
+#include <linux/refcount.h>
 #include <linux/kgdb.h>
 #include <uapi/linux/fb.h>
 
@@ -435,7 +436,7 @@ struct fb_tile_ops {
 
 
 struct fb_info {
-	atomic_t count;
+	refcount_t count;
 	int node;
 	int flags;
 	/*
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fbmem: Convert from atomic_t to refcount_t on fb_info->count
  2021-07-19  5:59 [PATCH] fbmem: Convert from atomic_t to refcount_t on fb_info->count Xiyu Yang
@ 2021-07-19 20:19 ` Sam Ravnborg
  0 siblings, 0 replies; 2+ messages in thread
From: Sam Ravnborg @ 2021-07-19 20:19 UTC (permalink / raw)
  To: Xiyu Yang
  Cc: Xin Tan, William Kucharski, Arnd Bergmann, Jason Gunthorpe,
	Tetsuo Handa, Daniel Vetter, yuanxzhang, Gustavo A. R. Silva,
	Matthew Wilcox, linux-fbdev, George Kennedy, dri-devel,
	Thomas Zimmermann, linux-kernel

Hi Xiyu, Xin,
On Mon, Jul 19, 2021 at 01:59:45PM +0800, Xiyu Yang wrote:
> refcount_t type and corresponding API can protect refcounters from
> accidental underflow and overflow and further use-after-free situations.
> 
> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>

Looks like a nice improvement, thanks.
Applied to drm-misc-next, it will appear in -next in a week or so.

	Sam

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-19 20:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-19  5:59 [PATCH] fbmem: Convert from atomic_t to refcount_t on fb_info->count Xiyu Yang
2021-07-19 20:19 ` Sam Ravnborg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.