3434#include <linux/screen_info.h>
3535#include <linux/sysfb.h>
3636
37+ static struct platform_device * pd ;
38+ static DEFINE_MUTEX (disable_lock );
39+ static bool disabled ;
40+
41+ static bool sysfb_unregister (void )
42+ {
43+ if (IS_ERR_OR_NULL (pd ))
44+ return false;
45+
46+ platform_device_unregister (pd );
47+ pd = NULL ;
48+
49+ return true;
50+ }
51+
52+ /**
53+ * sysfb_disable() - disable the Generic System Framebuffers support
54+ *
55+ * This disables the registration of system framebuffer devices that match the
56+ * generic drivers that make use of the system framebuffer set up by firmware.
57+ *
58+ * It also unregisters a device if this was already registered by sysfb_init().
59+ *
60+ * Context: The function can sleep. A @disable_lock mutex is acquired to serialize
61+ * against sysfb_init(), that registers a system framebuffer device.
62+ */
63+ void sysfb_disable (void )
64+ {
65+ mutex_lock (& disable_lock );
66+ sysfb_unregister ();
67+ disabled = true;
68+ mutex_unlock (& disable_lock );
69+ }
70+ EXPORT_SYMBOL_GPL (sysfb_disable );
71+
3772static __init int sysfb_init (void )
3873{
3974 struct screen_info * si = & screen_info ;
4075 struct simplefb_platform_data mode ;
41- struct platform_device * pd ;
4276 const char * name ;
4377 bool compatible ;
44- int ret ;
78+ int ret = 0 ;
79+
80+ mutex_lock (& disable_lock );
81+ if (disabled )
82+ goto unlock_mutex ;
4583
4684 /* try to create a simple-framebuffer device */
4785 compatible = sysfb_parse_mode (si , & mode );
4886 if (compatible ) {
49- ret = sysfb_create_simplefb (si , & mode );
50- if (!ret )
51- return 0 ;
87+ pd = sysfb_create_simplefb (si , & mode );
88+ if (!IS_ERR ( pd ) )
89+ goto unlock_mutex ;
5290 }
5391
5492 /* if the FB is incompatible, create a legacy framebuffer device */
@@ -60,8 +98,10 @@ static __init int sysfb_init(void)
6098 name = "platform-framebuffer" ;
6199
62100 pd = platform_device_alloc (name , 0 );
63- if (!pd )
64- return - ENOMEM ;
101+ if (!pd ) {
102+ ret = - ENOMEM ;
103+ goto unlock_mutex ;
104+ }
65105
66106 sysfb_apply_efi_quirks (pd );
67107
@@ -73,9 +113,11 @@ static __init int sysfb_init(void)
73113 if (ret )
74114 goto err ;
75115
76- return 0 ;
116+ goto unlock_mutex ;
77117err :
78118 platform_device_put (pd );
119+ unlock_mutex :
120+ mutex_unlock (& disable_lock );
79121 return ret ;
80122}
81123
0 commit comments