34
34
#include <linux/screen_info.h>
35
35
#include <linux/sysfb.h>
36
36
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
+
37
72
static __init int sysfb_init (void )
38
73
{
39
74
struct screen_info * si = & screen_info ;
40
75
struct simplefb_platform_data mode ;
41
- struct platform_device * pd ;
42
76
const char * name ;
43
77
bool compatible ;
44
- int ret ;
78
+ int ret = 0 ;
79
+
80
+ mutex_lock (& disable_lock );
81
+ if (disabled )
82
+ goto unlock_mutex ;
45
83
46
84
/* try to create a simple-framebuffer device */
47
85
compatible = sysfb_parse_mode (si , & mode );
48
86
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 ;
52
90
}
53
91
54
92
/* if the FB is incompatible, create a legacy framebuffer device */
@@ -60,8 +98,10 @@ static __init int sysfb_init(void)
60
98
name = "platform-framebuffer" ;
61
99
62
100
pd = platform_device_alloc (name , 0 );
63
- if (!pd )
64
- return - ENOMEM ;
101
+ if (!pd ) {
102
+ ret = - ENOMEM ;
103
+ goto unlock_mutex ;
104
+ }
65
105
66
106
sysfb_apply_efi_quirks (pd );
67
107
@@ -73,9 +113,11 @@ static __init int sysfb_init(void)
73
113
if (ret )
74
114
goto err ;
75
115
76
- return 0 ;
116
+ goto unlock_mutex ;
77
117
err :
78
118
platform_device_put (pd );
119
+ unlock_mutex :
120
+ mutex_unlock (& disable_lock );
79
121
return ret ;
80
122
}
81
123
0 commit comments