File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -92,12 +92,18 @@ static DECLARE_WAIT_QUEUE_HEAD(waitq);
92
92
/* Called when the /proc file is opened */
93
93
static int module_open (struct inode * inode , struct file * file )
94
94
{
95
+ /* Try to get without blocking */
96
+ if (!atomic_cmpxchg (& already_open , 0 , 1 )) {
97
+ /* Success without blocking, allow the access */
98
+ try_module_get (THIS_MODULE );
99
+ return 0 ;
100
+ }
95
101
/* If the file's flags include O_NONBLOCK, it means the process does not
96
- * want to wait for the file. In this case, if the file is already open,
102
+ * want to wait for the file. In this case, because the file is already open,
97
103
* we should fail with -EAGAIN, meaning "you will have to try again",
98
104
* instead of blocking a process which would rather stay awake.
99
105
*/
100
- if (( file -> f_flags & O_NONBLOCK ) && atomic_read ( & already_open ) )
106
+ if (file -> f_flags & O_NONBLOCK )
101
107
return - EAGAIN ;
102
108
103
109
/* This is the correct place for try_module_get(THIS_MODULE) because if
You can’t perform that action at this time.
0 commit comments