File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -74,24 +74,35 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
74
74
struct idxd_device * idxd ;
75
75
struct idxd_wq * wq ;
76
76
struct device * dev ;
77
+ int rc = 0 ;
77
78
78
79
wq = inode_wq (inode );
79
80
idxd = wq -> idxd ;
80
81
dev = & idxd -> pdev -> dev ;
81
82
82
83
dev_dbg (dev , "%s called: %d\n" , __func__ , idxd_wq_refcount (wq ));
83
84
84
- if (idxd_wq_refcount (wq ) > 0 && wq_dedicated (wq ))
85
- return - EBUSY ;
86
-
87
85
ctx = kzalloc (sizeof (* ctx ), GFP_KERNEL );
88
86
if (!ctx )
89
87
return - ENOMEM ;
90
88
89
+ mutex_lock (& wq -> wq_lock );
90
+
91
+ if (idxd_wq_refcount (wq ) > 0 && wq_dedicated (wq )) {
92
+ rc = - EBUSY ;
93
+ goto failed ;
94
+ }
95
+
91
96
ctx -> wq = wq ;
92
97
filp -> private_data = ctx ;
93
98
idxd_wq_get (wq );
99
+ mutex_unlock (& wq -> wq_lock );
94
100
return 0 ;
101
+
102
+ failed :
103
+ mutex_unlock (& wq -> wq_lock );
104
+ kfree (ctx );
105
+ return rc ;
95
106
}
96
107
97
108
static int idxd_cdev_release (struct inode * node , struct file * filep )
@@ -105,7 +116,9 @@ static int idxd_cdev_release(struct inode *node, struct file *filep)
105
116
filep -> private_data = NULL ;
106
117
107
118
kfree (ctx );
119
+ mutex_lock (& wq -> wq_lock );
108
120
idxd_wq_put (wq );
121
+ mutex_unlock (& wq -> wq_lock );
109
122
return 0 ;
110
123
}
111
124
You can’t perform that action at this time.
0 commit comments