@@ -37,10 +37,6 @@ static int device_open(struct inode *inode, struct file *file)
37
37
{
38
38
pr_info ("device_open(%p)\n" , file );
39
39
40
- /* We don't want to talk to two processes at the same time. */
41
- if (atomic_cmpxchg (& already_open , CDEV_NOT_USED , CDEV_EXCLUSIVE_OPEN ))
42
- return - EBUSY ;
43
-
44
40
try_module_get (THIS_MODULE );
45
41
return SUCCESS ;
46
42
}
@@ -49,9 +45,6 @@ static int device_release(struct inode *inode, struct file *file)
49
45
{
50
46
pr_info ("device_release(%p,%p)\n" , inode , file );
51
47
52
- /* We're now ready for our next caller */
53
- atomic_set (& already_open , CDEV_NOT_USED );
54
-
55
48
module_put (THIS_MODULE );
56
49
return SUCCESS ;
57
50
}
@@ -129,6 +122,11 @@ device_ioctl(struct file *file, /* ditto */
129
122
unsigned long ioctl_param )
130
123
{
131
124
int i ;
125
+ long ret = SUCCESS ;
126
+
127
+ /* We don't want to talk to two processes at the same time. */
128
+ if (atomic_cmpxchg (& already_open , CDEV_NOT_USED , CDEV_EXCLUSIVE_OPEN ))
129
+ return - EBUSY ;
132
130
133
131
/* Switch according to the ioctl called */
134
132
switch (ioctl_num ) {
@@ -166,11 +164,14 @@ device_ioctl(struct file *file, /* ditto */
166
164
/* This ioctl is both input (ioctl_param) and output (the return
167
165
* value of this function).
168
166
*/
169
- return (long )message [ioctl_param ];
167
+ ret = (long )message [ioctl_param ];
170
168
break ;
171
169
}
172
170
173
- return SUCCESS ;
171
+ /* We're now ready for our next caller */
172
+ atomic_set (& already_open , CDEV_NOT_USED );
173
+
174
+ return ret ;
174
175
}
175
176
176
177
/* Module Declarations */
0 commit comments